python - 如何在开放式简历中使ROI线移动或让用户用鼠标绘制它

标签 python python-3.x opencv tensorflow

我使用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/

相关文章:

适合菜鸟的 Python 数据包嗅探器和套接字

list - 将 Python 3 列表写入 .csv

python - 为什么 Python 的行为就像我的字典是一个列表?

c++ - 使用 waitKey 暂停和播放视频

python - 如何将整数从任何基数转换为任何其他基数?

python - 从 python 脚本,更改用户,设置环境并运行几个命令

python - 与 Pandas 总结几个月

python-3.x - 在Windows 7上为Python3安装OpenCV之后,运行时错误R6034

algorithm - 检测物体之间距离的最快方法?

python - 如何在 Windows 上安装 OpenCV 并在不使用包管理器的情况下为 PyCharm 启用它