python_opencv用线段画封闭矩形的实例
作者:嗨小方 时间:2022-05-04 19:07:59
如下所示:
def draw_circle(event,x,y,flags,param):
global ix,iy,drawing,mode,start_x,start_y
if event == cv2.EVENT_LBUTTONDOWN:
if drawing == False:
start_x, start_y = x,y
ix,iy = x,y
drawing = True
elif drawing == True:
cv2.line(img,(ix,iy),(x,y),(0,255,0),3)
ix, iy = x, y
print(drawing)
elif event == cv2.EVENT_MBUTTONDOWN:
drawing = False
cv2.line(img, (ix, iy), (start_x, start_y), (0, 255, 0), 3)
print(drawing)
#
# elif event == cv2.EVENT_RBUTTONUP:
# cv2.line(img,(ix,iy),(x,y),(0,255,0),3)
# Next we have to bind this mouse callback function to OpenCV # # window. In the main loop, we should set a keyboard binding for
# key ‘m' to toggle between rectangle and circle.
img = np.zeros((512,512,3), np.uint8)
cv2.namedWindow('image')
cv2.setMouseCallback('image',draw_circle)
while(1):
cv2.imshow('image',img)
k = cv2.waitKey(1) & 0xFF
if k == ord('m'): # 切换模式
mode = not mode
elif k == 27:
break
cv2.destroyAllWindows()
来源:https://blog.csdn.net/qq_25254777/article/details/80238444
标签:python,opencv,矩形
0
投稿
猜你喜欢
MySql安装与卸载的详细教程
2024-01-14 09:47:53
交互设计模式(二)-Pagination(分页,标记页数)
2009-08-03 13:37:00
laravel学习教程之关联模型
2023-06-11 19:46:55
Python中json.dumps()函数的使用解析
2022-11-04 19:41:09
大家都对vertical-align的各说各话
2008-06-19 12:11:00
python画柱状图--不同颜色并显示数值的方法
2021-12-31 17:22:18
谈谈如何手动释放Python的内存
2023-09-22 13:03:57
layui 富文本图片上传接口与普通按钮 文件上传接口的例子
2024-05-22 10:36:28
详解IOS微信上Vue单页面应用JSSDK签名失败解决方案
2024-04-30 10:25:40
python根据出生日期获得年龄的方法
2022-05-22 23:52:46
python读取dicom图像示例(SimpleITK和dicom包实现)
2023-07-06 14:08:10
js动态显示当前日期,时间和星期代码
2007-08-14 12:31:00
程序员开发项目是选择效率还是质量呢?
2023-09-17 08:37:03
Vue实现父子组件页面刷新的几种常用方法
2024-06-07 16:05:52
Python中变量交换的例子
2021-04-02 13:28:36
Bootstrap进度条与AJAX后端数据传递结合使用实例详解
2024-04-28 10:18:32
webpack的 rquire.context用法实现工程自动化的方法
2024-05-11 09:05:29
Linux中将txt导入到mysql的方法教程
2024-01-12 13:04:27
OL IE Bug
2009-09-09 16:25:00
解决Pycharm调用Turtle时 窗口一闪而过的问题
2023-05-06 14:46:29