我有一些代码可以应用一些图像转换来检测圆圈
(af5
)
至于结果我得到了GaussianBlur->cvtColor(gray)->canny->HoughCircles
数组。
如果我用OpenCV绘制结果:
vector<Vec3f> circles;
看起来不错(参见附图,蓝圈)
但是如果我试图不通过OpenCV绘制图像,我有另一个圆圈(或有时是椭圆形)(附加图像上的红色圆圈):
cv::Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
//circle center
circle( originalMat, center, 3, Scalar(0,255,0), -1, 8, 0 );
// circle outline
circle( originalMat, center, radius, Scalar(0,0,255), 1, 8, 0 );
为什么会这样?如何获得像素中的坐标和半径大小以正确绘制它?
p.s: UIGraphicsBeginImageContext(image.size); //the same size as original
[image drawAtPoint:CGPointZero];
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor redColor] setStroke];
CGRect circleRect = CGRectMake(circles[i][0] - circles[i][2] ,
circles[i][1] - circles[i][2],
circles[i][0] + circles[i][2],
circles[i][1] + circles[i][2]
);
circleRect = CGRectInset(circleRect, 5, 5);
CGContextStrokeEllipseInRect(ctx, circleRect);
UIImage *retImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
到UIImage
我的对话documentation