python opencv 鼠标提取矩形(Rectangle)ROI
方法:获取鼠标点击事件
代码
# import the necessary packages import argparse import cv2 # initialize the list of reference points and boolean indicating # whether cropping is being performed or not refPt = [] cropping = False def click_and_crop(event, x, y, flags, param):# grab references to the global variablesglobal refPt, cropping# if the left mouse button was clicked, record the starting# (x, y) coordinates and indicate that cropping is being# performedif event == cv2.EVENT_LBUTTONDOWN:refPt = [(x, y)]cropping = True# check to see if the left mouse button was releasedelif event == cv2.EVENT_LBUTTONUP:# record the ending (x, y) coordinates and indicate that# the cropping operation is finishedrefPt.append((x, y))cropping = False# draw a rectangle around the region of interestcv2.rectangle(image, refPt[0], refPt[1], (0, 255, 0), 2)cv2.imshow("image", image)# construct the argument parser and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", required=True, help="Path to the image") args = vars(ap.parse_args()) # load the image, clone it, and setup the mouse callback function image = cv2.imread(args["image"]) clone = image.copy() cv2.namedWindow("image") cv2.setMouseCallback("image", click_and_crop) # keep looping until the 'q' key is pressed while True:# display the image and wait for a keypresscv2.imshow("image", image)key = cv2.waitKey(1) & 0xFF# if the 'r' key is pressed, reset the cropping regionif key == ord("r"):image = clone.copy()# if the 'c' key is pressed, break from the loopelif key == ord("c"):break # if there are two reference points, then crop the region of interest # from teh image and display it if len(refPt) == 2:roi = clone[refPt[0][1]:refPt[1][1], refPt[0][0]:refPt[1][0]]cv2.imshow("ROI", roi)cv2.waitKey(0) # close all open windows cv2.destroyAllWindows()
结果
参考资料
https://github.com/xuyangcao/random_walker_gui
Capturing mouse click events with Python and OpenCV
python opencv 鼠标提取矩形(Rectangle)ROI相关推荐
- 【图像处理】——Python+opencv实现提取图像的几何特征(面积、周长、细长度、区间占空比、重心、不变矩等)
转载请注明详细地址 本文简单介绍了图像常见几何特征的概念以及求解方法 本文介绍了Python和opencv求解几何特征的常用方法 目录 其他形状外接轮廓的方法可以参考:<OpenCV-Pytho ...
- python opencv轮廓提取_Python + Opencv2 实现轮廓提取,轮廓区域面积计算
对图像处理时,会遇到这样一个场景:找到图像主体轮廓,这是其一,可能为了凸显轮廓,需要用指定的颜色进行标记:轮廓标记完可能任务还没有结束,还需对轮廓所勾勒的像素面积区域统计计算. 本篇文章的主要内容就是 ...
- python opencv最小外接矩形_Opencv绘制最小外接矩形、最小外接圆
Opencv中求点集的最小外结矩使用方法minAreaRect,求点集的最小外接圆使用方法minEnclosingCircle. minAreaRect方法原型: RotatedRect minAre ...
- python opencv最小外接矩形中心点_Opencv绘制最小外接矩形、最小外接圆
Opencv中求点集的最小外结矩使用方法minAreaRect,求点集的最小外接圆使用方法minEnclosingCircle. minAreaRect方法原型: RotatedRect minAre ...
- python opencv —— 背景提取(MOG、KNN)、识别与检测(Haar Cascade)
注意 opencv 的坐标轴,x 轴向右,和 width 对应,y 轴向下,和 height 对应: 1. MOG2 与 KNN MOG:Mixture of Gaussian import cv2c ...
- Python Opencv cv2提取图像中某种特定颜色区域(例如黑字白纸背景下的红色公章提取),并将纯色背景透明化
拜拜PHOTOSHOP- 领导突然让我帮他把公章从图片中抠出来,在确保了不是要做坏事的情况下,我打开了PHOTOSHOP,用魔棒工具一点一点抠,但由于魔棒工具的原理是对比临近区域像素差值,导致封闭字体 ...
- python opencv天空提取_python利用opencv实现印章的提取
抽空写了下,怕找不到了,做个备份,直接上代码,嗯,自己能看懂就喜欢这种感觉: #coding:utf-8 import cv2 import numpy as np #加载图片 image = cv2 ...
- python opencv旋转_Python opencv实现与rotatedrect类似的矩形旋转,pythonopencv,RotatedRect
本文原理:先旋转矩形到指定角度,然后提取矩形外轮廓,从而获取旋转后的矩形坐标点. #!/usr/bin/env python3 # -*- coding: utf-8 -*- # @Author: t ...
- python图片保存为txt文件_python + opencv实现提取png图像的像素信息并存储到txt文件中(附安装指导)...
相关库安装指导: 这里我们需要 opencv_python,numpy,matplotlib库,另外我用的是python3.6.1版本. 一般库大家都是用pip install命令安装的,不过不知道为 ...
- Python,OpenCV鼠标事件进行矩形、圆形的绘制(随机颜色、随机半径)
Python,OpenCV鼠标事件进行矩形.圆形的绘制(随机颜色.随机半径) 1. 效果图 2. 源码 参考 这篇博客将介绍鼠标事件,并介绍鼠标事件矩形.圆形的绘制: 所有的鼠标事件(左键按下.左键释 ...
最新文章
- 直接用SM30的维护表创建事务代码
- 加密解密php,2个比较经典的PHP加密解密函数分享
- oracle 10g体系结构及安全管理
- saltstack(三) --- salt-httpapi
- 000 SpringMVC介绍
- Spring-tx-TransactionInfo
- (七)对Jmeter进行参数化的俩种方式
- 如果你的苹果Mac键盘锁住了要怎么办呢?快来看看此教程吧!
- dcm4chee汉化_docker dcm4chee
- Eclipse运行慢
- 安卓-利用android studio制作简单的QQ登陆login界面
- Unity中表格制作与动态生成
- xxl-job 原理:
- 苹果怎么换字体_苹果手机电池不行了怎么办,换什么牌子好?
- Photoshop CS4在Windows11上会导致鼠标右键卡死的问题处理
- Processing 入门教程(三十) lerpColor颜色渐变
- [转]JavaScript和html5 canvas生成圆形印章
- 实训周实验(eNSP安装+简单使用+实验项目)总结
- 支付宝快捷登录相关事宜
- python marshal loads failed_Python模块学习:marshal 对象的序列化
热门文章
- C#面试题(String和StringBuilder区别)
- python 文件的打开与读取
- Android-怎么配置ADT配置了没有安卓图标怎么办
- hdu 6108 小C的倍数问题
- [转]asp 无法连接 access,出现 -2147467259 未指定的错误
- C# - ZIP 压缩流
- kafka和mqtt的区别和联系
- Arrays.asList( ) 返回一个特殊的“ArrayList”
- Linux下vi命令小结
- tpl_main_page.php