summaryrefslogtreecommitdiff
path: root/src/ipa/raspberrypi/controller/rpi/focus.cpp
blob: 1e2b649149acf59200c3d34ae9b3a958126ac8f4 (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
/* SPDX-License-Identifier: BSD-2-Clause */
/*
 * Copyright (C) 2020, Raspberry Pi (Trading) Limited
 *
 * focus.cpp - focus algorithm
 */
#include <stdint.h>

#include "../focus_status.h"
#include "../logging.hpp"
#include "focus.hpp"

using namespace RPi;

#define NAME "rpi.focus"

Focus::Focus(Controller *controller)
	: Algorithm(controller)
{
}

char const *Focus::Name() const
{
	return NAME;
}

void Focus::Read(boost::property_tree::ptree const &params)
{
	print_ = params.get<int>("print", 0);
}

void Focus::Process(StatisticsPtr &stats, Metadata *image_metadata)
{
	FocusStatus status;
	unsigned int i;
	for (i = 0; i < FOCUS_REGIONS; i++)
		status.focus_measures[i] = stats->focus_stats[i].contrast_val[1][1] / 1000;
	status.num = i;
	image_metadata->Set("focus.status", status);
	if (print_) {
		uint32_t value = (status.focus_measures[5] + status.focus_measures[6]) / 10;
		RPI_LOG("Focus contrast measure: " << value);
	}
}

/* Register algorithm with the system. */
static Algorithm *Create(Controller *controller)
{
	return new Focus(controller);
}
static RegisterAlgorithm reg(NAME, &Create);