Skip to content

Commit

Permalink
Just realised we can get rid of the resolution!
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMariday committed Mar 11, 2024
1 parent d79a270 commit 7762f89
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

*.csv
.idea/
4 changes: 3 additions & 1 deletion lib/led_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def find_led(self, image):
center_x = moments["m10"] / moments["m00"]
center_y = moments["m01"] / moments["m00"]

return LedResults((center_x, center_y), contours)
max_dimension = max(image.shape)

return LedResults((center_x/max_dimension, center_y/max_dimension), contours)

@staticmethod
def draw_results(image, results):
Expand Down
8 changes: 4 additions & 4 deletions lib/sfm/database_populator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def populate(db_path, input_directory, led_count=23, min_avg_points_per_view=100
for line in lines:
led_id, u, v = line.split(",")

key_points[int(led_id)][0] = float(u)
key_points[int(led_id)][1] = float(v)
key_points[int(led_id)][0] = float(u)*2000
key_points[int(led_id)][1] = float(v)*2000

total_keypoints += 1

Expand All @@ -47,8 +47,8 @@ def populate(db_path, input_directory, led_count=23, min_avg_points_per_view=100
# model=0 means that it's a "SIMPLE PINHOLE" with just 1 focal length parameter that I think should get optimised
# the params here should be f, cx, cy

width = int(str(input_files[0]).split("_")[-2])
height = int(str(input_files[0]).split("_")[-1].replace(".csv", ""))
width = 2000
height = 2000
fov = 60 # degrees, this gets optimised so doesn't //really// matter that much

SIMPLE_PINHOLE = 0
Expand Down
Binary file modified requirements.txt
Binary file not shown.
2 changes: 1 addition & 1 deletion scripts/capture_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
# The filename is made out of the date, then the resolution of the camera
string_time = time.strftime("%Y%m%d-%H%M%S")
filename = (
f"capture_{string_time}_{l3d.cam.get_width()}_{l3d.cam.get_height()}.csv"
f"capture_{string_time}.csv"
)

filepath = os.path.join(output_dir_full, filename)
Expand Down
17 changes: 7 additions & 10 deletions scripts/visualise.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,23 @@

args = parser.parse_args()

file_resolution = [
int(r) for r in args.filename.replace(".csv", "").split("_")[-2:]
]

display = np.zeros((file_resolution[1], file_resolution[0], 3))
display = np.zeros((640, 640, 3))

with open(args.filename, "r") as file:
lines = file.readlines()
file_points = [
[int(float(v)) for v in line.strip().split(",")] for line in lines
]
file_points = []
for line in lines:
led_id, u, v = line.strip().split(",")
file_points.append([led_id, float(u), float(v)])

if len(file_points[0]) == 3:

for point_id, point_u, point_v in file_points:
image_point = (int(point_u), int(point_v))
image_point = (int(point_u*640), int(point_v*640))
cv2.drawMarker(display, image_point, color=(0, 255, 0))
cv2.putText(
display,
f"{point_id}",
point_id,
image_point,
cv2.FONT_HERSHEY_SIMPLEX,
1,
Expand Down
6 changes: 3 additions & 3 deletions test/test_capture_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_capture_sequence():

# The filename is made out of the date, then the resolution of the camera
filename = (
f"capture_cam_{device_id}_{l3d.cam.get_width()}_{l3d.cam.get_height()}.csv"
f"capture_cam_{device_id}.csv"
)

filepath = os.path.join(output_dir_full, filename)
Expand All @@ -49,9 +49,9 @@ def test_capture_sequence_correctness():

mock_camera = MockCamera()

for device_id in range(5):
for device_id in range(9):
output_dir_full = os.path.join(os.getcwd(), "my_scans", "test")
filename = f"capture_cam_{device_id}_{mock_camera.get_width()}_{mock_camera.get_height()}.csv"
filename = f"capture_cam_{device_id}.csv"
filepath = os.path.join(output_dir_full, filename)

with open(filepath, "r") as csv_file:
Expand Down
4 changes: 2 additions & 2 deletions test/test_led_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def test_basic_image_loading():

led_results = led_finder.find_led(mock_camera.read())

assert close(led_results.u(), 257)
assert close(led_results.v(), 177)
assert close(led_results.u(), 257/640.0)
assert close(led_results.v(), 177/480.0)


def test_none_found():
Expand Down

0 comments on commit 7762f89

Please sign in to comment.