Skip to content

Commit 29e3be0

Browse files
committed
fix: fmt
1 parent ac62d1f commit 29e3be0

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

src/arduino/app_peripherals/camera/base_camera.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,17 @@ def record_avi(self, duration) -> np.ndarray:
273273
try:
274274
fourcc = cv2.VideoWriter.fourcc(*"MJPG")
275275
out = cv2.VideoWriter(filename, fourcc, self.fps, (width, height))
276+
276277
frame = first_frame
277278
for i in range(total_frames):
278279
if frame is not None:
279280
if frame.dtype != np.uint8:
280281
frame = _to_uint8(frame)
281282
out.write(frame)
282-
283+
283284
if i < total_frames - 1:
284285
frame = self.capture()
285-
286+
286287
out.release()
287288
with open(filename, "rb") as f:
288289
avi_data = f.read()
@@ -410,9 +411,9 @@ def _to_uint8(frame) -> np.ndarray:
410411
if np.issubdtype(frame.dtype, np.floating):
411412
# We adopt the OpenCV convention: float images are in [0, 1]
412413
frame = np.clip(frame * 255, 0, 255)
413-
414+
414415
elif np.issubdtype(frame.dtype, np.integer) and frame.dtype != np.uint8:
415416
info = np.iinfo(frame.dtype)
416417
frame = (frame.astype(np.float32) - info.min) / (info.max - info.min) * 255
417-
418+
418419
return frame.astype(np.uint8)

tests/arduino/app_peripherals/camera/test_base_camera.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -419,30 +419,33 @@ def event_callback(event, data):
419419
assert "streaming" in events[3][0]
420420
assert "disconnected" in events[4][0]
421421

422+
422423
def test_record_zero_duration():
423424
camera = MockedCamera()
424425
camera.start()
425426
with pytest.raises(ValueError):
426427
camera.record(0)
427428
camera.stop()
428429

430+
429431
def test_record():
430432
camera = MockedCamera(fps=5)
431433
camera.frame = np.ones((480, 640, 3), dtype=np.uint8)
432434
camera.start()
433-
435+
434436
duration = 1.0
435437
expected_frames = int(camera.fps * duration)
436438
frames = camera.record(duration)
437-
439+
438440
assert isinstance(frames, np.ndarray)
439441
assert frames.shape[0] == expected_frames
440442
assert frames.shape[1:] == camera.frame.shape
441443
assert frames.dtype == camera.frame.dtype
442444
assert np.all(frames == camera.frame)
443-
445+
444446
camera.stop()
445447

448+
446449
def test_record_avi():
447450
camera = MockedCamera(fps=5)
448451
camera.frame = np.ones((480, 640, 3), dtype=np.uint8)
@@ -455,8 +458,8 @@ def test_record_avi():
455458
assert isinstance(avi_bytes, np.ndarray)
456459
assert avi_bytes.dtype == np.uint8
457460
assert avi_bytes.size > 0
458-
459-
with tempfile.NamedTemporaryFile(suffix='.avi') as tmp:
461+
462+
with tempfile.NamedTemporaryFile(suffix=".avi") as tmp:
460463
tmp.write(avi_bytes.tobytes())
461464
tmp.flush()
462465

@@ -469,13 +472,14 @@ def test_record_avi():
469472
assert frame is not None
470473
assert frame.dtype == np.uint8
471474
read_count += 1
472-
475+
473476
cap.release()
474-
477+
475478
assert read_count == expected_frames
476-
479+
477480
camera.stop()
478481

482+
479483
def test_record_avi_uint8_conversion():
480484
camera = MockedCamera(fps=5)
481485
# Use float32 frame, should be converted to uint8 in AVI
@@ -485,15 +489,15 @@ def test_record_avi_uint8_conversion():
485489
duration = 1.0
486490
expected_frames = int(camera.fps * duration)
487491
avi_bytes = camera.record_avi(duration)
488-
492+
489493
assert isinstance(avi_bytes, np.ndarray)
490494
assert avi_bytes.dtype == np.uint8
491495
assert avi_bytes.size > 0
492-
493-
with tempfile.NamedTemporaryFile(suffix='.avi') as tmp:
496+
497+
with tempfile.NamedTemporaryFile(suffix=".avi") as tmp:
494498
tmp.write(avi_bytes.tobytes())
495499
tmp.flush()
496-
500+
497501
read_count = 0
498502
cap = cv2.VideoCapture(tmp.name)
499503
while True:
@@ -503,9 +507,9 @@ def test_record_avi_uint8_conversion():
503507
assert frame is not None
504508
assert frame.dtype == np.uint8
505509
read_count += 1
506-
510+
507511
cap.release()
508512

509513
assert read_count == expected_frames
510-
514+
511515
camera.stop()

0 commit comments

Comments
 (0)