Convex Hull on Java Android OpenCV 2.3

asked 2013-07-11 02:59:40 -0500

Jenang gravatar image

updated 2013-07-11 03:05:53 -0500

Please help me,

I have a problem for Convex Hull on Android. I use Java and OpenCV 2.3.

Before I made it on Java, I made it on C++ with Visual Studio 2008.

This code can running successfully on C++.

Now, i want to convert it from C++ to Java on Android. And I found error like "force close" when i run it on SDK Android simulator.

This is my code on C++:

vector<vector<Point> > contours;
vector<Vec4i> hierarchy;

Canny( img_gray, canny_output, thresh, thresh*2, 3 );
cv::dilate(canny_output, canny_output, cv::Mat(), cv::Point(-1,-1));
showCannyWindow();

findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
drawing = Mat::zeros( canny_output.size(), CV_64F );

/// Find the convex hull object for each contour
vector<vector<Point> > hull ( contours.size() );
for( int i = 0; i < contours.size(); i++ )
  {  convexHull( Mat(contours[i]), hull[i], false );
}

for(size_t i = 0; i < contours.size(); i++){
    drawContours( drawing, hull, i, Scalar(255, 255, 255), CV_FILLED ); // FILL WHITE COLOR
}

And this is my 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 your info, I did a little modification on Convex Hull at my code. I fill a color inside contour.

This is sample image result on C++:

Binary Image (Before Convex Hull and Fill Color):

image description

After Convex Hull and Fill Color:

image description

Anyone can help me to solve my problem?

I'm very grateful for your help.

edit retag flag offensive close merge delete

Comments

Isn't anyone can help me?

Jenang gravatar imageJenang ( 2013-07-11 23:01:30 -0500 )edit

Have you solved this?

Peliks gravatar imagePeliks ( 2013-07-25 12:45:32 -0500 )edit
JamieCorkhill gravatar imageJamieCorkhill ( 2017-09-19 08:41:11 -0500 )edit