【发布时间】:2015-01-26 22:12:21
【问题描述】:
你能帮我解决这个问题吗?
我的任务是使用 OpenCV 和 c++ 创建一个应用程序,该应用程序将接收植物叶子的图像输入。该应用程序将检测可能的疾病症状,例如叶片上的黑色/灰色/棕色斑点,或枯萎病、病变等。疾病的每种特征(例如斑点的颜色)代表不同的疾病。在检测到可能的症状后,应用程序会将其与应用程序数据库中的模板图像集合进行匹配,并输出可能的最佳匹配。
我必须使用什么方法?我研究过直方图匹配以及关键点和描述符匹配,但我不确定哪一个效果最好。
我找到了使用 SURF 和 FLANN 的示例代码,但我不知道这是否足够:
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/features2d.hpp"
using namespace cv;
void readme();
/**
* @function main
* @brief Main function
*/
int main( int argc, char** argv )
{
if( argc != 3 )
{ readme(); return -1; }
Mat img_1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
Mat img_2 = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
if( !img_1.data || !img_2.data )
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; }
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 400;
SurfFeatureDetector detector( minHessian );
std::vector<KeyPoint> keypoints_1, keypoints_2;
detector.detect( img_1, keypoints_1 );
detector.detect( img_2, keypoints_2 );
//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat descriptors_1, descriptors_2;
extractor.compute( img_1, keypoints_1, descriptors_1 );
extractor.compute( img_2, keypoints_2, descriptors_2 );
//-- Step 3: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match( descriptors_1, descriptors_2, matches );
double max_dist = 0; double min_dist = 100;
//-- Quick calculation of max and min distances between keypoints
for( int i = 0; i < descriptors_1.rows; i++ )
{ double dist = matches[i].distance;
if( dist < min_dist ) min_dist = dist;
if( dist > max_dist ) max_dist = dist;
}
printf("-- Max dist : %f \n", max_dist );
printf("-- Min dist : %f \n", min_dist );
//-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist,
//-- or a small arbitary value ( 0.02 ) in the event that min_dist is very
//-- small)
//-- PS.- radiusMatch can also be used here.
std::vector< DMatch > good_matches;
for( int i = 0; i < descriptors_1.rows; i++ )
{ if( matches[i].distance <= max(2*min_dist, 0.02) )
{ good_matches.push_back( matches[i]); }
}
//-- Draw only "good" matches
Mat img_matches;
drawMatches( img_1, keypoints_1, img_2, keypoints_2,
good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
//-- Show detected matches
imshow( "Good Matches", img_matches );
for( int i = 0; i < (int)good_matches.size(); i++ )
{ printf( "-- Good Match [%d] Keypoint 1: %d -- Keypoint 2: %d \n", i, good_matches[i].queryIdx, good_matches[i].trainIdx ); }
waitKey(0);
return 0;
}
/**
* @function readme
*/
void readme()
{ std::cout << " Usage: ./SURF_FlannMatcher <img1> <img2>" << std::endl; }
这是我的问题:
我必须使用什么方法?直方图匹配、关键点/描述符匹配还是?
如果我使用关键点/描述符匹配,什么算法是 SURF 和 FLANN 的最佳替代方案,因为我还将在 android 平台上实现它?我还需要执行阈值处理或分割吗?它不会删除重要的细节,如颜色、形状等吗?请大家,建议一些步骤来做到这一点。
【问题讨论】:
-
不幸的是,我认为你的问题太复杂了——有太多可能的方法来实现这一点,其中大多数都非常重要(你需要解决许多可能的症状使用特定的算法)。我不认为你会找到一个能够满足你所有需求的预制算法,尤其是对于用非常模糊的术语描述的任务。