NOTE: StackOverODEt 让我回答我自己的问题,因此我在这里回答这个问题。 请 bottom到底看我的答案。
QUESTION Given a binary image, I want to be able to identify which region has the greatest y-coordinate, i.e., which region is the closest to the bottom. In the function below, I try to use contours and bounding rectangles to get the answer I need. However, my use of the function cvContourBOundingRect gives rise to the following error message during compilation:
"_cvContourBoundingRectemphasized", referenced from:
GetLowestContourBoundingRectangle(_IplImage * img, bool)
in main.o. Symbol(s) not found. Collect2: Id returned 1 exit status.
Build Failed.
This is very strange, since I have successfully used other contour functions like cvFindContours and cvContourArea without any trouble. I tried running some searches on Google, but nothing turned up. If anyone can point me in the right direction I would appreciate it.
提前感谢。
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;
}
ANSWER: Okay, ironically I found out why it s breaking shortly after drafting my original question (although in fairness I ve been wrestling with this for a few hours at this point).
我研究了确定以下三项职能的负责人档案:
- cvFindContours -- imgproc_c.h
- cvContourArea -- imgproc_c.h
- cvContourBoundingRect -- 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.
*/
既然这样说,任何人都不知道我如何用非统一的定义来写这一职能?