Files
sunnypilot/system/camerad/test/test_exposure.py
ZwX1616 028527423c camerad: rework ox exposure score (#26948)
* wip

* make separate score func

* n4ot g

* clean up

* remove

* simplify

* b2b

* balance costs

* clean up

* no if tici

* box view

* new baselines

* Revert "new baselines"

This reverts commit f7a5d059eda70fa4d49e3024923da30e8821f42b.

* Revert "box view"

This reverts commit a57924be36e7d6abc2585aca9575c74cd583ef86.

Co-authored-by: Comma Device <device@comma.ai>
2023-01-13 21:32:15 -08:00

53 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python3
import time
import unittest
import numpy as np
from selfdrive.test.helpers import with_processes
from system.camerad.snapshot.snapshot import get_snapshots
TEST_TIME = 45
REPEAT = 5
class TestCamerad(unittest.TestCase):
@classmethod
def setUpClass(cls):
pass
def _numpy_rgb2gray(self, im):
ret = np.clip(im[:,:,2] * 0.114 + im[:,:,1] * 0.587 + im[:,:,0] * 0.299, 0, 255).astype(np.uint8)
return ret
def _is_exposure_okay(self, i, med_mean=np.array([[0.2,0.4],[0.2,0.6]])):
h, w = i.shape[:2]
i = i[h//10:9*h//10,w//10:9*w//10]
med_ex, mean_ex = med_mean
i = self._numpy_rgb2gray(i)
i_median = np.median(i) / 255.
i_mean = np.mean(i) / 255.
print([i_median, i_mean])
return med_ex[0] < i_median < med_ex[1] and mean_ex[0] < i_mean < mean_ex[1]
@with_processes(['camerad'])
def test_camera_operation(self):
passed = 0
start = time.time()
while time.time() - start < TEST_TIME and passed < REPEAT:
rpic, dpic = get_snapshots(frame="roadCameraState", front_frame="driverCameraState")
wpic, _ = get_snapshots(frame="wideRoadCameraState")
res = self._is_exposure_okay(rpic)
res = res and self._is_exposure_okay(dpic)
res = res and self._is_exposure_okay(wpic)
if passed > 0 and not res:
passed = -passed # fails test if any failure after first sus
break
passed += int(res)
time.sleep(2)
self.assertGreaterEqual(passed, REPEAT)
if __name__ == "__main__":
unittest.main()