I"m trying to change the color of a circle drawn on the output frame of the live camera feed whenever some key is pressed. When I press 'c' key I want the circle to change its color from blue to green. I'm trying the below approach to achieve this
# import the opencv library
import cv2
global circle_color
circle_color = (255,0,0)
# define a video capture object
vid = cv2.VideoCapture(0)
while(True):
# Capture the video frame
# by frame
ret, frame = vid.read()
cv2.circle(img=frame, center = (250,250), radius =100, color =circle_color, thickness=-1)
# Display the resulting frame
cv2.imshow('frame', frame)
# the 'q' button is set as the
# quitting button you may use any
# desired button of your choice
if cv2.waitKey(1) & 0xFF == ord('q'):
break
elif cv2.waitKey(1) & 0xFF == ord('c'):
# circle_color == (0,255,0)
cv2.circle(img=frame, center = (250,250), radius =100, color =(0,255,0), thickness=-1)
print("pressed c")
# After the loop release the cap object
vid.release()
# Destroy all the windows
cv2.destroyAllWindows()
When I try this code and press key 'c' I only see the console output as pressed c but I don't see any change in circle color on the output frame window it stays blue.
I even tried declaring global variable of color and updating it when the key is pressed this didn't work as well
Any help or suggestion to achieve this will be highly appreciated thanks.