RotatedRect angle does not provide enough information (Bug #3735)


Added by João Silva almost 11 years ago. Updated over 9 years ago.


Status:Open Start date:2014-06-03
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:documentation
Target version:-
Affected version:2.4.9 (latest release) Operating System:Linux
Difficulty: HW Platform:x64
Pull request:https://github.com/Itseez/opencv/pull/2877

Description

From my experiments, the angle returned by RotatedRect's angle variable goes from -90 to 0 degrees, which is not sufficient to determine if the object is leaned to the left or right.

For example, if the angle is -45 degrees, we cannot say if we need to rotate +45 or -45 degrees to deskew it.

An excerpt of the code I'm using:

RotatedRect rotated_rect = minAreaRect(contour);
float blob_angle_deg = rotated_rect.angle;
Mat mapMatrix = getRotationMatrix2D(center, blob_angle_deg, 1.0);

Leaning the object in one direction I get angles from 0 to -90 degrees, while leaning the object to the other direction I get angles from -90 to 0 degrees.


Associated revisions

Revision 1c6e9fdf
Added by Alexander Smorkalov about 10 years ago

Merge pull request #3735 from SpecLad:align-cpack-variables

History

Updated by João Silva almost 11 years ago

From http://stackoverflow.com/questions/24073127/opencvs-rotatedrect-angle-does-not-provide-enough-information, I think this can be solved this way:

RotatedRect rotated_rect = minAreaRect(contour);
float blob_angle_deg = rotated_rect.angle;
if (rotated_rect.size.width < rotated_rect.size.height) {
blob_angle_deg = 90 + blob_angle_deg;
}
Mat mapMatrix = getRotationMatrix2D(center, blob_angle_deg, 1.0);

So, in fact, RotatedRect's angle does not provide enough information for knowing an object's angle, you must also use RotatedRect's size.width and size.height.

Due to the number of questions about this issue in the Internet, maybe this should be clarified. Even if only in the documentation.

Contrarily to most of the other functions in OpenCV's API this feature seems difficult to understand. For instance, see http://shiyuzhao1.wordpress.com/2013/10/08/how-is-the-anlge-in-roatedrect-defined/ where the author writes "I bet you can never guess how the angle of a RoatedRect is defined."

What would be the disadvantages of making RotatedRect's angle consist in an value such that passing the symmetric to e.g. getRotationMatrix2D would allow to deskew the object enclosed by the RotatedRect?

Updated by Alexander Karsakov almost 11 years ago

Hi João,
thanks for reporting this issue.

I think RotatedRect provide general information which can be used in different way. But since OpenCV users are facing with determining object angle it should be clarified in documentation.
Since our resources are limited and you've done great investigation, could you please work on updating documentation? We will be grateful for this contribution.

  • Category set to imgproc, video
  • Status changed from New to Open

Updated by João Silva over 10 years ago

OK. Are there instructions for that specific contribution type, i.e. how do I change the documentation in general terms? Thanks.

Updated by Steven Puttemans over 10 years ago

Basic guidelines can be found here: http://code.opencv.org/projects/opencv/wiki/How_to_contribute
As to the documentation, look at the rst files that are in each module, they contain the docs related to the modules.

Updated by João Silva over 10 years ago

Hi followed the steps in http://code.opencv.org/projects/opencv/wiki/How_to_contribute but I'm not being able to build the documentation.

I tried:

sphinx-build opencv/doc/ tmp

but:

writing output... [ 0%] index
Exception occurred:
File "/usr/local/lib/python2.7/dist-packages/Sphinx-1.2.2-py2.7.egg/sphinx/environment.py", line 1093, in get_doctree
f = open(doctree_filename, 'rb')
IOError: [Errno 2] No such file or directory: u'/home/jmss/tmp/.doctrees/index.doctree'

I also tried cmake, make, make install but in the installation directory there are no HTML or PDF files.

How can I generate the HTML or PDF for testing the chages I made to /modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst?

Thanks.

Updated by João Silva over 10 years ago

From OpenCV answers I was told to run "make doc" to generate the documentation. I was able to test the changes in PDF format. It seeems HTML files are not generated. Could not work out with sphinx, still.

I created the pull request.

Updated by Roman Donchenko over 10 years ago

make html_docs will build the HTML version. You can't use Sphinx directly, since we do some... tricky things with it.

Updated by Steven Puttemans over 10 years ago

Pull request link added!

  • Pull request set to https://github.com/Itseez/opencv/pull/2877

Updated by Vadim Pisarevsky almost 10 years ago

  • Category changed from imgproc, video to documentation

Updated by Maksim Shabunin over 9 years ago

Issue has been transferred to GitHub: https://github.com/Itseez/opencv/issues/4764

Also available in: Atom PDF