How to use convexityDefects in Opencv 2.4

前端 未结 2 785
情话喂你
情话喂你 2020-12-22 05:14

I try to use convexHull and convexityDefects to define a hand. But when the program hit the convexityDefects, there is always an error

2条回答
  •  天命终不由人
    2020-12-22 05:37

    It looks like the issue is that convexityDefects() expects an array for the contourDefects parameter:

    void convexityDefects(InputArray contour, InputArray convexhull, OutputArray convexityDefects);
    

    Both contours and hull are vector> types, which is correct, but defects also needs to be a vector>. That way when you loop through the contours array, defects[i] will contain an array to pass to convexityDefects():

    ...
    
    vector> defects( contours.size() ); 
    
    ...
    

    Later on in your code, you will have to loop through the defects[i] vector to print the depth as well, if that is what you were trying to do.

提交回复
热议问题