本文实例为大家分享了python-opencv鼠标事件画框圈定目标的具体代码,供大家参考,具体内容如下
在视频/相机中,用鼠标画矩形框,圈定目标,从而获得鼠标的起始坐标点a、终止坐标点b
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 27 09:32:02 2016
@author: http://blog.csdn.net/lql0716
"""
import cv2
import numpy as np
current_pos = None
tl = None
br = None
#鼠标事件
def get_rect(im, title='get_rect'): # (a,b) = get_rect(im, title='get_rect')
mouse_params = {'tl': None, 'br': None, 'current_pos': None,
'released_once': False}
cv2.namedWindow(title)
cv2.moveWindow(title, 100, 100)
def onMouse(event, x, y, flags, param):
param['current_pos'] = (x, y)
if param['tl'] is not None and not (flags & cv2.EVENT_FLAG_L