Reputation: 1
I'm new to CV, and I'm trying to detect an image in a computer screen. My approach is using Hough line transform to get possible edges that form the image. I was wondering why the standard cv2.HoughLines() doesn't work as well. Any insight helps. Thank you!
This is the original image: Original Image
Probabilistic Hough Line Transform code:
lines = cv2.HoughLinesP(
edges, # Input edge image
1, # Distance resolution in pixels
np.pi/180, # Angle resolution in radians
threshold=300, # Min number of votes for valid line
minLineLength=300, # Min allowed length of line
maxLineGap=10 # Max allowed gap between line for joining them
)
edges_color = cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR)
for points in lines:
x1,y1,x2,y2=points[0]
# Draw the lines joing the points
# On the original image
cv2.line(edges_color,(x1,y1),(x2,y2),(0,255,0),3)
Probabilistic Hough Line Transform result: Probabilistic Hough Transform Result
Standard Hough Line Transform code:
lines = cv2.HoughLines(
edges, # Input edge image
1, # Distance resolution in pixels
np.pi/180, # Angle resolution in radians
threshold=300, # Min number of votes for valid line
)
edges_color = cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR)
for line in lines:
for rho,theta in line:
a=np.cos(theta)
b=np.sin(theta)
x0=a*rho
y0=b*rho
x1=int(x0+1000*(-b))
y1=int(y0+1000*(a))
x2=int(x0-1000*(-b))
y2=int(y0-1000*(a))
cv2.line(edges_color,(x1,y1),(x2,y2),(255,0,0),2)
Standard Hough Line Transform result: Standard Hough Line Transform Result
Upvotes: 0
Views: 65