Skip to content

Commit c8882c7

Browse files
committed
tests: Add bypass for lores size when testing imx296
The lores size 640x640 ended up larger than the cropped hires size, so the test would throw an exception. Fix this. Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
1 parent f5174e5 commit c8882c7

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

utils/test.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,25 @@ def detect_num_cameras(exe_dir):
7272
return 0
7373

7474

75+
def get_max_camera_size(exe_dir):
76+
"""Largest reported camera resolution as (W, H), or None if not detectable."""
77+
import re
78+
79+
try:
80+
executable = os.path.join(exe_dir, "rpicam-hello")
81+
result = subprocess.run(
82+
[executable, "--list-cameras"], capture_output=True, text=True, timeout=10
83+
)
84+
if result.returncode != 0:
85+
return None
86+
sizes = re.findall(r"^\d+ : \S+ \[(\d+)x(\d+) ", result.stdout, re.MULTILINE)
87+
if not sizes:
88+
return None
89+
return max((int(w), int(h)) for w, h in sizes)
90+
except (FileNotFoundError, subprocess.TimeoutExpired):
91+
return None
92+
93+
7594
def get_platform():
7695
platform = "vc4"
7796
try:
@@ -188,7 +207,16 @@ def test_hello(exe_dir, output_dir, preview_dir):
188207
check_time(time_taken, 1, 6, "test_hello: roi test")
189208

190209
# "crops test". Specify an image crop with lores output and see if it blows up.
210+
# Lores must be <= ROI'd viewfinder; clamp to the sensor so this also passes
211+
# on smaller sensors (e.g. imx296 at 1456x1088 -> 728x544 viewfinder).
191212
print(" crop test")
213+
size = get_max_camera_size(exe_dir)
214+
if size:
215+
w, h = size
216+
lores_w = max(64, min(640, w // 2 - 64))
217+
lores_h = max(64, min(640, h // 2 - 64))
218+
else:
219+
lores_w, lores_h = 640, 640
192220
retcode, time_taken = run_executable(
193221
args
194222
+ [
@@ -197,9 +225,9 @@ def test_hello(exe_dir, output_dir, preview_dir):
197225
"--roi",
198226
"0.25,0.25,0.5,0.5",
199227
"--lores-width",
200-
"640",
228+
str(lores_w),
201229
"--lores-height",
202-
"640",
230+
str(lores_h),
203231
],
204232
logfile,
205233
)

0 commit comments

Comments
 (0)