-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
Fix issues in Convex Hull algorithm #27020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.x
Are you sure you want to change the base?
Conversation
I created a simpler patch (than for #26975) that is considerably slower but seems to be correct. |
To fix this issue entirely i would propose something like the following: Preferred signature: easy to be implemented fast and correct. allows for input validation.template<typename TpointContainer, typename Thull>
void convexHull(TpointContainer& points, std::vector<Thull>& hull, bool clockwise> Deprecated signature 1: does the same as the preferred signature, only deprecated because the last parameter should be removed.template<typename TpointContainer, typename Tpoints, typename Thull>
void convexHull(TpointContainer& points, std::vector<Thull>& hull, bool clockwise, bool ignored> Deprecated signature 2: the original function fixed to the point where it retains behavior as closely as possible while preventing memory errors.
|
a408412
to
6ae1ea1
Compare
Afaics tests fail now when they are using numerical arrays as input. I wouldn't know how to fix that except by explicitly converting (i use _InputArray::copyTo now)... but actually arrays are not documented as possible input for convexHull. How should i proceed? |
There is no array kind. I am puzzled by how to make this work with all the variants. In short: how can i convert numerical arrays, std::vector<Point_> and cv::Matx_<Point_> via InputArray to a continuous memory region of points? how to distinguish them and perform input validation? int arr[2] = {2,3};
Point* pt = (Point*) arr; Just going through getMat() doesn't work for numerical arrays. and: how should i handle the discrepancies with the documentation? |
@mshabunin could you take a look? |
@mshabunin Could you take a look on it? |
I couldn't reproduce original issue, waiting for more details (see #26952). |
Sorry for the delay. I'll try to continue now but I don't know if i have enough time to finish. |
i am just asking because i wonder... you wouldn't ask for a reproducer if it was something like std::vector({0,1,2})[99] (and i think it is even worse). anyway i am on it. |
Friendly reminder. |
for( i = 0; i < nout; i++ ) | ||
*(Point*)(hull.ptr() + i*step) = data0[hullbuf[i]]; | ||
} else { | ||
_hull.create(nout, 1, _hull.type()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_hull.type()
may be undefined, e.g. in Python case of it output is just cv::Mat. The original approach works better here.
for(int i = 0; i < bl_count-1; i++ ) | ||
hullbuf[nout++] = int(&pointer[bl_stack[i]] - pointer); | ||
for(int i = br_count-1; i > 0; i-- ) | ||
hullbuf[nout++] = int(&pointer[br_stack[i]] - pointer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&pointer[bl_stack[i]] - pointer
is just bl_stack[i]
, right?
for(int i = 0; i < tl_count-1; i++ ) | ||
hullbuf[nout++] = int(&pointer[tl_stack[i]] - pointer); | ||
for(int i = tr_count - 1; i > 0; i-- ) | ||
hullbuf[nout++] = int(&pointer[tr_stack[i]] - pointer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pointer[tl_stack[i]] - pointer
is just tl_stack[i]
, right?
Pull Request Readiness Checklist
See: #26952 and #26975
Patch to opencv_extra has the same branch name.