summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2011-01-19 05:08:03 +0100
committerGuillaume Seguin <guillaume@segu.in>2011-01-19 05:08:03 +0100
commit7097bf100af83e7aa518b727a1d1514f9e510dd0 (patch)
treeb610e20deae52bba72f6106e7438b7b8f4cb25f6
parent0d84107241e956668b847f9e45acd8cba3bc8853 (diff)
downloadspacetimemanifolds-7097bf100af83e7aa518b727a1d1514f9e510dd0.tar.gz
spacetimemanifolds-7097bf100af83e7aa518b727a1d1514f9e510dd0.tar.bz2
Add path explorator and required utils
-rw-r--r--explore.cc84
-rw-r--r--explore.h12
-rw-r--r--path.cc7
-rw-r--r--path.h5
4 files changed, 108 insertions, 0 deletions
diff --git a/explore.cc b/explore.cc
index e69de29..5784f91 100644
--- a/explore.cc
+++ b/explore.cc
@@ -0,0 +1,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");
+}
diff --git a/explore.h b/explore.h
index 3a4220b..463464a 100644
--- a/explore.h
+++ b/explore.h
@@ -1,3 +1,15 @@
#ifndef EXPLORE_H
#define EXPLORE_H
+
+#include <vector>
+#include "cv.h"
+
+#include "path.h"
+#include "stitch.h"
+
+using namespace std;
+using namespace cv;
+
+void explore_path(vector<Mat> & frames, Path p);
+
#endif /* EXPLORE_H */
diff --git a/path.cc b/path.cc
index e8902d7..a1b79c0 100644
--- a/path.cc
+++ b/path.cc
@@ -12,3 +12,10 @@ void print_path(Path path)
i++;
}
}
+
+VPath path_to_vpath(Path path)
+{
+ VPath vpath (path.size());
+ copy (path.begin(), path.end(), vpath.begin());
+ return vpath;
+}
diff --git a/path.h b/path.h
index f9f697e..ca54be0 100644
--- a/path.h
+++ b/path.h
@@ -3,10 +3,15 @@
#include <algorithm>
#include <list>
+#include <vector>
using namespace std;
typedef pair<int,int> FrameStrip;
typedef list<FrameStrip> Path;
+typedef vector<FrameStrip> VPath;
+
+void print_path(Path path);
+VPath path_to_vpath(Path path);
#endif /* PATH_H */