Convex Hull on Java Android Opencv 2.3 -


please me,

i have problem convex hull on android. use java , opencv 2.3.

before made on java, made on c++ visual studio 2008.

this code can running on c++.

now, want convert c++ java on android. , found error "force close" when run on sdk android simulator.

this code on c++:

vector<vector<point> > contours; vector<vec4i> hierarchy;  findcontours( canny_output, contours, hierarchy, cv_retr_tree, cv_chain_approx_simple, point(0, 0) ); drawing = mat::zeros( canny_output.size(), cv_64f );  /// find convex hull object each contour vector<vector<point> > hull ( contours.size() ); for( int = 0; < contours.size(); i++ )   {  convexhull( mat(contours[i]), hull[i], false ); }  for(size_t = 0; < contours.size(); i++){     drawcontours( drawing, hull, i, scalar(255, 255, 255), cv_filled ); // fill white color } 

and code on android:

mat hierarchy = new mat(img_canny.rows(),img_canny.cols(),cvtype.cv_8uc1,new scalar(0));     list<mat> contours =new arraylist<mat>();     list<mat> hull = new arraylist<mat>(contours.size());     drawing = mat.zeros(img_canny.size(), im_gray);      imgproc.findcontours(img_dilasi, contours, hierarchy,imgproc.retr_tree, imgproc.chain_approx_simple, new point(0, 0));      for(int i=0; i<contours.size(); i++){         imgproc.convexhull(contours.get(i), hull.get(i), false);      }     for(int i=0; i<contours.size(); i++){         imgproc.drawcontours(drawing, hull, i, new scalar(255.0, 255.0, 255.0), 5);     } 

for info, did little modification on convex hull @ code. i fill color inside contour.

anyone can me solve problem?

i'm grateful help.

don't have rep add comment, wanted 2 answers above helped me imgproc.convexhull() working use case (2.4.8):

matofpoint mopin = ... matofint hull = new matofint(); imgproc.convexhull(mopin, hull, false);  matofpoint mopout = new matofpoint(); mopout.create((int)hull.size().height,1,cvtype.cv_32sc2);  for(int = 0; < hull.size().height ; i++) {     int index = (int)hull.get(i, 0)[0];     double[] point = new double[] {         mopin.get(index, 0)[0], mopin.get(index, 0)[1]     };     mopout.put(i, 0, point); }            // interesting mopout 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -