Commit fdf8ee46 authored by Dorota Czaplejewicz's avatar Dorota Czaplejewicz
Browse files

big camera: Add interactive test of optics

parent 9bebffde
Pipeline #79369 passed with stages
in 3 minutes and 28 seconds
......@@ -52,6 +52,8 @@ Depends:
python3-pytest,
python3-evdev,
python3-nmea2,
python3-numpy,
python3-opencv,
python3-pyudev,
python3-yaml,
usb-modeswitch,
......
"""
Interactively tests camera optics under controlled brightness.
Does not test focus.
"""
import cv2
import numpy as np
import shlex
import subprocess
from tempfile import NamedTemporaryFile
import time
def call(cmd):
return subprocess.check_call(shlex.split(cmd))
def yad(argstr):
return call('yad ' + argstr)
def use_big_camera():
# set up media pipeline
call('''media-ctl -d "platform:30b80000.csi" --entity "csi" --set-v4l2 "'csi':0 [fmt:SGRBG8/1052x780 colorspace:raw]"''')
call('''media-ctl -d "platform:30b80000.csi" --entity "csi" --set-v4l2 "'imx8mq-mipi-csi2 30b60000.csi':0 [fmt:SGRBG8/1052x780 colorspace:raw]"''')
call('''media-ctl -d "platform:30b80000.csi" --entity "csi" --set-v4l2 "'s5k3l6xx 3-002d':0 [fmt:SGRBG8/1052x780 colorspace:raw]"''')
call('''media-ctl -d "platform:30b80000.csi" -l "'s5k3l6xx 3-002d':0 -> 'imx8mq-mipi-csi2 30b60000.csi':0 [1]"''')
# no test pttern
call('''v4l2-ctl --media-bus-info platform:30b80000.csi --device 's5k3l6xx 3-002d' --set-ctrl=test_pattern=0''')
# Gain should match test conditions (test rig?)
call('''v4l2-ctl --media-bus-info platform:30b80000.csi --device 's5k3l6xx 3-002d' --set-ctrl=analogue_gain=512 --set-ctrl=exposure=3000''')
# return raw picture
with NamedTemporaryFile(mode='rb') as tempf:
call('''v4l2-ctl --device="/dev/v4l/by-path/platform-30b80000.csi-video-index0" --set-fmt-video=width=1052,height=780,pixelformat=GRBG --stream-mmap --stream-skip=3 --stream-count=1 --stream-to={}'''.format(tempf.name))
return ((1052, 780), tempf.read())
if __name__ == '__main__':
yad("--form --text 'Please point the big camera towards a white surface and press OK'")
time.sleep(3) # give the user some time to place the phone in a rig or whatever
(width, height), raw_bytes = use_big_camera()
raw_picture = np.frombuffer(
raw_bytes, np.dtype('u1'), width * height
).reshape((height, width))
demosaic = cv2.cvtColor(raw_picture, cv2.COLOR_BAYER_GR2RGB)
yad("--form --text 'Once you click OK, a picture will appear. Please check it for optical problems like specks, and then close it.'")
with NamedTemporaryFile(suffix='.png', mode='rb') as png:
cv2.imwrite(png.name, demosaic)
subprocess.check_call(['xdg-open', png.name])
yad("--image dialog-question --title 'Camera evaluation' --button=No:1 --button=Yes:0 --text 'Is the picture free from optical problems like specks?'")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment