python - How do I get HoughLines to recognize the rest of the lines in this picture? -


in image below, can see i'm able recognize horizontal lines vertical ones aren't coming out great. in particular, none of middle lines of grids being seen , side lines being overdrawn (i.e. connected each other).

here's code created it:

img = cv2.imread('./p6.png') gray = cv2.cvtcolor(img,cv2.color_bgr2gray) threshhold, threshhold_img = cv2.threshold(gray, 0, 255, cv2.thresh_binary + cv2.thresh_otsu) edges = cv2.canny(threshhold_img, 150, 200, 3, 5) lines = cv2.houghlinesp(edges,1,np.pi/180,500, minlinelength = 600, maxlinegap = 75)[0].tolist()  x1,y1,x2,y2 in lines:     cv2.line(img,(x1,y1),(x2,y2),(0,255,0),1) 

when i've adjusted different parameters, end situations 1 middle vertical line (the 1 ending before jexxy in table) extends bottom through top of third grid. unless relax params every line drawn in, including ones representing yi, er, san @ top of first 3 grids, cannot code see middle verticals defining grid interiors.

how can fix this?

image hough lines drawn in

* updated use thresh_binary_inv without canny *

img = cv2.imread('./p6.png') gray = cv2.cvtcolor(img,cv2.color_bgr2gray) threshhold, threshhold_img = cv2.threshold(gray, 0, 255, cv2.thresh_binary_inv) lines = cv2.houghlinesp(edges,1,np.pi/180,500, minlinelength = 600, maxlinegap = 75)[0].tolist()  x1,y1,x2,y2 in lines:     cv2.line(img,(x1,y1),(x2,y2),(0,255,0),1) 

intermediate picture threshold_img using thresh_binary_inv

after doing thresh_binary_inv, lines output

* update: added threshold img using binary , otsu *

threshold_img thresh_binary + thresh_otsu

i think happens in case is difficult find set of parameters create both horizontal , vertical lines @ same time without lines "stealing" votes other lines. quick trick here , enforce detection of vertical lines only, while focus on dominant horizontal lines later:

# vertical lines lines = cv2.houghlinesp(     threshhold_img, 1, np.pi, threshold=100, minlinelength=100, maxlinegap=1)  # horizontal lines lines2 = cv2.houghlinesp(     threshhold_img, 1, np.pi / 2, threshold=500, minlinelength=500, maxlinegap=1) 

which gives me:

enter image description here


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -