Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenCV-如何使用C++;_C++_Opencv_Image Processing_Feature Extraction_Feature Detection - Fatal编程技术网

C++ OpenCV-如何使用C++;

C++ OpenCV-如何使用C++;,c++,opencv,image-processing,feature-extraction,feature-detection,C++,Opencv,Image Processing,Feature Extraction,Feature Detection,我需要一些帮助来匹配非正常血细胞和原始细胞。 经过一些搜索,我找到了SURF和SIFT特征提取 我有这个模板 还有这个原始图像 这是我的代码: int main(int argc, char** argv) { Mat img_scene = imread("d:\\projimg\\last.jpg", CV_LOAD_IMAGE_GRAYSCALE); Mat img_object = imread("d:\\projimg\\lasttmp.jpg", CV_LOAD_IMAGE_G

我需要一些帮助来匹配非正常血细胞和原始细胞。 经过一些搜索,我找到了SURF和SIFT特征提取

我有这个模板

还有这个原始图像

这是我的代码:

int main(int argc, char** argv)
{

Mat img_scene = imread("d:\\projimg\\last.jpg", CV_LOAD_IMAGE_GRAYSCALE);
Mat img_object = imread("d:\\projimg\\lasttmp.jpg", CV_LOAD_IMAGE_GRAYSCALE);
//Mat img_object = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
//Mat img_scene = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);

if (!img_object.data || !img_scene.data)
{
    std::cout << " --(!) Error reading images " << std::endl; return -1;
}

//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 200;

SurfFeatureDetector detector(minHessian);

std::vector<KeyPoint> keypoints_object, keypoints_scene;

detector.detect(img_object, keypoints_object);
detector.detect(img_scene, keypoints_scene);

//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;

Mat descriptors_object, descriptors_scene;

extractor.compute(img_object, keypoints_object, descriptors_object);
extractor.compute(img_scene, keypoints_scene, descriptors_scene);

//-- Step 3: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match(descriptors_object, descriptors_scene, matches);
matches.resize(10);
sort(matches.begin(), matches.end());
double max_dist = 0; double min_dist = 100;

//-- Quick calculation of max and min distances between keypoints
for (int i = 0; i <matches.size(); 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 3*min_dist )
std::vector< DMatch > good_matches;

for (int i = 0; i < matches.size(); i++)
{
    if (matches[i].distance < 3 * min_dist)
    {
        good_matches.push_back(matches[i]);
    }
}

Mat img_matches;
drawMatches(img_object, keypoints_object, img_scene, keypoints_scene,
    good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
    vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);

//-- Localize the object
std::vector<Point2f> obj;
std::vector<Point2f> scene;

for (int i = 0; i < good_matches.size(); i++)
{
    //-- Get the keypoints from the good matches
    obj.push_back(keypoints_object[good_matches[i].queryIdx].pt);
    scene.push_back(keypoints_scene[good_matches[i].trainIdx].pt);
}
imshow("ii", img_matches);
waitKey();
return 0;
}
int main(int argc,char**argv)
{
Mat img_scene=imread(“d:\\projimg\\last.jpg”,CV_LOAD_IMAGE_GRAYSCALE);
Mat img\u object=imread(“d:\\projimg\\lasttmp.jpg”,CV\u LOAD\u IMAGE\u灰度);
//Mat img_object=imread(argv[1],CV_LOAD_IMAGE_GRAYSCALE);
//Mat img_scene=imread(argv[2],CV_LOAD_IMAGE_GRAYSCALE);
如果(!img_object.data | |!img_scene.data)
{
标准::不能很好地匹配;
for(int i=0;i
有人能帮我匹配所有相似的模板吗


谢谢大家

没有回答,但也许你可以试着找到所有正常的血细胞?(剩余的血细胞不正常)我认为功能提取器对您没有帮助。我会尝试根据形状对其进行过滤。请阅读文档,了解您是否为正常血细胞实现了代码,或者知道如何实现?尝试调整图像模板的大小,并对源图像执行关联。