我正在使用this作为制造更好的车辆计数器的基础,但roi行在屏幕中间硬编码:cv.line(input_frame, (0, int(height/2)), (int (width), int(height/2)), (0, 0xFF, 0), 5)
像这样,我正在寻找两种使之动态化的方法,或者让用户绘制,如果仅找到rectangles的教程和答案,或者通过单击鼠标使其在屏幕中向上或向下移动,便可以使它动态化。
预先谢谢你。
答案 0 :(得分:1)
看看here 您需要捕获鼠标坐标,然后使用cv.line
def click_and_crop(event, x, y, flags, param):
# grab references to the global variables
global refPt, cropping
# if the left mouse button was clicked, record the starting
# (x, y) coordinates and indicate that cropping is being
# performed
if event == cv2.EVENT_LBUTTONDOWN:
refPt = [(x, y)]
cropping = True
# check to see if the left mouse button was released
elif event == cv2.EVENT_LBUTTONUP:
# record the ending (x, y) coordinates and indicate that
# the cropping operation is finished
# y = height x = width
refPt.append((x, y))
cropping = False
# draw a rectangle around the region of interest
#cv.line(input_frame, (0, int(height/2)), (int (width), int(height/2)), (0, 0xFF, 0), 5)
cv2.line(image,(0, int(y)), (int(width), int(y)), (0, 255, 0), 2)
cv2.imshow("image", image)