I have an image and I want to get the red grid out of this image. I tried already with the HoughlinesP function and this works (see enter image description here), but right now i want to do this with the HoughLines function, because this is faster. The problem is that the output of this one is not a [x1,y1,x2,y2], but it is [rho, theta].
I already tried to converse it like this:
line_coordinates = []
for line in lines:
for rho,theta in line:
x1 = int(rho * math.cos(theta))
y1 = int(rho * math.sin(theta))
x2 = int(x1 + 1000 * (-math.sin(theta)))
y2 = int(y1 + 1000 * (math.cos(theta)))
line_coordinates.append([x1, y1, x2, y2])
cv2.line(imgOriginal, (x1, y1), (x2, y2), (0, 0, 255), 2)
But if i do this, then i get something like this: enter image description here, how can i make this conversion better?
I am using this as functions:
imgOriginal = cv2.imread(path, cv2.IMREAD_COLOR)
hsv = cv2.cvtColor(imgOriginal, cv2.COLOR_BGR2HSV)
mask_red = cv2.inRange(hsv, np.array([150, 25, 150]), np.array([180, 255, 255]))
mask_red_extra = cv2.inRange(hsv, np.array([1, 25, 150]), np.array([40, 255, 255]))
red_mask = mask_red + mask_red_extra
cv2.imshow('edges', red_mask)
threshold = 150
lines = cv2.HoughLines(red_mask, 1, np.pi/180, threshold)
hough_lines = cv2.HoughLinesP(red_mask, 1, np.pi / 180, threshold=50, minLineLength=75, maxLineGap=300)
and right here the original picture: enter image description here
No. Cannot output of a
Houghlinesfunction to one of theHoughlinesPfunction?Use
HoughLinesinstead ofHoughLinesPSnippet:
Screenshot: