Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. Imgproc.findContours(cont, contours, hierarchy, Imgproc.RETR_CCOMP, Imgproc.CHAIN_APPROX_SIMPLE, new Point(0, 0));
  2.         cleanedMatList = new ArrayList<Mat>();
  3.         int c = 0;
  4.  
  5.         for (int i = 0; i >= hierarchy.cols(); i++) {
  6.             Rect rect = Imgproc.boundingRect(contours.get(i));
  7.             if (rect.height > HTRESH) {
  8.                 Imgproc.rectangle(binary, new Point(rect.x, rect.y), new Point(rect.x + rect.width - 1, rect.y + rect.height - 1), new Scalar(0, 0, 255), 3);
  9.                 cleanedMatList.add(c, binary);
  10.                 c++;
  11.             }
  12.         }
  13.  
  14.         List<MatOfInt> digitsHull = new ArrayList<MatOfInt>();
  15.         for(int i=0; i < contours.size(); i++){
  16.             digitsHull.add(new MatOfInt());
  17.         }
  18.         for(int i=0; i < contours.size(); i++){
  19.             Imgproc.convexHull(contours.get(i), digitsHull.get(i));
  20.         }
  21.  
  22.         List<MatOfPoint> digitRegions = new ArrayList<MatOfPoint>();
  23.  
  24.         for (int i = 0; i< digitRegions.size(); i++) {
  25.             MatOfPoint dr = digitRegions.get(i);
  26.             dr.push_back(digitsHull.get(i));
  27.         }
  28.  
  29.         Mat digitsMask = new Mat(srcImage.rows(), srcImage.cols(), CvType.CV_8U);
  30.         Imgproc.drawContours(digitsMask, digitRegions, 0, new Scalar(255, 255, 255), -1);
  31.         Imgproc.morphologyEx(digitsMask, digitsMask, Imgproc.MORPH_DILATE, kernal);
  32.  
  33.         Mat cleaned = new Mat(srcImage.rows(), srcImage.cols(), CvType.CV_8U);
  34.         diwb.copyTo(cleaned, digitsMask);
  35.  
  36.         return diwb;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement