Source files in libcamera start by a comment block header, which includes the file name and a one-line description of the file contents. While the latter is useful to get a quick overview of the file contents at a glance, the former is mostly a source of inconvenience. The name in the comments can easily get out of sync with the file name when files are renamed, and copy & paste during development have often lead to incorrect names being used to start with. Readers of the source code are expected to know which file they're looking it. Drop the file name from the header comment block. The change was generated with the following script: ---------------------------------------- dirs="include/libcamera src test utils" declare -rA patterns=( ['c']=' \* ' ['cpp']=' \* ' ['h']=' \* ' ['py']='# ' ['sh']='# ' ) for ext in ${!patterns[@]} ; do files=$(for dir in $dirs ; do find $dir -name "*.${ext}" ; done) pattern=${patterns[${ext}]} for file in $files ; do name=$(basename ${file}) sed -i "s/^\(${pattern}\)${name} - /\1/" "$file" done done ---------------------------------------- This misses several files that are out of sync with the comment block header. Those will be addressed separately and manually. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
# SPDX-License-Identifier: BSD-2-Clause
|
|
#
|
|
# Copyright (C) 2019, Raspberry Pi Ltd
|
|
#
|
|
# camera tuning tool for lux level
|
|
|
|
from ctt_tools import *
|
|
|
|
|
|
"""
|
|
Find lux values from metadata and calculate Y
|
|
"""
|
|
def lux(Cam, Img):
|
|
shutter_speed = Img.exposure
|
|
gain = Img.againQ8_norm
|
|
aperture = 1
|
|
Cam.log += '\nShutter speed = {}'.format(shutter_speed)
|
|
Cam.log += '\nGain = {}'.format(gain)
|
|
Cam.log += '\nAperture = {}'.format(aperture)
|
|
patches = [Img.patches[i] for i in Img.order]
|
|
channels = [Img.channels[i] for i in Img.order]
|
|
return lux_calc(Cam, Img, patches, channels), shutter_speed, gain
|
|
|
|
|
|
"""
|
|
perform lux calibration on bayer channels
|
|
"""
|
|
def lux_calc(Cam, Img, patches, channels):
|
|
"""
|
|
find means color channels on grey patches
|
|
"""
|
|
ap_r = np.mean(patches[0][3::4])
|
|
ap_g = (np.mean(patches[1][3::4])+np.mean(patches[2][3::4]))/2
|
|
ap_b = np.mean(patches[3][3::4])
|
|
Cam.log += '\nAverage channel values on grey patches:'
|
|
Cam.log += '\nRed = {:.0f} Green = {:.0f} Blue = {:.0f}'.format(ap_r, ap_b, ap_g)
|
|
# print(ap_r, ap_g, ap_b)
|
|
"""
|
|
calculate channel gains
|
|
"""
|
|
gr = ap_g/ap_r
|
|
gb = ap_g/ap_b
|
|
Cam.log += '\nChannel gains: Red = {:.3f} Blue = {:.3f}'.format(gr, gb)
|
|
|
|
"""
|
|
find means color channels on image and scale by gain
|
|
note greens are averaged together (treated as one channel)
|
|
"""
|
|
a_r = np.mean(channels[0])*gr
|
|
a_g = (np.mean(channels[1])+np.mean(channels[2]))/2
|
|
a_b = np.mean(channels[3])*gb
|
|
Cam.log += '\nAverage channel values over entire image scaled by channel gains:'
|
|
Cam.log += '\nRed = {:.0f} Green = {:.0f} Blue = {:.0f}'.format(a_r, a_b, a_g)
|
|
# print(a_r, a_g, a_b)
|
|
"""
|
|
Calculate y with top row of yuv matrix
|
|
"""
|
|
y = 0.299*a_r + 0.587*a_g + 0.114*a_b
|
|
Cam.log += '\nY value calculated: {}'.format(int(y))
|
|
# print(y)
|
|
return int(y)
|