Threshold in Android using opencv

Not sure if this is the right way to ask, but please help. I have an image of a rumpled car. I have to process it and extract the dents and return the number of dents. I was able to do this quite well with the following result:

enter image description here

enter image description here

Matlab code:

  img2=rgb2gray(i1);
  imshow(img2);
  img3=imtophat(img2,strel('disk',15));
  img4=imadjust(img3);
  layer=img4(:,:,1);
  img5=layer>100 & layer<250;
  img6=imfill(img5,'holes');
  img7=bwareaopen(img6,5);
  [L,ans]=bwlabeln(img7);
  imshow(img7);
  I=imread(i1);
  Ians=CarDentIdentification(I);

However, when I try to do this using opencv, I get the following:

enter image description here

With the following code:

   Imgproc.cvtColor(source, middle, Imgproc.COLOR_RGB2GRAY);
    Imgproc.equalizeHist(middle, middle);
    Imgproc.threshold(middle, middle, 150, 255, Imgproc.THRESH_OTSU);

Please tell me how can I get the best results in opencv, as well as how to count dents? I tried findcontour (), but it gives a very large amount. I also tried on other images, but I do not get the proper results. Please, help.

+4
source share
1

, MATLAB, imtophat - Top-hat ( imopen), .

OpenCV :

1. < <

kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (15, 15))

2: ,

tophat = cv2.morphologyEx(v, cv2.MORPH_TOPHAT, kernel)

:

Tophat

3 - Otsu -

ret, thresh = cv2.threshold(tophat, 17, 255, 0)

-

topHat thresholded

OP Java, Java:

private Mat topHat(Mat image)
{
Mat element  = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(15, 15), new Point (0, 0));
Mat dst = new Mat;
Imgproc.morphologyEx(image, dst, Imgproc.MORPH_TOPHAT, element, new Point(0, 0));

return dst;
}

, (CvType.8UC1), .

+1

Source: https://habr.com/ru/post/1682292/


All Articles