Quantcast
Viewing all articles
Browse latest Browse all 41027

Adding MatOfPoint items to ArrayList-shape detection for Android

I'm using Java bindings for detecting simple shapes on Android. Here's my code following the [OpenCV](http://opencv-code.com/tutorials/detecting-simple-shapes-in-an-image/) tutorial. However, I get a null pointer exception when adding the approximate curve matrix (approx) to detected rectangles list (rectangles). What am I doing wrong? public boolean detectRectangle(){ boolean detected=false; Imgproc.findContours(touchedRegionBin.clone(), mContours= new ArrayList(), hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE); // private List approx = new ArrayList (); // private MatOfPoint2f contours2f= new MatOfPoint2f(); // private MatOfPoint2f approx2f = new MatOfPoint2f(); // private List mContours = new ArrayList(); for (int i = 0; i < mContours.size(); i++) { mContours.get(i).convertTo(contours2f, CvType.CV_32FC2); // Approximate contour with accuracy proportional // to the contour perimeter Imgproc.approxPolyDP(contours2f, approx2f, Imgproc.arcLength(contours2f, true)*0.02, true); Converters.Mat_to_vector_Point(approx2f, approx); // number of vertices if (approx.size() == 4 // && Math.abs(Imgproc.contourArea(contours2f)) > 1000 // && Imgproc.isContourConvex((MatOfPoint)approx) ) { double maxCosine = 0; // Get the degree (in cosines) of all corners for( int j = 2; j < 5; j++ ) { double cosine = Math.abs(angle( (approx.get(j%4)), approx.get(j-2), approx.get(j-1))); maxCosine = Math.max(maxCosine, cosine); } if( maxCosine <= 0.3 ){ rectangles.add((MatOfPoint) approx); boundingR = Imgproc.boundingRect(mContours.get(i)); detected= true; } } }//end of for return detected; }

Viewing all articles
Browse latest Browse all 41027


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>