-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e6e72f
commit dbf0e29
Showing
8 changed files
with
154 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import tempfile | ||
from marimapper.led_map_2d import LEDMap2D, get_all_2d_led_maps | ||
|
||
|
||
def test_partially_valid_data(): | ||
temp_led_map_file = tempfile.NamedTemporaryFile(delete=False, suffix=".csv") | ||
temp_led_map_file.write( | ||
b"""index,u,v | ||
0,0.379490,0.407710 | ||
2,0,0 | ||
2.2,0,0 | ||
bananas,apples,grapes | ||
""" | ||
) | ||
temp_led_map_file.close() | ||
|
||
led_map = LEDMap2D(filepath=temp_led_map_file.name) | ||
|
||
assert led_map.valid | ||
|
||
assert len(led_map) == 2 | ||
|
||
assert led_map.get_detection(0).pos() == (0.379490, 0.407710) | ||
|
||
assert led_map.get_detection(2).pos() == (0, 0) | ||
|
||
|
||
def test_invalid_path(): | ||
|
||
led_map = LEDMap2D(filepath="doesnt-exist-i-hope") | ||
assert not led_map.valid | ||
|
||
|
||
def test_get_all_maps(): | ||
|
||
directory = tempfile.TemporaryDirectory() | ||
|
||
temp_led_map_file = tempfile.NamedTemporaryFile( | ||
delete=False, suffix=".csv", dir=directory.name | ||
) | ||
temp_led_map_file.write( | ||
b"""index,u,v | ||
0,0.379490,0.407710 | ||
""" | ||
) | ||
temp_led_map_file.close() | ||
|
||
temp_led_map_file_invalid = tempfile.NamedTemporaryFile( | ||
delete=False, suffix=".html", dir=directory.name | ||
) | ||
temp_led_map_file_invalid.write( | ||
b"""index,u,v | ||
0,0.379490,0.407710 | ||
""" | ||
) | ||
temp_led_map_file_invalid.close() | ||
|
||
all_maps = get_all_2d_led_maps(directory=directory.name) | ||
|
||
assert len(all_maps) == 1 | ||
|
||
directory.cleanup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import tempfile | ||
from marimapper.led_map_3d import LEDMap3D | ||
|
||
|
||
def test_file_write(): | ||
|
||
led_id = 0 | ||
led_x = 0 | ||
led_y = 0 | ||
led_z = 0 | ||
led_x_normal = 1 | ||
led_y_normal = 1 | ||
led_z_normal = 1 | ||
led_error = 1 | ||
|
||
led_dict = { | ||
"pos": (led_x, led_y, led_z), | ||
"normal": (led_x_normal, led_y_normal, led_z_normal), | ||
"error": led_error, | ||
} | ||
|
||
led_map = LEDMap3D({led_id: led_dict}) | ||
|
||
assert led_map.keys() == [led_id] | ||
|
||
output_file = tempfile.NamedTemporaryFile(delete=False) | ||
|
||
led_map.write_to_file(output_file.name) | ||
|
||
with open(output_file.name) as f: | ||
lines = f.readlines() | ||
|
||
headings = ["index", "x", "y", "z", "xn", "yn", "zn", "error"] | ||
|
||
assert lines[0].strip().split(",") == headings | ||
data_line = lines[1].strip().split(",") | ||
assert int(data_line[headings.index("index")]) == led_id | ||
assert float(data_line[headings.index("x")]) == led_x | ||
assert float(data_line[headings.index("y")]) == led_y | ||
assert float(data_line[headings.index("z")]) == led_z | ||
assert float(data_line[headings.index("xn")]) == led_x_normal | ||
assert float(data_line[headings.index("yn")]) == led_y_normal | ||
assert float(data_line[headings.index("zn")]) == led_z_normal | ||
assert float(data_line[headings.index("error")]) == led_error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,34 @@ | ||
from marimapper.led_identifier import LedFinder | ||
from marimapper.led_identifier import find_led_in_image, draw_led_detections | ||
from marimapper.camera import Camera | ||
|
||
|
||
def close(x, y): | ||
return abs(x - y) < 0.000001 | ||
|
||
|
||
def test_init(): | ||
LedFinder() | ||
|
||
|
||
def test_basic_image_loading(): | ||
led_finder = LedFinder() | ||
|
||
mock_camera = Camera("test/MariMapper-Test-Data/9_point_box/cam_0/capture_0000.png") | ||
|
||
detection = led_finder.find_led(mock_camera.read()) | ||
detection = find_led_in_image(mock_camera.read(color=False)) | ||
assert close(detection.u, 0.4029418361244019) | ||
assert close(detection.v, 0.4029538809144072) | ||
|
||
|
||
def test_none_found(): | ||
led_finder = LedFinder() | ||
|
||
mock_camera = Camera("test/MariMapper-Test-Data/9_point_box/cam_0/capture_%04d.png") | ||
|
||
for frame_id in range(24): | ||
frame = mock_camera.read() | ||
frame = mock_camera.read(color=False) | ||
if frame_id in [7, 15, 23]: | ||
led_results = led_finder.find_led(frame) | ||
led_results = find_led_in_image(frame) | ||
assert led_results is None | ||
|
||
|
||
def test_draw_results(): | ||
|
||
led_finder = LedFinder() | ||
mock_camera = Camera("test/MariMapper-Test-Data/9_point_box/cam_0/capture_%04d.png") | ||
frame = mock_camera.read() | ||
led_results = led_finder.find_led(frame) | ||
led_finder.draw_results(frame, led_results) | ||
led_results = find_led_in_image(frame) | ||
draw_led_detections(frame, led_results) |