我想检测图像中的圆圈。这是我尝试检测此图像中圆圈数量的代码:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <stdio.h>
/** @function main */
int main(int argc, char** argv)
{
//load image from directory
IplImage* gray = cvLoadImage("comb.png",0);
// IplImage* gray = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);
CvMemStorage* storage = cvCreateMemStorage(0);
//covert to grayscale
cvCvtColor(gray, gray, CV_RGB2GRAY);
// This is done so as to prevent a lot of false circles from being detected
cvSmooth(gray, gray, CV_GAUSSIAN, 7, 7);
IplImage* canny = cvCreateImage(cvGetSize(gray),IPL_DEPTH_8U,1);
//IplImage* rgbcanny = cvCreateImage(cvGetSize(gray),IPL_DEPTH_8U,3);
cvCanny(gray, canny, 10, 20, 3);
//detect circles
CvSeq* circles = cvHoughCircles(gray, storage, CV_HOUGH_GRADIENT, 1, gray->width/10);
if(circles->total>0)
printf("circles found: %d\n",circles->total);
else
printf("circles not found");
return 0;
}
但出现以下错误:- OpenCV 错误:cvCvtColor 中的断言失败(dst.data == dst0.data),文件 /OpenCV/OpenCV-2.4.3/modules/imgproc/src/color.cpp,第 3811 行终止后调用抛出 'cv::Exception' 的实例 what(): /OpenCV/OpenCV-2.4.3/modules/imgproc/src/color.cpp:3811: error: (-215) dst.data == dst0.data in函数 cvCvtColor
请告诉我程序有什么问题。我使用的是 ubuntu linux。