I'm using cv::minEnclosingCircle(...)
in order to get the minimum circle that exactly evolves my contour, but I'm getting a circle a little big bigger.
In other words, I'm trying to get something like this:
But I'm getting this (the circle):
Note how the circle is a little bigger than the item to enclose.
I need to enclose my object into a circle, not an ellipse.
Thank you in advance.
This is my code:
cv::vector<cv::Point> allPixels;
int columnas = img.cols, filas = img.rows;
cv::Point pt;
for(int col = 0; col < columnas; col++){
for(int row = 0; row < filas; row++){
int val = img.at<uchar>(row,col);
if(val == 255){
pt.x = col;
pt.y = row;
allPixels.push_back(pt);
}
}
}
cv::Mat dispImage = img.clone();
cv::Point2f center;
float radius;
cv::minEnclosingCircle(allPixels,center,radius);
cv::circle(dispImage,center,radius,cv::Scalar(128),1);
cv::circle(dispImage,center,1,cv::Scalar(128),1);
cv::imwrite("Enclosing_Result.png",dispImage);
With 'img' a cv::Mat with size (760,760) and format CV_8UC1. The final result ("Enclosing_Result.png") is next:
And my target is which follows (drawn):