-
Notifications
You must be signed in to change notification settings - Fork 0
/
measure_points_gui.py
67 lines (47 loc) · 1.56 KB
/
measure_points_gui.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import cv2
from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np
import pprint
import toml
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("image_path_str", type=str, help="URL of image to be processed")
args = parser.parse_args()
local_file_path = args.image_path_str
pp = pprint.PrettyPrinter(indent=4)
# Open the TOML file
with open("config.toml", "r") as f:
# Load the contents of the file into a dictionary
config = toml.load(f)
image_path = Path(local_file_path)
assert image_path.exists()
points = []
img = cv2.imread(image_path.as_posix(), cv2.IMREAD_UNCHANGED)
location, street, time = image_path.stem.split("_")
print(f"{location=}, {street=}")
# Step 3: Create a mouse callback function
def mouse_callback(event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDOWN:
print("X: ", x, "Y: ", y)
points.append([x, y])
cv2.circle(img, (x, y), 5, (0, 0, 255), -1)
cv2.imshow("image", img)
# Step 4: Create a window to display the image
cv2.namedWindow("image")
# Step 5: Set the mouse callback function to the window
cv2.setMouseCallback("image", mouse_callback)
# Step 6: Display the image in the window
cv2.imshow("image", img)
# Step 7: Wait for a key event
while True:
if cv2.waitKey(0) & 0xFF == ord("q"):
break
print("points = ", end="")
pp.pprint(points)
config[location][street]["points"] = points
with open("config.toml", "w") as f:
# Write the dictionary to the file as TOML
toml.dump(config, f)
# Step 8: Close all windows
cv2.destroyAllWindows()