Thresholding in Android using opencv -
not sure if right way ask, please help. have image of dented car. have process , highlight dents , return number of dents. able reasonably following result:
the matlab code is:
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 try using opencv, this:
with 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 obtain better results in opencv, , how count dents? tried findcontour() gives large number. tried on other images well, i'm not getting proper results. please help.
so matlab site, imtophat
- top-hat filtering computes morphological opening of image (using imopen) , subtracts result original image.
you in opencv following steps:
step 1: disk structuring element
kernel = cv2.getstructuringelement(cv2.morph_ellipse, (15, 15))
step 2: compute opening of image , subtract result original image
tophat = cv2.morphologyex(v, cv2.morph_tophat, kernel)
this gives following result -
step 3 - manually threshold or use otsu -
ret, thresh = cv2.threshold(tophat, 17, 255, 0)
which gives following image -
since op wants code in java, here probable code in 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; }
make sure on gray scale image (cvtype.8uc1
) , can threshold suitably.
Comments
Post a Comment