Find close up corner with python and opencv

130 Views Asked by At

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:

enter image description here

enter image description here

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:

enter image description here

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?

0

There are 0 best solutions below