RotatedRect and Ellipse (Bug #425)


Added by Benoit R over 14 years ago. Updated over 14 years ago.


Status:Done Start date:
Priority:High Due date:
Assignee:- % Done:

0%

Category:core
Target version:-
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

Hy just to say that this morning I try to use rotated rect and ellispe and I had two bad surprises:

First of all I have a painted a shape on an image, then I have find its shape, and finally I have tried to fit an Ellipse on the shape

This is the first part that seems to work okay

cv::vector< cv::vector< cv::Point > > vecPts;
findContours(img, vecPts, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
cv::RotatedRect rrect = cv::fitEllipse(cv::Mat(vecPts));

But now I have two problems:

1- I can't paint correctly the RotatedRect:

To paint I need to invert the angle:

rrect.angle*=-1;
cv::ellipse(img,rrect,cv::Scalar(0,0,255,0),2);

or if I use the other function I need to inverse the angle and divide the size by 2

cv::Size rSize= cv::Size(rrect.size.width/2,rrect.size.height/2);
cv::ellipse(img,rrect.center,rSize,-rrect.angle,0,360,cv::Scalar(0,255,255,255),2);

2- Another problems is using RotatedRect::points() method which doesn't work, and set me point somewhere else.

cv::Point2f rrPtsr4;
rrect.points(rrPts);

It seems to be the
float a = (float)cos(_angle)*0.5f;
float b = (float)sin(_angle)*0.5f;

that need to be changed in
float a = (float)sin(_angle)*0.5f;
float b = (float)cos(_angle)*0.5f;

in core/operations.hpp


I don't know which functions was a bad behaviour (the angle is bad in fitEllipse or is it bad at painting?
Why do I need to rescale the size of a rotated rect by 2?

Therefore I did not write any patch for this!!!

I hope it will help you guy.


Associated revisions

Revision a937d9d4
Added by Vadim Pisarevsky over 14 years ago

unified the coordinate interpretation in RotatedRect (ticket #425)

Revision 6dc3b662
Added by Andrey Kamaev about 12 years ago

Merge pull request #425 from asmaloney:vector_empty

History

Updated by Pei JIA over 14 years ago

Hi, Please refer to my patch
#400

This has not been finally confirmed by VP, but I tested it already.
Revise it in my way, it works fine.

Hope this help.

Best Regards
JIA

Updated by Vadim Pisarevsky over 14 years ago

sorry for delay.
except for box.size scaling, all the other issues have been resolved (SVN r4122). now the samples fitellipse (where the new C++ API, similar to your sample, is used), camshiftdemo and minarearect, as well as all the related OpenCV functions and tests interpret box.size in the similar way.

to draw an ellipse inscribed in the RotatedRect using the normal center, axes, angle variant of cv::ellipse, you can use:

cv::ellipse(img, rrect.center, rrect.size*0.5f, rrect.angle, ...);

  • Status changed from Open to Done
  • (deleted custom field) set to fixed

Also available in: Atom PDF