I have been working with OpenCV and Python.
I have been trying to find a gap where Hough lines do not cover an image.
The code that I have written so far has been this:
import cv2
import numpy as np
from numpy import mean
import matplotlib.pyplot as plt
def get_hough_lines(img, name):
try:
copies = img.copy()
inputImageGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(inputImageGray, 150, 200, apertureSize=3)
dtype = [('x1', float), ('y1', float), ('x2', float), ('y2', float)]
lines = cv2.HoughLinesP(edges, cv2.HOUGH_PROBABILISTIC, np.pi / 180,threshold = 30,minLineLength = 30,maxLineGap = 27)
for x in range(0, len(lines)):
for x1, y1, x2, y2 in lines[x]:
cv2.line(img,(x1,y1),(x2,y2),(0,128,0),2, cv2.LINE_AA)
font = cv2.FONT_HERSHEY_SIMPLEX
# Save image of what it like before
cv2.imwrite("before.jpg", copies)
# Save image of what it looked like after
cv2.imwrite("after.jpg", img)
return average_direction
except TypeError as e:
print('could not parse hough lines')
return None
except Exception as e:
print('could not parse hough lines')
return None
When you pass in an image of this:

The output image will be this:

The green lines show where the Hough Lines have been applied, but what I wan't to do and I am not sure how to do this is to identify 'large gaps' in the image where the Hough Lines were not drawn.
For example in the image below, the gap on the middle left and the top right.
If it helps, I have also tried thinking about the lines that get returned are x1,y1,x2,y2 so would form an array like this:
[[x1,y1,x2,y2], [x1,y1,x2,y2] ...]
I wasn't sure if you reshaped the individual arrays below like this:
[[[x1,y1][x2,y2]], [[x1,y1],[x2,y2]] ...]
Then you could model them as lines and create some kind of mesh or lattice and then find 'large gaps' based on that?
