Reputation: 429
I am trying to detect lines from noisy image and as a result I get too many lines. I need to iterate through lines multiple times and this is just too slow with so many lines, I am only interested in lines that are long enough.
My code to detect lines is as follows:
// Edge detection
int lowThreshold = 35;
Canny(greyMat, dst, lowThreshold, lowThreshold * 3, 3);
cv::blur(dst, dst, cv::Size(2,2));
// Standard Hough Line Transform
std::vector<cv::Vec2f> lines; // will hold the results of the detection
HoughLines(dst, lines, 1, rho_resolution, 150, 0, 0 ); // runs the actual detection
And the resulting image from Canny is
HoughLines will detect 100 lines, I am only interested in the long ones in the middle that form a rectangle. How can I remove the short lines? If I increase Canny threshold some lines I need are not detected.
Upvotes: 0
Views: 3848
Reputation: 555
blur the image to reduce the noise or little details in frame, it worked for me.
kernel = np.ones((5, 5), np.float32) / 25
smoothed = cv2.filter2D(frame, -1, kernel)
gray=cv2.cvtColor(smoothed, cv2.COLOR_BGR2GRAY)
edge=cv2.Canny(gray, 100, 150)
lines = cv2.HoughLines(edge, 1, np.pi / 180, 200)
print(lines)
Upvotes: 1
Reputation: 1702
General the method is to blur the image, which is done to make sure the noise is suppressed in the image leaving back only the actual edges of the objects to be detected.
The type of method used is subjective to the image. You can play around with Median or/and Gaussian Filter before extracting edges and check if you find any improvement.
Upvotes: 0