C++ - Find convexity defects of float contour [closed]

asked Apr 29 '19

jack_coach gravatar image

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

Preview: (hide)

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-15 14:32:43.245940

Comments

Can I just change or remove che typecheck

NO. you'd haveto change further instances of Point to Point2f here

also the defects calculated currently are Vec4i. wouldn't you need someting like Vec4f , then ? (which again would require changing the interfaces)

berak gravatar imageberak (Apr 29 '19)edit

I don't want to convert the vector from float to integer, as I am writing a time-sensitive application.

lol, PROVE, that it takes significant time to change a vector of Point2f to Point2i. tbh, this soundsa bit like "premature optimization".

berak gravatar imageberak (Apr 29 '19)edit

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?

jack_coach gravatar imagejack_coach (Apr 29 '19)edit