I'm using cv2.HoughlinesP to find the coordinates for each line in a document image. I'm getting 2 line coordinates when using HoughlinesP when there is only 1 line. How can I combine these two coordinates or treat them as if they are for the same line instead of treating them as separate lines.
The issue, is that because I'm using coordinates obtained from houghlinesp, the lines are treated as if they are rectangular boxes, as in the top endpoints of the line are separate, and the bottom endpoints of the line are treated separately. Therefore 2 separate line coordinates are given instead of coordinates for 1 line.
So in this case where this form has 7 lines being detected, when I use HoughlinesP to get these line coordinates, I get 14 different coordinates.
import cv2
from google.colab.patches import cv2_imshow
import numpy as np
#image preprocessing
img= cv2.imread('page9.png')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
#First, get the gray image and process GaussianBlur.
kernel_size = 5
blur_gray = cv2.GaussianBlur(gray,(kernel_size, kernel_size),0)
#Second, process edge detection use Canny.
low_threshold = 50
high_threshold = 150
edges = cv2.Canny(blur_gray, low_threshold, high_threshold)
#Then, use HoughLinesP to get the lines.
rho = 1 # distance resolution in pixels of the Hough grid
theta = np.pi / 180 # angular resolution in radians of the Hough grid
threshold = 25 # minimum number of votes (intersections in Hough grid cell)
min_line_length = 150 # minimum number of pixels making up a line
max_line_gap = 3 # maximum gap in pixels between connectable line segments
line_image = np.copy(img) * 0 # creating a blank to draw lines on
# Run Hough on edge detected image
# Output "lines" is an array containing endpoints of detected line segments
lines = cv2.HoughLinesP(edges, rho, theta, threshold, np.array([]),
min_line_length, max_line_gap)
print(len(lines))
and this is the output I get showing the number of line coordinates :
13