3

我正在尝试使用 SURF,但我在 C 中找不到这样做的方法。文档似乎只有 C++ 的内容。

我已经能够检测到 SURF 功能:

    IplImage *img = cvLoadImage("img5.jpg");

    CvMat* image = cvCreateMat(img->height, img->width, CV_8UC1);
    cvCvtColor(img, image, CV_BGR2GRAY);

    // detecting keypoints
    CvSeq *imageKeypoints = 0, *imageDescriptors = 0;
    int i;

    //Extract SURF points by initializing parameters
    CvSURFParams params = cvSURFParams(1, 1);
    cvExtractSURF( image, 0, &imageKeypoints, &imageDescriptors, storage, params );
    printf("Image Descriptors: %d\n", imageDescriptors->total);

    //draw the keypoints on the captured frame
    for( i = 0; i < imageKeypoints->total; i++ )
    {
        CvSURFPoint* r = (CvSURFPoint*)cvGetSeqElem( imageKeypoints, i );
        CvPoint center;
        int radius;
        center.x = cvRound(r->pt.x);
        center.y = cvRound(r->pt.y);
        radius = cvRound(r->size*1.2/9.*2);
        cvCircle( image, center, radius, CV_RGB(0,255,0), 1, 8, 0 );
    }

但我找不到需要比较 2 个图像的描述符的方法。我在 C++ 中找到了这段代码,但翻译时遇到了麻烦:

    // matching descriptors
    BruteForceMatcher<L2<float> > matcher;
    vector<DMatch> matches;
    matcher.match(descriptors1, descriptors2, matches);

    // drawing the results
    namedWindow("matches", 1);
    Mat img_matches;
    drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches);
    imshow("matches", img_matches);
    waitKey(0);

如果有人可以引导我使用描述符匹配器甚至更好,我将不胜感激,让我知道在哪里可以找到仅 C 语言的 OpenCV 文档。

4

3 回答 3

0

查看来自thioldhack的博客文章。包含示例代码。它适用于 QT,但您可以轻松地为 VC++ 或任何其他产品做到这一点。您将需要使用 K 近邻算法匹配关键点。它拥有一切。

于 2012-04-23T11:18:05.497 回答
0

这个链接可能会给你一个提示。https://projects.developer.nokia.com/opencv/browser/opencv/opencv-2.3.1/samples/c/find_obj.cpp。在函数中查看naiveNearestNeighbor

于 2012-04-23T08:51:20.837 回答
0

稍长但最可靠的方法是在您的计算机上使用调试信息编译 OpenCV,然后使用调试器进入 C++ 实现。你也可以把它复制到你的项目中,然后像剥洋葱一样剥它,直到你得到纯 C。

于 2018-06-26T09:36:13.460 回答