Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. Utils.bitmapToMat(myBitmap32, matImage);
  2.  
  3. Mat hsv = new Mat();
  4. Imgproc.cvtColor(matImage, hsv, Imgproc.COLOR_RGB2HSV);
  5.  
  6. Scalar lowerThreshold = new Scalar(0, 0.23 * 255, 50); // brown/skin color sana – lower hsv values
  7. Scalar upperThreshold = new Scalar(50, 0.68 * 255, 255); // brown/skin color sana – higher hsv values
  8. Mat segmentedImage = new Mat();
  9.  
  10. Core.inRange(hsv, lowerThreshold, upperThreshold, segmentedImage);
  11.  
  12. Mat dilatedMat = new Mat();
  13.  
  14. Imgproc.dilate(segmentedImage, dilatedMat, new Mat());
  15.  
  16.  
  17. List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
  18. Mat hierarchy = new Mat();
  19. Imgproc.findContours(dilatedMat, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
  20.  
  21. double maxVal = 0;
  22. int maxValIdx = 0;
  23. for (int contourIdx = 0; contourIdx < contours.size(); contourIdx++)
  24. {
  25. double contourArea = Imgproc.contourArea(contours.get(contourIdx));
  26. if (maxVal < contourArea)
  27. {
  28. maxVal = contourArea;
  29. maxValIdx = contourIdx;
  30. }
  31. }
  32.  
  33. Imgproc.drawContours(matImage, contours, maxValIdx, new Scalar(0,255,0), -1);
  34.  
  35.  
  36. final Bitmap resultBitmap = Bitmap.createBitmap(matImage.cols(), matImage.rows(), Bitmap.Config.ARGB_8888);
  37. Utils.matToBitmap(matImage, resultBitmap);`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement