ucisysarch / opencvjs

JavaScript Bindings for OpenCV
Other
577 stars 108 forks source link

convexityDefects #16

Open Bluejay47 opened 7 years ago

Bluejay47 commented 7 years ago

Can anyone offer tips on how to interpret the results of the convexityDefects method? I am seeing a 1 col n row Mat with 16 values like this:

defects.row(0).data(): Uint8Array[16]
0:183
1:4
2:0
3:0
4:228
5:5
6:0
7:0
8:94
9:3
10:0
11:0
12:25
13:129
14:1
15:0

... and having problems mentally mapping that to the struct I would get from C.

struct CvConvexityDefect
{
   CvPoint* start; // point of the contour where the defect begins
   CvPoint* end; // point of the contour where the defect ends
   CvPoint* depth_point; // the farthest from the convex hull point within the defect
   float depth; // distance between the farthest point and the convex hull
};

Thanks.

kylemcdonald commented 7 years ago

.data() is a Uint8Array which means that you will need to access the data in a different way if you know there are CvPoints and floats. I used get_int_at() to do this with the output from cv.findContours. Maybe you can do something similar here?