我试图检测球场的轮廓,但是它无法拾取图像的矩形形状。
b,g,r = cv2.split(img)
rgb_img = cv2.merge([r,g,b])
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,100,200,apertureSize = 3)
lines = cv2.HoughLines(edges,1,np.pi/180,200)
for rho,theta in lines[0]:
a = np.cos(theta)
b = np.sin(theta)
x0 = a*rho
y0 = b*rho
x1 = int(x0 + 1000*(-b))
y1 = int(y0 + 1000*(a))
x2 = int(x0 - 1000*(-b))
y2 = int(y0 - 1000*(a))
cv2.line(img,(x1,y1),(x2,y2),(0,0,255),2)
检测到的线条呈红色,仅显示在图像的右侧。
*我也尝试过HoughLinesP(),但它会选择不需要的行。还尝试调整阈值和最小和最大线长度。
** Input Image
答案 0 :(得分:0)
图片可能有彩色通道。请从这里获得帮助。
https://github.com/opencv/opencv/blob/master/samples/python/squares.py