So I'm trying to find the corner of a painted plexiglas. The background and the corner itself is rough and textured. Here are two sample images:
Since the corner is a bit rounded, I think the best way to find the pixel coordinates of the corner is to interpolate the edges and find their intersection. The goal is to reliably find the pixel coordinates of the corner in a live webcam feed.
I did try to use the Canny edge detection and then HoughLinesP
import cv2
import numpy as np
image = cv2.imread(filename)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (9, 9), 0)
edges = cv2.Canny(blur, 150, 10)
rho = 1
theta = np.pi / 180
threshold = 45
min_line_length = 15
max_line_gap = 200
lines = cv2.HoughLinesP(edges, rho, theta, threshold, np.array([]),
min_line_length, max_line_gap)
for line in lines:
for x1, y1, x2, y2 in line:
cv2.line(image, (x1, y1), (x2, y2), (255, 0, 0), 1)
cv2.imshow('Corners', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
I was tweaking all the parameters randomly until I found something I was looking for:
My next step would be to cluster all those lines into groups and fit a single line to approximate the edges. I think my procedure is probably ugly and unreliable once I put it to a live webcam feed of these corners. Does someone have a better idea, or am I on a good track here?