Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Utils.bitmapToMat(myBitmap32, matImage);
- Mat hsv = new Mat();
- Imgproc.cvtColor(matImage, hsv, Imgproc.COLOR_RGB2HSV);
- Scalar lowerThreshold = new Scalar(0, 0.23 * 255, 50); // brown/skin color sana – lower hsv values
- Scalar upperThreshold = new Scalar(50, 0.68 * 255, 255); // brown/skin color sana – higher hsv values
- Mat segmentedImage = new Mat();
- Core.inRange(hsv, lowerThreshold, upperThreshold, segmentedImage);
- Mat dilatedMat = new Mat();
- Imgproc.dilate(segmentedImage, dilatedMat, new Mat());
- List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
- Mat hierarchy = new Mat();
- Imgproc.findContours(dilatedMat, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
- double maxVal = 0;
- int maxValIdx = 0;
- for (int contourIdx = 0; contourIdx < contours.size(); contourIdx++)
- {
- double contourArea = Imgproc.contourArea(contours.get(contourIdx));
- if (maxVal < contourArea)
- {
- maxVal = contourArea;
- maxValIdx = contourIdx;
- }
- }
- Imgproc.drawContours(matImage, contours, maxValIdx, new Scalar(0,255,0), -1);
- final Bitmap resultBitmap = Bitmap.createBitmap(matImage.cols(), matImage.rows(), Bitmap.Config.ARGB_8888);
- Utils.matToBitmap(matImage, resultBitmap);`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement