I have a 2d drawing of a element (isometric view) as follow:
I would like to extract only the thick, longest black line (element with arrows embedded in it not dimensions) from it.
How to achieve that ?
For now my code goes as follow
import cv2
import numpy as np
inputImage = cv2.imread("iso.jpg")
inputImageGray = cv2.cvtColor(inputImage, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(inputImageGray, 150, 200, apertureSize=3)
minLineLength = 30
maxLineGap = 5
lines = cv2.HoughLinesP(
image=edges,
rho=cv2.HOUGH_PROBABILISTIC,
theta=np.pi / 180,
threshold=30,
minLineLength=minLineLength,
maxLineGap=maxLineGap,
)
for x in range(0, len(lines)):
for x1, y1, x2, y2 in lines[x]:
pts = np.array([[x1, y1], [x2, y2]], np.int32)
cv2.polylines(inputImage, [pts], True, (0, 255, 0))
cv2.imshow("Result", inputImage)
cv2.imshow("Edges", edges)
cv2.waitKey(0)
Which gives fallowing result - it detect all lines also thin ones, text brackets etc.


Sorry, I posted this under a misunderstanding. This is not what the OP wanted. The post was not clear. He apparently wants the medium thick lines with the arrows (from his subsequent comment).
Nevertheless, perhaps this will help someone else on a different project. So here is one way to get the thickest black lines using Python/OpenCV.
Input:
Results:
You can use contours to extract each one separately if that is needed.