I am working on a skeletal formula image processor in python as a chemistry project. It is still in its very early stages, but I've been stumped by a problem. When I run the image processing, singular lines are counted as multiple; as multiple lines are picked up from a single pen line. Therefore I need a way of discriminating between the lines and making it so there is one line registered per actual pen line so I can accurately count it as a CH3 group as it is in skeletal formula.
Here is my current code:
import cv2 as cv
import numpy as np
import math
image1 = cv.imread('test2.jpeg')
gray = cv.cvtColor(image1,cv.COLOR_BGR2GRAY)
canimg = cv.Canny(gray, 50, 200)
lines = cv.HoughLinesP(canimg, 1, np.pi/180.0, 80, np.array ([]), 70, 20)
N = lines.shape[0]
for i in range(N):
x1 = lines[i][0][0]
y1 = lines[i][0][1]
x2 = lines[i][0][2]
y2 = lines[i][0][3]
cv.line(image1,(x1,y1),(x2,y2),(255,0,0),2)
cv.imshow('Lines Detected',image1)
cv.imshow("Canny Detection", canimg)
cv.waitKey(0)
cv.destroyAllWindows()
See images attached as my problem demonstrated.
Any links / suggestions / comments / criticisms really appreciated to improve line detection in image processing.