summaryrefslogtreecommitdiffhomepage
path: root/tracker-pt/pt-api.cpp
blob: 298f405a58c837473846ace03e79dc3d6747f347 (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
#include "pt-api.hpp"
#include "cv/numeric.hpp"

using namespace types;

pt_camera_info::pt_camera_info()
{
}

double pt_camera_info::get_focal_length(f fov, int res_x, int res_y)
{
    const double diag_len = std::sqrt(double(res_x*res_x + res_y*res_y));
    const double aspect_x = res_x / diag_len;
    //const double aspect_y = res_y / diag_len;
    const double diag_fov = fov * M_PI/180;
    const double fov_x = 2*std::atan(std::tan(diag_fov*.5) * aspect_x);
    //const double fov_y = 2*atan(tan(diag_fov*.5) * aspect_y);
    const double fx = .5 / std::tan(fov_x * .5);
    return fx;
    //fy = .5 / tan(fov_y * .5);
    //static bool once = false; if (!once) { once = true; qDebug() << "f" << ret << "fov" << (fov * 180/M_PI); }
}

pt_camera::pt_camera()
{
}

pt_camera::~pt_camera()
{
}

pt_runtime_traits::pt_runtime_traits()
{
}

pt_runtime_traits::~pt_runtime_traits()
{
}

pt_point_extractor::pt_point_extractor()
{
}

pt_point_extractor::~pt_point_extractor()
{
}

double pt_point_extractor::threshold_radius_value(int w, int h, int threshold)
{
    double cx = w / 640., cy = h / 480.;

    const double min_radius = 1.75 * cx;
    const double max_radius = 15 * cy;

    const double radius = std::fmax(0., (max_radius-min_radius) * threshold / f(255) + min_radius);

    return radius;
}


std::tuple<double, double> pt_pixel_pos_mixin::to_pixel_pos(double x, double y, int w, int h)
{
    return std::make_tuple(w*(x+.5), .5*(h - 2*y*w));
}

std::tuple<double, double> pt_pixel_pos_mixin::to_screen_pos(double px, double py, int w, int h)
{
    px *= w/(w-1.), py *= h/(h-1.);
    return std::make_tuple((px - w/2.)/w, -(py - h/2.)/w);
}

pt_frame::pt_frame()
{
}

pt_frame::~pt_frame()
{
}