Bounding box can possibly return a negative index (Bug #3283)
Description
Small situation description:
I have a background-foreground segmentation process on which an ellips has been fitted and that data has been supplied to my algorithm in the form of a txt file. I want to process the boundingbox of that provided ellipse data.
For this I fit a poly to the provided ellipse data and then calculate the boundingbox.
vector<Point> fit_line; // Note that current_ellipse is a struct containing my retrieved textfile data ellipse2Poly( Point(current_ellipse.x_center, current_ellipse.y_center), Size(current_ellipse.width, current_ellipse.heigth), current_ellipse.angle, 0.0, 360.0, 1.0, fit_line); Rect roi = boundingRect(fit_line); cout << roi << endl;
All of a sudden further processing breaks down. Last outputted roi was:
[449 x 179 from (-6, 54)]
Which is actually a correct bounding box match for the given ellipse data BUT which will lead to false processing if anyone wants to do something with that data in drawing context. This because the openCV interface doesn't allow to draw anything outside the positive coordinate plane.
From the point of view of the algorithm, it is correct, however from the point of view of all the other algorithms, this is delicate and dangerous.
I suggest inserting a warning inside the boundingbox function, that puts a warning on the screen that negative indexes occur. Or are there any other suggestions?
History
Updated by Vladislav Vinogradov over 11 years ago
Hello, Steven!
I think that idea to print some warning message on the screen is not a very good for library.
It is a developer's choice what to show for the end-user, not the library's.
Many OpenCV functions check input arguments and throw exceptions if something is wrong.
So, if a developer uses bounding box with negative indexes, he will get assertion failure and he will be forced to solve this issue.
Probably, we should add some notes to documentation for boundingRect
that it could return negative indexes and developer should check it before usage.
Updated by Steven Puttemans over 11 years ago
Ok agreed. Will take somewhere in the near feature (since I am leaving for a week) to make the update of the documentation and will submit a pullrequest then.
Updated by Steven Puttemans over 11 years ago
- Assignee changed from Vadim Pisarevsky to Steven Puttemans
- Status changed from New to Open
Updated by Steven Puttemans over 11 years ago
Pull request submitted: https://github.com/Itseez/opencv/pull/1538
- % Done changed from 0 to 70
Updated by Steven Puttemans over 11 years ago
- % Done changed from 70 to 100
- Status changed from Open to Done
- Assignee deleted (
Steven Puttemans)