C++ - Find convexity defects of float contour

asked 2019-04-29 03:37:52 -0500

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

edit retag flag offensive close merge delete

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 ( 2019-04-29 03:51:55 -0500 )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 ( 2019-04-29 03:54:34 -0500 )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 ( 2019-04-29 07:16:47 -0500 )edit