伙計們!
我正在嘗試在這張非常嘈雜的影像上檢測矩形線。到目前為止,我能夠檢測到第一個 Rectangle 和外部矩形。但我找不到內部矩形。對我的問題有幫助嗎?太感謝了!
# 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)


轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/448633.html
