File size: 1,133 Bytes
b27cd24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import cv2
import os

#  Image path
image_path = "/Users/Jamila/Desktop/LineFinder/Images/ImagesByUs/image_001.jpg"

# Check if file exists
if not os.path.exists(image_path):
    print(f"Error: The file at path '{image_path}' does not exist.")
    exit()

# Load the image
image = cv2.imread(image_path, cv2.IMREAD_COLOR)  # Ensure it's read as a color image

# Verify if the image was loaded correctly
if image is None:
    print("Error: Could not load image. Check the file path or file format.")
    exit()
else:
    print("Image loaded successfully with shape:", image.shape)

# Function to capture mouse click events and print coordinates
def get_coordinates(event, x, y, flags, param):
    if event == cv2.EVENT_LBUTTONDOWN:  # Detect left mouse button click
        print(f"Clicked at X: {x}, Y: {y}")

# Create a window and set mouse callback function
cv2.namedWindow('image')
cv2.setMouseCallback('image', get_coordinates)

# Display the image in a loop until exiting
while True:
    cv2.imshow('image', image)
    if cv2.waitKey(20) & 0xFF == 27:  # 27 - Exit when ESC key is pressed
        break

cv2.destroyAllWindows()