summaryrefslogtreecommitdiff
path: root/explore.cc
blob: 5784f910863e25e9a1b719d1b81e794a9002151e (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
79
80
81
82
83
84
#include <vector>
#include <cstdio>

#include "cv.h"
#include "highgui.h"

#include "explore.h"
#include "stitch.h"
#include "compute.h"

using namespace std;
using namespace cv;

typedef struct {
  vector<Mat> & frames;
  VPath path;
  Mat mosaic;
  int fwidth, fheight, width;
  int selected;
} PathData;

Mat overlay_line(Mat & orig, int x, int r, int g, int b)
{
  Point pt1 (x, 0), pt2 (x, orig.size().height);
  Mat ret = orig.clone();
  cv::line(ret, pt1, pt2, CV_RGB(r, g, b));
  return ret;
}

void mouse_cb(int event, int x, int y, int flags, void* param)
{
  PathData *pd = (PathData*) param;
  int greenline = -1;
  Mat todraw = pd->mosaic;
  if (event == CV_EVENT_MOUSEMOVE)
  {
    greenline = x;
  }
  if (event == CV_EVENT_LBUTTONDOWN)
  {
    pd->selected = x;

    FrameStrip fs = pd->path[x];
    float cost = -1.;
    if (x > 0)
    {
      FrameStrip fs2 = pd->path[x-1];
      cost = edgecost(pd->frames[fs2.first], fs2.second,
                      pd->frames[fs.first], fs.second);
    }
    fprintf(stderr, "Strip %d taken from frame %d, column %d, cost %f\n",
                    x, fs.first, fs.second, cost);
    imshow("Frame view", overlay_line(pd->frames[fs.first],
                                      fs.second,
                                      255, 0, 0));
  }
  if (greenline != -1)
  {
    todraw = overlay_line (todraw, greenline, 0, 255, 0);
  }
  if (pd->selected != -1)
  {
    todraw = overlay_line (todraw, pd->selected, 255, 0, 0);
  }
  if (greenline != 1 || pd->selected != -1)
  {
    imshow("Explore", todraw);
  }
}

void explore_path(vector<Mat> & frames, Path p)
{
  Mat mosaic = stitch_path(frames, p);
  PathData pd = {frames, path_to_vpath(p), mosaic,
                 frames[0].size().width,
                 frames[0].size().height,
                 p.size(),
                 -1};
  namedWindow("Explore", CV_WINDOW_AUTOSIZE);
  imshow("Explore", mosaic);
  cvSetMouseCallback("Explore", mouse_cb, &pd);
  cvWaitKey (0);
  cvDestroyWindow ("Explore");
}