summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2011-01-19 05:08:21 +0100
committerGuillaume Seguin <guillaume@segu.in>2011-01-19 05:08:21 +0100
commitf320ecb1c74e75e9a7f41859161a82cb1b81fe21 (patch)
tree93a681770ff73def4f301739e8aa05d5bc4c08a3
parent7097bf100af83e7aa518b727a1d1514f9e510dd0 (diff)
downloadspacetimemanifolds-f320ecb1c74e75e9a7f41859161a82cb1b81fe21.tar.gz
spacetimemanifolds-f320ecb1c74e75e9a7f41859161a82cb1b81fe21.tar.bz2
Expose edgecost func, cleanup
-rw-r--r--compute.cc57
-rw-r--r--compute.h2
2 files changed, 15 insertions, 44 deletions
diff --git a/compute.cc b/compute.cc
index 732e71b..671756b 100644
--- a/compute.cc
+++ b/compute.cc
@@ -1,47 +1,17 @@
#include <queue>
#include <cstdio>
#include <limits>
-
#include <xmmintrin.h>
+#include "cv.h"
+#include "highgui.h"
#include "compute.h"
+#include "path.h"
#include "pyramid.h"
-#include "tictoc.h"
+#include "tictoc.h"
#include "stitch.h"
-#include "path.h"
-#include "highgui.h"
-
-/*
-double edgecost(Mat & f, int i, Mat & g, int j)
-{
- Mat from_1 = f.colRange(i + 1, i + X_CMP_WIDTH + 1);
- Mat from_2 = f.colRange(i - X_CMP_WIDTH, i);
- Mat to_1 = g.colRange(j + 1, j + X_CMP_WIDTH + 1);
- Mat to_2 = g.colRange(j - X_CMP_WIDTH, j);
- Mat delta_1, delta_2;
- cv::pow(from_1 - to_1, CMP_NORM, delta_1);
- cv::pow(from_2 - to_2, CMP_NORM, delta_2);
- int frame_height = f.size().height;
- int blocks_count = frame_height / Y_CMP_WINDOW;
- int block_offset = (frame_height - blocks_count * Y_CMP_WINDOW) / 2;
- double weight1 = 0, weight2 = 0;
- for (int block = 0; block < blocks_count; ++block)
- {
- int start = block * Y_CMP_WINDOW + block_offset;
- Mat block1 = delta_1.rowRange(start, start + Y_CMP_WINDOW);
- Scalar channelssum = cv::sum(block1);
-#define csum(a) (a[0] + a[1] + a[2])
- weight1 = max(weight1, csum(channelssum));
- Mat block2 = delta_2.rowRange(start, start + Y_CMP_WINDOW);
- channelssum = cv::sum(block2);
- weight2 = max(weight2, csum(channelssum));
-#undef csum
- }
- double weight = min(weight1, weight2);
- return weight / (X_CMP_WIDTH * Y_CMP_WINDOW * f.channels());
-}
-*/
+#include "explore.h"
inline
float blockpow_and_sum(Mat & f, Mat & g,
@@ -65,7 +35,7 @@ float blockpow_and_sum(Mat & f, Mat & g,
return r[0] + r[1] + r[2] + r[3];
}
-double edgecost_parallel(Mat & f, int i, Mat & g, int j)
+double edgecost(Mat & f, int i, Mat & g, int j)
{
int frame_height = f.size().height;
int blocks_count = frame_height / Y_CMP_WINDOW;
@@ -82,8 +52,8 @@ double edgecost_parallel(Mat & f, int i, Mat & g, int j)
{
#endif
double weight = 0;
- int fx = (tid == 0) ? i + 1 : i - X_CMP_WIDTH;
- int gx = (tid == 0) ? j + 1 : j - X_CMP_WIDTH;
+ int fx = (tid == 0) ? i + 1 : i - X_CMP_WIDTH + 1;
+ int gx = (tid == 0) ? j : j - X_CMP_WIDTH;
for (int block = 0; block < blocks_count; ++block)
{
int y = block * Y_CMP_WINDOW + block_offset;
@@ -184,10 +154,8 @@ Path constrained_dijkstra(vector<Mat> & frames, vector<vector<bool> > mask,
if (strip + delta_strip < X_CMP_WIDTH
|| strip + delta_strip >= cur_width - X_CMP_WIDTH)
continue;
- cost = edgecost_parallel(frames[frame],
- strip,
- frames[frame + delta_frame],
- strip + delta_strip);
+ cost = edgecost(frames[frame], strip,
+ frames[frame + delta_frame], strip + delta_strip);
}
else if (delta_frame == 0 && delta_strip == 1)
{
@@ -245,6 +213,8 @@ Path constrained_dijkstra(vector<Mat> & frames, vector<vector<bool> > mask,
int frame = v / cur_width;
int strip = (v - frame * cur_width);
path.push_front(FrameStrip(frame, strip));
+ fprintf(stdout, "Edge to (%d, %d) cost %.3le\n", frame, strip,
+ prev_cost - dists[v]);
prev_cost = dists[v];
v = prev[v];
}
@@ -335,12 +305,11 @@ Mat compute_mosaic(vector<Mat> & frames,
path,
direction,
&length);
+ explore_path(downscaled[i], path);
Mat mosaic = stitch_path(downscaled[i], path);
- imshow("temp", mosaic);
char buf[200];
sprintf(buf, "temp-%d.png", i);
imwrite(buf, mosaic * 255);
- waitKey(0);
paths[i] = path;
mosaics[i] = mosaic;
fprintf(stdout, "Length at scale level %d = %.3le\n", i, length);
diff --git a/compute.h b/compute.h
index a8f9d15..7828eb4 100644
--- a/compute.h
+++ b/compute.h
@@ -20,4 +20,6 @@ Mat compute_mosaic(vector<Mat> & frames,
vector<Path> & paths
);
+double edgecost(Mat & f, int i, Mat & g, int j);
+
#endif /* COMPUTE_H */