Home > Blockchain >  Drawing circle with event buttons in python with cv2
Drawing circle with event buttons in python with cv2

Time:01-24

I dont know how to make circle, which decreasing/increasing radius when ' ' or '-' is pushing.

I have to:

  • if i push left mouse click - i have to draw a circle / done
  • if i push right click - i have to change color of circle / done
  • if i push ' ' --- i have to increase my circle radius by i = 10
  • if i push '-' --- i have to decrease my circle radius by i = 10

Now, i have this code.

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() 

I have to make a program, which increases or decreasing radius on button. I saw this, but its not possible for me to transform it into my program (enter image description here

  • Related