How do I draw Convexity Defect using OpenCV Android ???

asked 2015-06-15 01:07:04 -0500

ichaka gravatar image

updated 2015-06-17 21:09:59 -0500

I'm doing my final project about hand gesture recognition using OpenCV in Android. So far I did until Convex Hull. Now, I want to draw convexity defect on it and get the defect value from it. But I am stack. I found some references codes, but most of it written in C++ code. I have no idea how to convert them into Java android code. Anyone, Would you mind to help me by convert this code? this is the C++ code :

/// Draw convexityDefects
for( int i = 0; i< contours.size(); i++ )
size_t count = contours[i].size();
if( count <300 )

vector<Vec4i>::iterator d=convdefect[i].begin();
while( d!=convdefect[i].end() ) {
Vec4i& v=(*d);
int startidx=v[0]; Point ptStart( contours[i][startidx] );
int endidx=v[1]; Point ptEnd( contours[i][endidx] );
int faridx=v[2]; Point ptFar( contours[i][faridx] );
float depth = v[3] / 256;

line( drawing, ptStart, ptEnd, Scalar(0,255,0), 1 );
line( drawing, ptStart, ptFar, Scalar(0,255,0), 1 );
line( drawing, ptEnd, ptFar, Scalar(0,255,0), 1 );
circle( drawing, ptFar,   4, Scalar(0,255,0), 2 );

I would be glad if you can solve this for me, because it's for my final project. Thanks a lot.

edit retag flag offensive close merge delete