Skip to content

Commit

Permalink
Replaced previous testing approach to a higher dater, more reliable c…
Browse files Browse the repository at this point in the history
…amera capture stream.
  • Loading branch information
TheMariday committed Feb 18, 2024
1 parent 93bc146 commit 3b4f208
Show file tree
Hide file tree
Showing 150 changed files with 70 additions and 15 deletions.
5 changes: 5 additions & 0 deletions lib/led_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ def draw_results(image, results):
cv2.drawMarker(render_image, [int(i) for i in results.center], (0, 255, 0), markerSize=100)

return render_image


if __name__ == "__main__":

led_finder = LedFinder()
Binary file added test/camera_layout.blend
Binary file not shown.
Binary file removed test/media/capture_sequence/a_0.png
Binary file not shown.
Binary file removed test/media/capture_sequence/a_1.png
Binary file not shown.
Binary file removed test/media/capture_sequence/a_10.png
Binary file not shown.
Binary file removed test/media/capture_sequence/a_11.png
Binary file not shown.
Binary file removed test/media/capture_sequence/a_12.png
Binary file not shown.
Binary file removed test/media/capture_sequence/a_13.png
Binary file not shown.
Binary file removed test/media/capture_sequence/a_14.png
Binary file not shown.
Binary file removed test/media/capture_sequence/a_2.png
Binary file not shown.
Binary file removed test/media/capture_sequence/a_3.png
Binary file not shown.
Binary file removed test/media/capture_sequence/a_4.png
Binary file not shown.
Binary file removed test/media/capture_sequence/a_5.png
Binary file not shown.
Binary file removed test/media/capture_sequence/a_6.png
Binary file not shown.
Binary file removed test/media/capture_sequence/a_7.png
Binary file not shown.
Binary file removed test/media/capture_sequence/a_8.png
Binary file not shown.
Binary file removed test/media/capture_sequence/a_9.png
Binary file not shown.
Binary file removed test/media/capture_sequence/a_none.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed test/media/capture_sequence/s_0.png
Diff not rendered.
Binary file removed test/media/capture_sequence/s_1.png
Diff not rendered.
Binary file removed test/media/capture_sequence/s_2.png
Diff not rendered.
Binary file removed test/media/capture_sequence/s_3.png
Diff not rendered.
Binary file removed test/media/capture_sequence/s_4.png
Diff not rendered.
Binary file removed test/media/capture_sequence/s_5.png
Diff not rendered.
Binary file removed test/media/capture_sequence/s_6.png
Diff not rendered.
Binary file removed test/media/capture_sequence/s_7.png
Diff not rendered.
Binary file removed test/media/capture_sequence/s_8.png
Diff not rendered.
Binary file removed test/media/capture_sequence/s_none.png
Diff not rendered.
54 changes: 54 additions & 0 deletions test/mock_camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import cv2


class MockCamera:

def __init__(self, device_id=0):

self.current_frame = 0
self.device_id = device_id

def get_width(self):
return 640

def get_height(self):
return 480

def get_af_mode(self):
return 0

def get_focus(self):
return 0

def get_exposure_mode(self):
return 0

def get_exposure(self):
return 0

def get_gain(self):
return 0

def set_resolution(self, width, height):
pass

def set_autofocus(self, mode, focus=0):
pass

def set_exposure_mode(self, mode):
pass

def set_gain(self, gain):
pass

def set_exposure(self, exposure):
pass

def read(self):
frame = self.read_frame(self.current_frame)
self.current_frame += 1
return frame

def read_frame(self, frame_id):
filename = f"test/media/capture_sequence/cam_{self.device_id}/capture_{frame_id:04}.png"
return cv2.cvtColor(cv2.imread(filename), cv2.COLOR_BGR2GRAY)
26 changes: 11 additions & 15 deletions test/test_led_identifier.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import sys
import cv2
sys.path.append('./')
from lib.led_identifier import LedFinder
from mock_camera import MockCamera


def close(x, y):
return abs(x - y) < 0.5


def load_image(filename):
image = cv2.imread(filename)
return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
return abs(x - y) < 1.0


def test_init():
Expand All @@ -20,20 +15,21 @@ def test_init():
def test_basic_image_loading():
led_finder = LedFinder()

image = load_image("test/media/capture_sequence/a_0.png")
mock_camera = MockCamera()

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

assert close(led_results.u(), 193)
assert close(led_results.v(), 150)
assert close(led_results.u(), 257)
assert close(led_results.v(), 177)


def test_none_found():

led_finder = LedFinder()

image = load_image("test/media/capture_sequence/a_none.png")

led_results = led_finder.find_led(image)
mock_camera = MockCamera()

assert led_results is None
for frame_id in [7, 15, 23]: # None of these should be visible from any views
frame = mock_camera.read_frame(frame_id)
led_results = led_finder.find_led(frame)
assert led_results is None

0 comments on commit 3b4f208

Please sign in to comment.