Home > Blockchain >  Rectangle detection on noisy image Python
Rectangle detection on noisy image Python

Time:03-22

guys!

I'm trying to detect rectangles lines on this very noisy image. So far I was able to detect the first Rectangle and the outside rectangle. But I not able to find the inner rectangles. Any help to my problem? Thank you so much!

# import the necessary packages
import cv2
import numpy as np
# Read image
img = cv2.imread('test8_2.jpg', cv2.IMREAD_COLOR) # road.png is the filename
# Convert the image to gray-scale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Find the edges in the image using canny detector
edges = cv2.Canny(gray, 60, 120)
# Detect points that form a line
lines = cv2.HoughLinesP(edges, 1, np.pi/180, 15, minLineLength=10, maxLineGap=40)
# Draw lines on the image
for line in lines:
    x1, y1, x2, y2 = line[0]
    cv2.line(img, (x1, y1), (x2, y2), (255, 0, 0), 3)
# Show result
cv2.imshow("Result Image", img)
cv2.waitKey(0)

enter image description here

enter image description here

  • Related