我不知道如何画圆,当“+”或“-”在推的时候,半径会减小/增大。
我必须:
如果我按鼠标左键-我必须画一个圆/完成
如果我按下右键-我必须改变圆圈的颜色/完成
如果我按“+”---我必须将圆半径增加i = 10
如果我按“-”---我必须将圆半径减小i = 10
现在,我有这个代码。
import cv2
import numpy as np
import random
k = cv2.waitKey(10) & 0xff
def draw_circle(event, x, y, flags, param):
k1 = cv2.waitKey(10) & 0xff
# global radius # just trying idk
if event == cv2.EVENT_LBUTTONDOWN:
cv2.circle(img = image, center = (x,y), radius = 50 ,
color = (255,0,0), thickness = 2)
print('x = {}, y = {}'.format(x,y))
elif event == cv2.EVENT_RBUTTONDOWN:
c1 = random.randint(0, 255)
c2 = random.randint(0, 255)
c3 = random.randint(0, 255)
cv2.circle(img = image, center = (x,y), radius = 100,
color = (c1, c2, c3), thickness = 2)
image = np.zeros((600,600,3), dtype = np.uint8)
cv2.namedWindow(winname = 'testwindow')
cv2.setMouseCallback('testwindow',draw_circle)
while True:
cv2.imshow('testwindow',image)
if k == 32:
print('Something')
k = cv2.waitKey(1)
if k == 27:
break
cv2.destroyAllWindows()
我必须做一个程序,它增加或减少按钮的半径。我看到了这个,但它不可能为我把它转换成我的程序(mouse events on opencv)
1条答案
按热度按时间ni65a41a1#
试试这个: