import cv2
import numpy as np
cv2.namedWindow('bgr', cv2.WINDOW_NORMAL)
img = np.zeros((800,800,3),np.uint8)
text1='line:l'
text2='rectangle:r'
text3='circle:c'
text4='out:q'
cv2.putText(img,text1,(10,20),cv2.FONT_HERSHEY_COMPLEX,0.5,[200,200,200])
cv2.putText(img,text2,(10,40),cv2.FONT_HERSHEY_COMPLEX,0.5,[200,200,200])
cv2.putText(img,text3,(10,60),cv2.FONT_HERSHEY_COMPLEX,0.5,[200,200,200])
cv2.putText(img,text4,(10,80),cv2.FONT_HERSHEY_COMPLEX,0.5,[200,200,200])
cv2.imshow('bgr',img)
def line(event, x, y, flags, userdata):
if event == cv2.EVENT_LBUTTONDOWN:
dot.append((x,y))
if event == cv2.EVENT_LBUTTONUP:
dot.append((x,y))
cv2.line(img,(dot[0]),(dot[1]),(220,200,255),1,64)
cv2.imshow('bgr',img)
def rec(event, x, y, flags, userdata):
if event == cv2.EVENT_LBUTTONDOWN:
dot.append((x,y))
opencv 鼠标画直线圆矩形
最新推荐文章于 2024-04-25 13:47:30 发布
这篇博客介绍了如何利用OpenCV库在Python中实现鼠标交互,允许用户通过点击和拖动来绘制直线、圆和矩形。通过讲解关键代码和步骤,读者可以学习到计算机视觉领域的图像处理技巧。
摘要由CSDN通过智能技术生成