I have an image. img
in which I have detected lines using the approach here, the output is in lines
. The code for this is
img = cv2.imread('myfile.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
blur_gray = cv2.GaussianBlur(gray,(5, 5),0)
edges = cv2.Canny(blur_gray, 50, 150)
lines = cv2.HoughLinesP(edges, 1, np.pi / 180, 15, np.array([]), 50, 20)
Here lines
is a list of lines having start and end coordinates (x1,y1)
and (x2,y2)
.
I need to only retain those lines which lie inside a bounding polygon, which is in an image boundary
that has only the polygon edges in white, all other pixels are black. This image looks like this
How can I delete those lines in lines
from img
that do not lie inside the polygon I have in boundary
? Is there an efficient way to do this without manually checking end-points of each line in lines
to lie within the polygon?