import cv2 as cv def findcoord(event, x, y, flags, params): if event ==…
- User
import cv2 as cv def find_coord(event, x, y, flags, params): if event == cv.EVENT_LBUTTONDOWN: # Correct the mouse event # Left mouse click print(x, ',', y) # how to define or print on the same image or windows font = cv.FONT_HERSHEY_PLAIN cv.putText(img, str(x) + ',' + str(y), (x, y), font, 1, (255, 0, 0), 2) # show the text on the image itself cv.imshow("image", img) if name == "main": # read and display the image img = cv.imread("/Users/abhi/2 Areas/JOB/Teisnach Thesis/Important images/New Images/Medium_Grinded_KT copy.jpg.jpeg") if img is None: print("Error: Image not found.") else: # display the image cv.imshow("image", img) # setting call back function cv.setMouseCallback("image", find_coord) cv.waitKey(0) cv.destroyAllWindows(): this is the code for finding the exact coordinates of the pixels in an image. and this is the code for euclidean distance measurements between 2 points: from scipy.spatial import distance distance.euclidean([1, 0, 0], [0, 1, 0]), where the give values are example. Now, I want to use the output of the first code, as an input for the euclidean distance measurements. when i click on the image using the 1st code, it gives me x and y coordinates and i want to use those coordinates to calculate the euclidean distance. give me a python code for that.
- Assistant
To achieve this, you can store the coordinates of the points you click on in a list and then calculate the Euclidean distance between them. Below is a modified version of your code that integrates both functionalities: