我正在进行车辆检测,我想画一个我可以检测到此代码的车辆可以检测到的区域:
import numpy as np
import cv2
drawing = False
ix = 0
iy = 0
def draw_line(event,x,y,flags,params):
global ix,iy,drawing
# Left Mouse Button Down Pressed
if(event==1):
drawing = True
ix = x
iy = y
if(event==0):
if(drawing==True):
#For Drawing Line
print('d')
cv2.line(img,pt1=(ix,iy),pt2=(x,y),color=(0,255,0),thickness=2)
ix = x
iy = y
# cv2.rectangle(image,pt1=(ix,iy),pt2=(x,y),color=(255,255,255),thickness=3)
if(event==4):
drawing = False
cv2.namedWindow("Window")
cv2.setMouseCallback("Window",draw_line)
path = "/home/omarubuntu/PFEomar/aaa.mp4"
cap = cv2.VideoCapture(path)
while(True):
ret, img = cap.read()
cv2.imshow("Window",img)
if cv2.waitKey(20) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
但是我无法获得结果,是否有任何方法可以使其起作用。 我不想使用矩形,因为我没有想要的区域。 请任何人能帮助我。