Here is the full code. so what this code does is it will open an imagewindow and when we left click anywhere in the image it will show the point where we leftclicked and its coordinate. I hope this helps
import cv2
import numpy as np
counter = 0
points = []
def MouseCallback(event, x, y, flags, userdata):
global counter
if(event == cv2.EVENT_LBUTTONDOWN):
if(counter < 4):
cv2.circle(dst, (x,y), 3, (0,255,255), 4, cv2.LINE_AA)
cv2.putText(dst, "x: {x},y:{y}".format(x=x,y=y), (x-250,y), cv2.FONT_HERSHEY_SIMPLEX, 1,(0,100,255),2,cv2.LINE_AA)
cv2.imshow("Destination Image", dst)
points.append((x,y))
counter += 1
#print(x,y)
#print(points)
if(len(points) == 4):
#roi = dst[:,541:1018]
#cv2.imshow("winname", roi)
#print(points)
array_points = np.array(points)
#new_points = order_points(array_points)
print(array_points)
cv2.imwrite("saved.jpg", dst)
#top_left_x = min(points, key=itemgetter(1))[0]
#top_left_y = min(points, key=itemgetter(0))[0]
#bot_right_x = max(points, key=itemgetter(1))[0]
#bot_right_y = max(points, key=itemgetter(0))[0]
#height = top_left_y - bot_right_y
#width = top_left_x - bot_right_x
#print(y1,x1,y2,x2)
#roi = dst[top_left_y:bot_right_y+1,top_left_x:bot_right_x+1]
#cv2.imshow("roi", roi)
dst = cv2.imread("times_square.jpg")
mask = np.zeros((dst.shape[:2]),dtype='uint8')
cv2.imshow("mask", mask)
cv2.imshow("Destination Image", dst)
print(cv2.EVENT_RBUTTONDOWN,"hello")
cv2.setMouseCallback("Destination Image", MouseCallback)
key = cv2.waitKey(0)
if( key == ord('q') ):
cv2.destroyAllWindows()