python - Blob detection using OpenCV -


i trying white blob detection using opencv. script failed detect big white block goal while small blobs detected. new opencv, , doing wrong when using simpleblobdetection in opencv? [solved partially, please read below]

and here script:

#!/usr/bin/python  # standard imports import cv2 import numpy np;  matplotlib import pyplot plt  # read image im = cv2.imread('whiteborder.jpg', cv2.imread_grayscale) imfiltered = cv2.inrange(im,255,255)  #opening kernel = np.ones((5,5))  opening = cv2.morphologyex(imfiltered,cv2.morph_open,kernel)  #write out filtered image  cv2.imwrite('colorfiltered.jpg',opening)   # setup simpleblobdetector parameters. params = cv2.simpleblobdetector_params()  params.blobcolor= 255 params.filterbycolor = true   # create detector parameters ver = (cv2.__version__).split('.') if int(ver[0]) < 3 :     detector = cv2.simpleblobdetector(params) else :      detector = cv2.simpleblobdetector_create(params)   # detect blobs. keypoints = detector.detect(opening)  # draw detected blobs green circles. # cv2.draw_matches_flags_draw_rich_keypoints ensures # size of circle corresponds size of blob  print str(keypoints)  im_with_keypoints = cv2.drawkeypoints(opening, keypoints, np.array([]), (0,255,0), cv2.draw_matches_flags_draw_rich_keypoints)  # show blobs ##cv2.imshow("keypoints", im_with_keypoints)  cv2.imwrite('keypoints.jpg',im_with_keypoints)  cv2.waitkey(0) 

edit:

by adding bigger value of area maximum value, able identify big blob end goal identify big white rectangle exist or not. , white blob detection did returns not rectangle surrounding areas well. [this part solved]

edit 2:

based on answer @pschn, update code apply logic, first set color filter white pixels , remove noise point using opening. works sample data , can keypoint after blob detection. enter image description here

if want detect white rectangle can try set higher threshold, e.g. 253, erase small object opening , take biggest blob. first smoothed image, thresholding it:

enter image description here

and opening:

enter image description here

now have use findcontours , take boundingrect. if rectangle white should work. if lower 251 threshold other small blobs appear , region merges them, here:

enter image description here

then still opening several times , this: enter image description here

but dont think fastest idea ;)


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -