# SPDX-License-Identifier: BSD-2-Clause # # Copyright (C) 2019, Raspberry Pi (Trading) Limited # # ctt_lux.py - 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) 59595729905f7ec'>diff
path: root/src/ipa/raspberrypi/controller/controller.cpp
blob: 22461cc464aa485aca5ccaec9c97c5fcb70f29d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* SPDX-License-Identifier: BSD-2-Clause */
/*
 * Copyright (C) 2019, Raspberry Pi (Trading) Limited
 *
 * controller.cpp - ISP controller
 */

#include "algorithm.hpp"
#include "controller.hpp"

#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>

using namespace RPiController;

Controller::Controller()
	: switch_mode_called_(false) {}

Controller::Controller(char const *json_filename)
	: switch_mode_called_(false)
{
	Read(json_filename);
	Initialise();
}

Controller::~Controller() {}

void Controller::Read(char const *filename)
{
	RPI_LOG("Controller starting");
	boost::property_tree::ptree root;
	boost::property_tree::read_json(filename, root);
	for (auto const &key_and_value : root) {
		Algorithm *algo = CreateAlgorithm(key_and_value.first.c_str());
		if (algo) {
			algo->Read(key_and_value.second);
			algorithms_.push_back(AlgorithmPtr(algo));
		} else
			RPI_LOG("WARNING: No algorithm found for \""
				<< key_and_value.first << "\"");
	}
	RPI_LOG("Controller finished");
}

Algorithm *Controller::CreateAlgorithm(char const *name)
{
	auto it = GetAlgorithms().find(std::string(name));
	return it != GetAlgorithms().end() ? (*it->second)(this) : nullptr;
}

void Controller::Initialise()
{
	RPI_LOG("Controller starting");
	for (auto &algo : algorithms_)
		algo->Initialise();
	RPI_LOG("Controller finished");
}

void Controller::SwitchMode(CameraMode const &camera_mode, Metadata *metadata)
{
	RPI_LOG("Controller starting");
	for (auto &algo : algorithms_)
		algo->SwitchMode(camera_mode, metadata);
	switch_mode_called_ = true;
	RPI_LOG("Controller finished");
}

void Controller::Prepare(Metadata *image_metadata)
{
	RPI_LOG("Controller::Prepare starting");
	assert(switch_mode_called_);
	for (auto &algo : algorithms_)
		if (!algo->IsPaused())
			algo->Prepare(image_metadata);
	RPI_LOG("Controller::Prepare finished");
}

void Controller::Process(StatisticsPtr stats, Metadata *image_metadata)