【发布时间】:2011-03-24 05:03:24
【问题描述】:
我使用 Xcode 和 c++
我已经从OpenCV documentation 复制了 HoughCircles 代码:
#include <cv.h>
#include <highgui.h>
#include <math.h>
using namespace cv;
int main(int argc, char** argv)
{
Mat img, gray;
if( argc != 2 && !(img=imread(argv[1], 1)).data)
return -1;
cvtColor(img, gray, CV_BGR2GRAY);
// smooth it, otherwise a lot of false circles may be detected
GaussianBlur( gray, gray, Size(9, 9), 2, 2 );
vector<Vec3f> circles;
HoughCircles(gray, circles, CV_HOUGH_GRADIENT,
2, gray->rows/4, 200, 100 );
for( size_t i = 0; i < circles.size(); i++ )
{
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
// draw the circle center
circle( img, center, 3, Scalar(0,255,0), -1, 8, 0 );
// draw the circle outline
circle( img, center, radius, Scalar(0,0,255), 3, 8, 0 );
}
namedWindow( "circles", 1 );
imshow( "circles", img );
return 0;
}
然后这样修改:
int main(int argc, char** argv)
{
VideoCapture cap(0);
if(!cap.isOpened())
return -1;
namedWindow( "circles", 1 );
Mat img, gray;
for( ;; )
{
cap >> img;
vector<Vec3f> circles;
cvtColor(img, gray, CV_BGR2GRAY);
GaussianBlur(gray, gray, Size(7,7), 1.5, 1.5);
HoughCircles(img, circles, CV_HOUGH_GRADIENT, 2, img->rows/4, 200, 100 );
imshow( "circles", img );
if(waitKey(30) >= 0) break;
}
return 0;
}
我在这两种情况下都得到了错误:错误:'->' 的基本操作数具有非指针类型'cv::Mat' 然后我将 -> 替换为 .仍然得到另一个错误。这与我从文档中复制的代码相同。
我的理论是,发生这种情况是因为它没有得到图像或其他东西。但是当我取出 HoughCircles 代码时,相机运行良好。
请问有什么想法吗?
【问题讨论】: