Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 600

FitEllipse return bigger ellipse than original ContourSize

$
0
0
I am stuck in weird situation. My `fitEllipse` method returns a big Ellipse than my original Contour. Here is the output of Image: [![enter image description here][1]][1] and my binary image from which it is generating contour is: [![enter image description here][2]][2] There is no noise or anything but I am still getting a large ellipse. My code is as follows: findContours( meter_bin, contours, hierarchy, RETR_LIST, CHAIN_APPROX_SIMPLE); for (int z=0;z200) { Mat pointsf; Mat(contours[z]).convertTo(pointsf, CV_32F); RotatedRect box = fitEllipse(pointsf); if( MAX(box.size.width, box.size.height) > MIN(box.size.width, box.size.height)*30 ) continue; drawContours(img4, contours, (int)z, Scalar::all(255), 1, 8); ellipse(img4, box, Scalar(0,0,255), 1, LINE_AA); ellipse(img4, box.center, box.size*0.5f, box.angle, 0, 360, Scalar(0,255,255), 1, LINE_AA); Point2f vtx[4]; double length[4]; box.points(vtx); for( int j = 0; j < 4; j++ ) { length[j]=sqrt((vtx[j].x - vtx[(j+1)%4].x) * (vtx[j].x - vtx[(j+1)%4].x) + (vtx[j].y - vtx[(j+1)%4].y) * (vtx[j].y - vtx[(j+1)%4].y)); line(img4, vtx[j], vtx[(j+1)%4], Scalar(0,255,0), 1, LINE_AA); } } } I am not sure why this is happening as everything seems to be fine here. Please let me know what is going wrong here Regards, [1]: https://i.stack.imgur.com/wpt87.png [2]: https://i.stack.imgur.com/d1WcZ.png

Viewing all articles
Browse latest Browse all 600

Latest Images

Trending Articles



Latest Images