因此,我正在使用以下代码(已经调整了参数):
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace cv;
int main(int, char** argv)
{
Mat src, src_gray;
/// Read the image
src = imread( argv[1], 1 );
if( !src.data )
{ return -1; }
/// Convert it to gray
cvtColor( src, src_gray, CV_BGR2GRAY );
/// Reduce the noise so we avoid false circle detection
GaussianBlur( src_gray, src_gray, Size(9, 9), 2, 2 );
vector<Vec3f> circles;
/// Apply the Hough Transform to find the circles
HoughCircles( src_gray, circles, CV_HOUGH_GRADIENT, 6.0, 5, 110, 70, 3, 20 );
/// Draw the circles detected
for( size_t i = 0; i < circles.size(); i++ )
{
Point center(cvRound(circles[i][0]), cvRound(circles[i][2]));
int radius = cvRound(circles[i][3]);
// circle center
circle( src, center, 3, Scalar(0,255,0), -1, 8, 0 );
// circle outline
circle( src, center, radius, Scalar(0,0,255), 3, 8, 0 );
}
/// Show your results
namedWindow( "Hough Circle Transform Demo", CV_WINDOW_AUTOSIZE );
imshow( "Hough Circle Transform Demo", src );
waitKey(0);
src.release();
src_gray.release();
return 0;
}
我想检测的图像是以下的圆形图案:测试图片
这实际上是通过使用cvBlobsLib获得的两个斑点的轮廓,并重新绘制成一个新图像。
该算法能够识别每个圆的中心,但是,当我按任意键关闭程序时,它就会崩溃... :( 我不得不强制关闭它。
我需要将该算法适应于在相机中运行,因此在出现崩溃问题时无法继续实现。
那么,有人知道可能导致这个问题的原因吗? 我正在使用Visual Studio 2012和OpenCV版本2.4.2进行开发。
如果有人能给我建议或尝试运行该算法,我将非常感激!