python手记(39)

#!/usr/bin/env python
#-*- coding: utf-8 -*-
#code:myhaspl@qq.com
import cv2
import numpy as np fn="test1.jpg"
print 'http://blog.csdn.net/myhaspl'
print 'myhaspl@qq.com'
print
print 'loading %s ...' % fn
print 'working',
img = cv2.imread(fn)
w=img.shape[1]
h=img.shape[0]
sz1=w
sz0=h
EVENTS = ['CV_EVENT_MOUSEMOVE', 'CV_EVENT_LBUTTONDOWN', 'CV_EVENT_RBUTTONDOWN', 'CV_EVENT_MBUTTONDOWN', 'CV_EVENT_LBUTTONUP',
'CV_EVENT_RBUTTONUP', 'CV_EVENT_MBUTTONUP' , 'CV_EVENT_LBUTTONDBLCLK','CV_EVENT_RBUTTONDBLCLK','CV_EVENT_MBUTTONDBLCLK'] def callback_function(event,x,y,flag,param):
global EVENTS
global img if EVENTS[event]=='CV_EVENT_LBUTTONDOWN':
print "(%d,%d):"%(y,x)
print img[y,x,:]
cv2.imshow('img', img) return
def getdistance(color1,color2):
return np.sqrt(sum((color1-color2)*(color1-color2))) cv2.namedWindow('img')
cv2.setMouseCallback('img', callback_function)
cv2.imshow('img', img)
cv2.waitKey()
cv2.destroyAllWindows()

python opencv 鼠标事件

python手记(39)

上一篇:BZOJ4946[Noi2017]蔬菜——线段树+堆+模拟费用流


下一篇:BZOJ1042 [HAOI2008]硬币购物 【完全背包 + 容斥】