我使用this作为制作更好的车辆计数器的基础,但roi行在屏幕中间硬编码:cv.line(input_frame, (0, int(height/2)), (int (width), int(height/2)), (0, 0xFF, 0), 5)
像这样,我正在寻找两种使之动态化的方法,或者让用户画图(如果仅找到rectangles的教程和答案,或者通过单击鼠标使其在屏幕中上下移动)。
先感谢您。
最佳答案
看看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)
关于python - 如何在开放式简历中使ROI线移动或让用户用鼠标绘制它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54271706/