Skip to content

Commit

Permalink
fixed styling
Browse files Browse the repository at this point in the history
fixed 2d viewer
  • Loading branch information
TheMariday committed Jun 13, 2024
1 parent 58ea803 commit d8a9fc5
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 63 deletions.
3 changes: 0 additions & 3 deletions backends/fadecandy/fadecandy_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ def __init__(self, uri="localhost:7890"):
self.buffer = [(0, 0, 0) for _ in range(self.get_led_count())]
self.client.put_pixels(self.buffer)

def __del__(self):
black = [(0, 0, 0) for _ in range(self.get_led_count())]

def get_led_count(self):
# return the number of LEDs in your system here
return 64
Expand Down
1 change: 0 additions & 1 deletion lib/file_monitor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import time
import hashlib
from pathlib import Path

Expand Down
5 changes: 2 additions & 3 deletions lib/led_identifier.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import cv2
from lib.utils import cprint, Col
from lib.led_map_2d import LEDDetection


Expand All @@ -21,10 +20,10 @@ def find_led(self, image):
return None
elif led_response_count > 1:
pass
#cprint(
# cprint(
# f"Warning! More than 1 light source found, found {led_response_count} light sources",
# format=Col.WARNING,
#)
# )

moments = cv2.moments(image_thresh)

Expand Down
4 changes: 2 additions & 2 deletions lib/led_map_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def keys(self):
return self.data.keys()

def _load(self, filename):
#cprint(f"Reading 3D map {filename}...")
# cprint(f"Reading 3D map {filename}...")

if not os.path.exists(filename):
cprint(
Expand Down Expand Up @@ -80,7 +80,7 @@ def _load(self, filename):
)
continue

#cprint(f"Read {len(self.data)} lines from 3D map {filename}...")
# cprint(f"Read {len(self.data)} lines from 3D map {filename}...")
return True

def write_to_file(self, filename):
Expand Down
28 changes: 3 additions & 25 deletions lib/visualize_model.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,11 @@
import colorsys
import time
import cv2
import numpy as np
import open3d
from multiprocessing import Process, Event
from lib.led_map_3d import LEDMap3D
from lib.file_monitor import FileMonitor


def render_2d_model(led_map):
display = np.ones((640, 640, 3)) * 0.2

max_id = max(led_map.keys())

for led_id in led_map:
col = colorsys.hsv_to_rgb(led_id / max_id, 0.5, 1)
image_point = (led_map[led_id]["pos"] * 640).astype(int)
cv2.drawMarker(display, image_point, color=col)
cv2.putText(
display,
str(led_id),
image_point,
cv2.FONT_HERSHEY_SIMPLEX,
1,
color=col,
)

cv2.imshow("MariMapper", display)
cv2.waitKey(0)


class Renderer3D(Process):

def __init__(self, filename):
Expand Down Expand Up @@ -100,7 +76,9 @@ def reload_geometry(self, first=False):
normals = []
for led_id in led_map.keys():
xyz.append(led_map[led_id]["pos"])
normals.append(led_map[led_id]["normal"] / np.linalg.norm(led_map[led_id]["normal"]))
normals.append(
led_map[led_id]["normal"] / np.linalg.norm(led_map[led_id]["normal"])
)

self.point_cloud.points = open3d.utility.Vector3dVector(xyz)
self.point_cloud.normals = open3d.utility.Vector3dVector(normals)
Expand Down
49 changes: 49 additions & 0 deletions scripts/view_2d_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import argparse
import sys

sys.path.append("./")

import numpy as np
import cv2
import colorsys
from lib.led_map_2d import LEDMap2D


def render_2d_model(led_map):
display = np.ones((640, 640, 3)) * 0.2

max_id = max(led_map.get_detections().keys())

for led_id in led_map.get_detections():
col = colorsys.hsv_to_rgb(led_id / max_id, 0.5, 1)
pos = np.array((led_map.get_detection(led_id).u, led_map.get_detection(led_id).v))
image_point = (pos * 640).astype(int)
cv2.drawMarker(display, image_point, color=col)
cv2.putText(
display,
str(led_id),
image_point,
cv2.FONT_HERSHEY_SIMPLEX,
1,
color=col,
)

cv2.imshow("MariMapper", display)
cv2.waitKey(0)


if __name__ == "__main__":

parser = argparse.ArgumentParser(description="Visualises 2D maps")

parser.add_argument(
"filename",
type=str,
help="The 2d_map file to visualise",
)

args = parser.parse_args()

map_data = LEDMap2D(filepath=args.filename)

render_2d_model(map_data)
28 changes: 0 additions & 28 deletions scripts/visualise.py

This file was deleted.

0 comments on commit d8a9fc5

Please sign in to comment.