Invalid Arguments In Convexhull Android Ndk And Opencv
I have this C++ OpenCV code in my jni folder of android application hello-jni.cpp. I just want to find and draw convexhull but cause of hull[i] the convexhull method generate an er
Solution 1:
When you initialize hull
vector<vector<Point> > contours;
vector<vector<Point> > hull(contours.size());
hull
size is 0
, since contours
size is 0. So when you access hull[i]
you are accessing out of bounds.
Declare hull
after findContours
:
findContours(threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
vector<vector<Point> > hull(contours.size());
You can also simply call convexHull
as:
convexHull(contours[i], hull[i]);
since 3rd argument orientation
is false by default, and 4th argument returnPoints
is ignored when 2nd argument is a std::vector
.
thresh
value is ignored when you use THRESH_OTSU
.
UPDATE
It seems that there are some problems with Android NDK. A simple workaround is:
- disable the error for invalid arguments, or
- use the following
Code:
Mat mHull;
convexHull(Mat(contours[i]), mHull, false, true);
hull[i].assign(mHull.begin<Point>(), mHull.end<Point>());
Post a Comment for "Invalid Arguments In Convexhull Android Ndk And Opencv"