python - Hough circle transform to circular shadow -


i have image in trying apply hough circle transforms circular objects in view.

i having difficulty finding circle fits outer shadow of cyclinder. can done segment shadow , fit circle it?

code:

img = cv2.medianblur(im,7) cimg = cv2.cvtcolor(img,cv2.color_gray2bgr)  plt.imshow(cimg) plt.show()  circles = cv2.houghcircles(img,cv2.hough_gradient,1,20,                             param1=50,param2=150,minradius=100,maxradius=0)  circles = np.uint16(np.around(circles))  in circles[0,:]:     # draw outer circle     cv2.circle(cimg,(i[0],i[1]),i[2],(255,0,0),10)     # draw center of circle     cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),20)      radius = i[2]     print 'radius', radius, 'px'  plt.imshow(cimg) plt.show() 

i'm going write out code , not go through because there's lot of functions , hate assume know or don't know , spend long time doing write-up. if have any questions feel free ask , i'll add them in post.

you asked fit circle crescent shadows, i've fitted circles shadows. it's important realize in kind of production code would, imagine, have process lot of images of nature necessary refine circles fitted. in particular kind of structural analysis of type worried fitting given shape pixels, not object in question you're looking for.

i've intentionally left wrongly-fitted circle in there. suggest going convexhull, or haar detector or shape matching depending on you're interested in.

import cv2  import numpy np  img = cv2.imread("orig.png", cv2.imread_grayscale)  ret, thresh = cv2.threshold(img, 80, 255, cv2.thresh_binary_inv)  ero = cv2.erode(thresh, np.ones((5,5))) dil = cv2.dilate(ero, np.ones((5,5)))  img, contours, hierarchy = cv2.findcontours(dil, cv2.retr_external,                                             cv2.chain_approx_none)  #just drawing purposes, cimg not required cimg = cv2.cvtcolor(img, cv2.color_gray2bgr) cnt in contours:     (x, y), radius = cv2.minenclosingcircle(cnt)     center = (int(x), int(y))     radius = int(radius)     cv2.circle(cimg, center, radius, (255, 0, 0), 1) 

the output image got

enter image description here

both crescents fitted correctly bottom 1 matching outside of tank , not crescent exactly. sort of hysteresis tracking , shift circle until it's outer edge precisely @ crescent consistently though.

there's additional circle can removed if tune parameters right filtering exact circles need you. f.e. if want top crescent ask smallest y coordinate, if shadows big these can ask circles of radii larger threshold etc...


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -