【问题标题】:OpenCV C vs C++OpenCV C 与 C++
【发布时间】:2012-05-03 20:24:24
【问题描述】:

我正在尝试使用 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 文档。

【问题讨论】:

    标签: c++ c opencv feature-detection surf


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 虽然理论上可以回答这个问题,it would be preferable 在这里包含答案的基本部分,并提供链接以供参考。即使您包含的链接将来会中断,这也将有助于您的答案保持良好状态。
      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 2014-02-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-14
        相关资源
        最近更新 更多