Commit 099ec620 authored by Tadej Borovšak's avatar Tadej Borovšak

Start tracking wrapper

parent a14a735d
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <math.h>
//#define SHOW_STEPS 1
//
using namespace std;
using namespace cv;
//
//
//static RNG rng (time (NULL));
//
//#define SMOOTH 1
//#define MIN_SIGMA 1
//#define SHOOW_STEPS 1
//
//
//static void
//cross_entropy (Mat const &res,
// int no_samples,
// int no_elites,
// Scalar &mean,
// Scalar &sigma)
//{
//#if SHOW_STEPS
// double m;
// minMaxLoc (res, NULL, &m);
// Mat out;
// res.convertTo (out, CV_8U, 255 / m);
// cvtColor (out, out, COLOR_GRAY2BGR);
//#endif /* SHOW_STEPS */
//
// Mat rnd = Mat::zeros (1, no_samples, CV_16SC2);
// Mat vals = Mat::zeros (1, no_samples, CV_32F);
// Vec2s *ptr_p = rnd.ptr<Vec2s> ();
// float *ptr_v = vals.ptr<float> ();
// Mat order;
// Vec2i accum (0, 0);
//
// float old_val, new_val;
//
// new_val = res.at<float> (mean[0], mean[1]);
//
// do
// {
// old_val = new_val;
// ellipse (out, Point (mean[0], mean[1]), Point (sigma[0], sigma[1]),
// 0, 0, 360, Scalar (0, 0, 255));
//
// rng.fill (rnd, RNG::NORMAL, mean, sigma);
// for (int i = 0; i < no_samples; i++)
// ptr_v[i] = res.at<float> (ptr_p[i][0], ptr_p[i][1]);
// sortIdx (vals, order, CV_SORT_EVERY_ROW | CV_SORT_DESCENDING);
//
// int *ptr_o = order.ptr<int> ();
// accum = Vec2i (0, 0);
// for (int i = 0; i < no_elites; i++)
// accum += rnd.at<Vec2s> (0, ptr_o[i]);
//#if SMOOTH
// mean = (Scalar (accum[0] / no_elites, accum[1] / no_elites) + mean) / 2;
//#else
// mean = Scalar (accum[0] / no_elites, accum[1] / no_elites);
//#endif /* SMOOTH */
//
// new_val = res.at<float> (mean[0], mean[1]);
// float diff = fabs (new_val - old_val) / fabs (new_val + old_val);
// cout << diff << endl;
// if (diff < 0.02)
// break;
//
// accum = Vec2i (0, 0);
// for (int i = 0; i < no_elites; i++)
// {
// Vec2i val = rnd.at<Vec2s> (0, ptr_o[i]) - Vec2s (mean[0], mean[1]);
// accum += val.mul(val);
// }
// sigma = Scalar (sqrt (accum[0] / (float)no_elites),
// sqrt (accum[1] / (float)no_elites));
//#if MIN_SIGMA
// sigma = Scalar (max (sigma[0], 3.0), max (sigma[1], 2.0));
//#endif /* MIN_SIGMA */
// }
// while (true);
//
//#ifdef SHOW_STEPS
// char fname[200];
// snprintf (fname, 200, "img-%08d.png", time (NULL) % (long)1e8);
// imwrite (fname, out);
// resize (out, out, Size (), 5, 5, INTER_CUBIC);
// imshow ("test", out);
// waitKey (0);
//#endif /* SHOW_STEPS */
//}
//
///* Tracker callbacks */
//typedef void (*InitFunc) (Mat const &img,
// Rect const &region,
// Point &location,
// void **data);
//typedef void (*UpdateFunc) (Mat const &img,
// void const *data,
// Point &location);
//
//typedef enum
//{
// INTERACTIVE = 1 << 0,
// INITIALIZE = 1 << 1,
// TRAJECTORY = 1 << 2,
// PAUSE = 1 << 3
//}
//Flags;
//
//static void
//track (InitFunc init,
// UpdateFunc update,
// vector<char const *> &images,
// Rect const &region,
// Flags flags)
//{
// Mat img = imread (images[0]);
//
// if (region.area == 0 && flags & INTERACTIVE)
// {
//
//}
#define WIN "test"
typedef struct
{
Point ul, br;
Mat img;
}
Data;
static void
update_display (Data *data)
{
Mat tmp = data->img.clone ();
if (data->ul != data->br)
rectangle (tmp, data->ul, data->br, Scalar (0, 0, 255));
imshow (WIN, tmp);
}
static void
mouse_cb (int e,
int x,
int y,
int f,
void *d)
{
Data *data = (Data *)d;
switch (e)
{
case EVENT_LBUTTONDOWN:
data->ul.x = x;
data->ul.y = y;
data->br.x = x;
data->br.y = y;
break;
case EVENT_MOUSEMOVE:
data->br.x = x;
data->br.y = y;
break;
case EVENT_LBUTTONUP:
update_display (data);
break;
default:
break;
}
if (f & EVENT_FLAG_LBUTTON)
update_display (data);
}
int
main (int argc,
char **argv)
{
Data data = {
Point (0, 0),
Point (0, 0),
imread ("david/00000001.jpg")
};
namedWindow (WIN);
setMouseCallback (WIN, mouse_cb, (void *)&data);
update_display (&data);
int key = waitKey ();
while (key != 1048586)
key = waitKey ();
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment