summaryrefslogtreecommitdiff
path: root/naive_steerer.cpp
blob: f4c122f0e76e27d135aaee1f55b512a285f6c541 (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
/*
 * naive_steerer.cpp
 * 
 * Copyright 2012 Florian Jung <florian.a.jung@web.de>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 3
 * as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 */


#include "naive_steerer.h"
#include "util.h"

using namespace std;

NaiveSteerer::NaiveSteerer(int chx, int chy)
{
	set_crosshair(chx,chy);
}

void NaiveSteerer::set_crosshair(int chx, int chy)
{
	crosshair_x=chx;
	crosshair_y=chy;
}

void NaiveSteerer::process_image(const Mat& img)
{
	int left_sum=0, right_sum=0;
	for (int row = 0; row<img.rows; row++)
	{
		const uchar* data=img.ptr<uchar>(row);
		
		for (int col=0; col<img.cols;col++)
		{
			if (*data)
			{
				if (row<=crosshair_y)
				{
					if (col < crosshair_x)
						left_sum++;
					else
						right_sum++;
				}
			}
			
			data+=img.step[1];
		}
	}
	
	steer = -4* flopow(  (((float)left_sum / (left_sum+right_sum))-0.5  )*2.0 , 1.6);
}

double NaiveSteerer::get_steer_data()
{
	return steer;
}

double NaiveSteerer::get_confidence()
{
	//return confidence;
	return 1.0; // TODO
}