OpenCV C vs C++

OpenCV C vs C++

本文关键字:C++ vs OpenCV      更新时间:2023-10-16

我正在尝试使用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: %dn", 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 文档。

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

查看thioldhack的博客文章。包含一个示例代码。它适用于QT,但您可以轻松地为VC++或任何其他方法执行此操作。您需要使用 K 最近邻算法匹配关键点。它拥有一切。

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