C++ - Find convexity defects of float contour [closed]
I have a contour represented by a std::vector<cv::point2f> and I have to find its convexity defects.
So I write these 2 lines (cHull is a vector of integer indices) :
cv::convexHull( calibContour , cHull ) ;
cv::convexityDefects( calibContour , cHull , defects )
And at runtime I get this error:
OpenCV Error: Assertion failed (npoints >= 0) in convexityDefects, file /home/nvidia/Desktop/opencv-3.3.1/modules/imgproc/src/convhull.cpp, line 274
terminate called after throwing an instance of 'cv::Exception'
what(): /home/nvidia/Desktop/opencv-3.3.1/modules/imgproc/src/convhull.cpp:274: error: (-215) npoints >= 0 in function convexityDefects
The 274th line of convexhull.cpp does in fact check for the presence of points in the contour, but only for signed integers:
npoints = points.checkVector(2, CV_32S);
Why is that so?
I don't want to convert the vector from float to integer, as I am writing a time-sensitive application.
Can I just change or remove che typecheck in the opencv code and rebuild it?
Thanks for your answers, cheers,
Giacomo
NO. you'd haveto change further instances of
Point
to Point2f herealso the defects calculated currently are
Vec4i
. wouldn't you need someting likeVec4f
, then ? (which again would require changing the interfaces)lol, PROVE, that it takes significant time to change a vector of Point2f to Point2i. tbh, this soundsa bit like "premature optimization".
I admit I might be paranoid about the time issue, in fact I am already converting the vector to move on, but still... cv::convexHull() accepts also vectors of floats, why cv:convexityDefects() shouldn't?