Draw circle on image with mouse click

Hi, I have a code such that when I click on an image it gives me the x and y coordinates. I also want it to draw a small dot/circle at the place where I clicked.

Can someone help, please?


import cv2
import numpy as np
[print(i) for i in dir(cv2) if 'EVENT' in i]

# importing the module
import cv2

xcoor = [0]
ycoor = [0]
# function to display the coordinates of
# of the points clicked on the image
# point_matrix = np.zeros((2,2),np.int)
# counter = 0
def click_event(event, x, y, flags, params):
    # checking for left mouse clicks
    #global counter

    if event == cv2.EVENT_LBUTTONDOWN:
        # point_matrix[counter] = x, y
        # counter = counter + 1
        # for x in range(0, 2):
        #     cv2.circle(img, (point_matrix[x][0], point_matrix[x][1]), 3, (0, 255, 0), cv2.FILLED)

        # displaying the coordinates
        # on the Shell
        print(x, ' ', y)

Why did you write a for x in range (0,2) before cv2.circle?
Just write:

if event == cv2.EVENT_LBUTTONDOWN:
    cv2.circle(img, (x,y), 3, (0,255,0))
    imshow("image", img)

I imagine you have elsewhere the image display and event creation part (as it’s missing from the code).