OpenCV C++ Conversion to Java for Shape Detection Issues

asked 2014-06-05 15:53:59 -0600

bolo gravatar image

updated 2014-06-05 15:55:03 -0600

We are a bit new to the openCV Java development and ran across an issue.

We are trying to convert this code to Java for Android.

The approxPolyDp requires a MatOfPoint2f where we have 'approx' parameter. Though, when we need to use this same variable in the if statement just after for the isContourConvex, it requires a MatOfPoint. The original code in the first place was using a ArrayList for approx. We're very confused by this and need a nudge in the right direction to understand what we're supposed to do.

// Find contours
java.util.ArrayList<java.util.ArrayList<Point>>();
List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat hierarchy = new Mat();
Imgproc.findContours(bw.clone(), contours, hierarchy, Imgproc.RETR_EXTERNAL,       Imgproc.CHAIN_APPROX_SIMPLE);

// java.util.ArrayList<Point> approx = new java.util.ArrayList<Point>();
MatOfPoint2f approx = new MatOfPoint2f();

Mat dst = img.clone();

for (int i = 0; i < contours.size(); i++)
{
// Approximate contour with accuracy proportional
// to the contour perimeter
MatOfPoint2f contoursMat2 = new MatOfPoint2f( contours.get(i));

Imgproc.approxPolyDP(contoursMat2, approx, Imgproc.arcLength(contoursMat2, true) * 0.02, true);

// Skip small or non-convex objects 
if (Math.abs(Imgproc.contourArea(contours.get(i))) < 100 || !Imgproc.isContourConvex(approx))
continue;
edit retag flag offensive close merge delete

Comments

Why did you try to convert it to java? You can work with OpenCV with Java and C++ at the same project. Follow this link http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html?highlight=native . And there is a lot of information on web.

itay gravatar imageitay ( 2014-07-08 05:26:53 -0600 )edit