OpenCV:cvContourBoundingRect给出了;“未找到符号”;而其他轮廓函数工作正常

OpenCV:cvContourBoundingRect给出了;“未找到符号”;而其他轮廓函数工作正常,opencv,detection,region,contour,Opencv,Detection,Region,Contour,注意:StackOverflow不允许我回答我自己的问题,所以我在这里回答。请滚动到底部查看我的答案 问题: 给定一个二值图像,我希望能够识别哪个区域具有最大的y坐标,即哪个区域最接近底部。在下面的函数中,我尝试使用轮廓和边界矩形来获得我需要的答案。但是,在编译过程中,使用函数cvContourBOundingRect会产生以下错误消息: "_cvContourBoundingRectemphasized", referenced from: GetLowestContourBoundingR

注意:StackOverflow不允许我回答我自己的问题,所以我在这里回答。请滚动到底部查看我的答案

问题: 给定一个二值图像,我希望能够识别哪个区域具有最大的y坐标,即哪个区域最接近底部。在下面的函数中,我尝试使用轮廓和边界矩形来获得我需要的答案。但是,在编译过程中,使用函数cvContourBOundingRect会产生以下错误消息:

"_cvContourBoundingRectemphasized", referenced from: 
GetLowestContourBoundingRectangle(_IplImage * img, bool) 
in main.o. Symbol(s) not found. Collect2: Id returned 1 exit status. 
Build Failed.
这是非常奇怪的,因为我已经成功地使用了其他轮廓函数,如cvFindContours和cvContourArea,没有任何问题。我试着在谷歌上运行一些搜索,但什么也没找到。如果有人能给我指出正确的方向,我将不胜感激

提前谢谢

CvRect GetLowestContourBoundingRectangle(IplImage *img, bool invertFlag) {
    // NOTE: CONTOURS ARE DRAWN AROUND WHITE AREAS
    IplImage *output = invertFlag ? cvCloneImage(InvertImage(img)) : cvCloneImage(img); // this goes into find contours and is consequently modified

    // find contours
    CvMemStorage *contourstorage = cvCreateMemStorage(0);
    CvSeq* contours = NULL;
    cvFindContours(output, contourstorage, &contours, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);

    // analyze each contour
    int lowestRectangleCoordinate = 0;
    CvRect currentBoundingRectangle;
    CvRect lowestBoundingRectangle;

    while (contours) {
        currentBoundingRectangle = cvContourBoundingRect(contours);
        if (currentBoundingRectangle.y + currentBoundingRectangle.height > lowestRectangleCoordinate) {
            lowestRectangleCoordinate = currentBoundingRectangle.y + currentBoundingRectangle.height;
            lowestBoundingRectangle = currentBoundingRectangle;
        }

        contours = contours->h_next;
    }

    cvReleaseMemStorage(&contourstorage);
    return lowestBoundingRectangle;
}
答复: 好吧,具有讽刺意味的是,我在起草了我的原始问题后很快就发现了为什么它会破裂(尽管公平地说,我已经为此绞尽脑汁几个小时了)

我查找了定义了以下三个函数的头文件:

  • cvFindContours——imgproc_c.h
  • CVA区域——imgproc_c.h
  • cvContourBoundingRect—compat.hpp
  • 显然,compat.hpp适用于不推荐使用的函数,这些函数是为了向后兼容而保留的。以下是标题中的内容:

    /*
       A few macros and definitions for backward compatibility
       with the previous versions of OpenCV. They are obsolete and
       are likely to be removed in future. To check whether your code
       uses any of these, define CV_NO_BACKWARD_COMPATIBILITY before
       including cv.h.
    */
    

    话虽如此,有人知道我如何用非过时的定义编写此函数吗?

    关于您最初的问题“OpenCV:cvContourBoundingRect给出了“未找到符号”

    用于链接该(已弃用)方法的库如下所示:

    libopencv_legacy.so

    而“新的”看起来像这样:boundingRect(输入阵列点)