看文档时有这个练习题,搞了半天没搞好,结果发现是自己太粗心了,写下来记录一下
import numpy as np
import cv2 as cv
# 创建一个黑色的图像,一个窗口
img = np.zeros((700,800,3), np.uint8)
cv.namedWindow('image')
def nothing(x):
pass
#画圆
def draw_circle(event,x,y,flags,param):
if event == cv.EVENT_LBUTTONDBLCLK:
cv.circle(img,(x,y),radius,(255,0,0),-1)
cv.setMouseCallback('image', draw_circle)
# 创建颜色变化的轨迹栏
cv.createTrackbar('R','image',0,255,nothing)
cv.createTrackbar('G','image',0,255,nothing)
cv.createTrackbar('B','image',0,255,nothing)
cv.createTrackbar('radius','image',1,100,nothing)
# 为 ON/OFF 功能创建开关
switch = '0 : OFF \n1 : ON'
cv.createTrackbar(switch, 'image',0,1,nothing)
while(1):
cv.imshow('image',img)
k = cv.waitKey(1) & 0xFF
if k == 27:
break
# 得到四条轨迹的当前位置
r = cv.getTrackbarPos('R','image