blob: 98446649b1162f06e48f8eea266bc9bbd62d7950 (
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
|
#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
}
|