python鼠标画点连线,使用Python OpenCV库使用鼠标单击在图像上画一条线

该博客介绍了如何利用Python的OpenCV库通过鼠标操作在图像上绘制线条。当点击鼠标左键开始拖动到释放时,应显示线条,但实际未出现。问题在于捕获鼠标事件并记录坐标的过程。解决方案提供了一个名为DrawLineWidget的类,它跟踪鼠标点击事件,记录起始和结束点,并在释放鼠标时在图像上绘制线条。
摘要由CSDN通过智能技术生成

I am trying to draw a line on an image using mouse operations. I am using OpenCV library. My code

import matplotlib.pyplot as plt

import cv2

src_window = 'CV2 Window'

SHOW_DEBUG_STEPS = True

drag = 0

select_flag = 0

x1 = 0

x2 = 0

y1 = 0

y2 = 0

point1 = [x1,y1]

point2 = [x2,y2]

SCALAR_YELLOW = (0.0,255.0,255.0)

cap = cv2.VideoCapture('example_01.mp4')

def closeAll():

cap.release()

cv2.destroyAllWindows()

def retn(ret):

if not ret:

print('Error reading the frame')

closeAll()

def frm(fFrame):

if fFrame is None:

print('Error reading the frame')

closeAll()

def drawMyLine(frame):

global point1</

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值