I want to detect lines in a picture like this:
And my code is like this:
import numpy as np
import cv2
import math
# prepare the image
image = cv2.imread("image")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (3,3), 0)
ret3,thesh = cv2.threshold(blurred,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
# line detection
rho=1
theta=math.pi/180
thresh = 10
minLength= 30
maxGap= 5
lines = cv2.HoughLinesP(th3.copy(), 1, rho, thresh, minLength, maxGap)
img = image.copy()
for line in lines:
for x1,y1,x2,y2 in line:
cv2.line(image,(x1,y1),(x2,y2),(255,0,0),1)
It seems that HoughLinesP is not able to detect the horizontal lines, no matter what value of the parameters above I twisted. Is there a way to detect both the horizontal and vertical lines ?
Many thanks !