I have the code that applies some transformations for image for detecting circles
(GaussianBlur->cvtColor(gray)->canny->HoughCircles
)
and as for result i got vector<Vec3f> circles;
array.
If I draw the result with 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 );
It looks ok(see attached image, blue circle)
But in case I'm trying to draw image not via OpenCV, I've got another circle (or ellipse sometimes)(red circle on attached image):
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();
Why does it happen? How can I get coordinates and radius size in pixel to draw it correctly?
p.s: UIImage
to Mat
conversation i got form documentation