gpt4 book ai didi

image-processing - 'cvFindContours' 未在此范围内声明,opencv 2.4.2,编译错误

转载 作者:太空宇宙 更新时间:2023-11-03 21:48:01 26 4
gpt4 key购买 nike

我正在使用 opencv 2.4.2 库检测边缘并在图像上查找四边形形状。一切都很顺利,直到我遇到这些编译错误

../src/GoodFeaturesToDetect.cpp:198:109: error: ‘cvFindContours’ was not declared in this scope
../src/GoodFeaturesToDetect.cpp:203:106: error: ‘cvContourPerimeter’ was not declared in this scope
../src/GoodFeaturesToDetect.cpp:203:114: error: ‘cvApproxPoly’ was not declared in this scope
../src/GoodFeaturesToDetect.cpp:206:64: error: ‘cvContourArea’ was not declared in this scope

这是我的标题:

#include <opencv2/core/core.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace cv;
using namespace std;

void DrawLine( Mat img, Point start, Point end );
vector<Point2f> FindCornersUsingGoodFeaturesToTrack(Mat toTrack);
void ConnectPointsWithLine(Mat img,vector<Point2f> corners);
void DrawQuad(Mat img, Point a, Point b, Point c, Point d);
void DetectAndDrawQuads(Mat img);

这是调用函数的方法

void DetectAndDrawQuads(Mat img){
CvSeq* contours;
CvSeq* result;
CvMemStorage *storage=cvCreateMemStorage(0);
Mat gray;
cvtColor(img,gray,CV_BGR2GRAY);
cvFindContours(&gray,storage, &contours, sizeof(CvContour),CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE, Point(0,0));

//Loop through all the contours discovered
//Figure out which ones form a quad
while(contours){
result=cvApproxPoly(contours, sizeof(CvContour),storage, CV_POLY_APPROX_DP,cvContourPerimeter(contours)*0.02,0);

if(result->total=4 && fabs(cvContourArea(result, CV_WHOLE_SEQ)) > 20){
CvPoint *pt[4];
for(int i=0; i<4; i++)
pt[i]=(CvPoint*) cvGetSeqElem(result,i);

DrawQuad(gray,*pt[0],*pt[1],*pt[2],*pt[3]);

}
contours = contours->h_next;
}

}

DetectAndDrawQuads 从 main() 调用..

这是链接库

opencv_contrib opencv_flann opencv_legacy opencv_calib3d opencv_ml opencv_imgproc opencv_highgui opencv_objdetect opencv_core opencv_features2d

我正在研究 Eclipse CDT (Helois)

如有任何提示,我将不胜感激。谢谢。

最佳答案

首先,您应该使用 #include <>对于 opencv header (如第一行,与第二行和第三行形成对比)。

cv 开头的方法喜欢cvFindContours来自较旧的 opencv C 接口(interface),并与较新的 C++ 接口(interface)分开。例如 cvFindContouropencv2/imgproc/imgproc_c.h 中定义而不是 opencv2/imgproc/imgproc.hpp (注意 _c.h 部分)。

在附注中,您已经包含了 stdlib.h两次。

关于image-processing - 'cvFindContours' 未在此范围内声明,opencv 2.4.2,编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11604632/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com