00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <iostream>
00041 #include <cvd/image_io.h>
00042 #include <cvd/image_interpolate.h>
00043 #include <gvars3/instances.h>
00044 #include <tag/printf.h>
00045 #include <tag/stdpp.h>
00046
00047 #include "load_data.h"
00048 #include "utility.h"
00049
00050 using namespace std;
00051 using namespace CVD;
00052 using namespace tag;
00053 using namespace GVars3;
00054 using namespace TooN;
00055
00056
00057
00058
00059
00060 Image<byte> warp_image(const Image<byte>& in, const Image<array<float, 2> >& warp)
00061 {
00062 Image<byte> ret(in.size(), 0);
00063
00064 image_interpolate<Interpolate::Bilinear, byte> interp(in);
00065
00066 for(int y=0; y < ret.size().y; y++)
00067 for(int x=0; x < ret.size().x; x++)
00068 {
00069 if(warp[y][x][0] != -1 && interp.in_image(Vec(warp[y][x])))
00070 ret[y][x] = interp[Vec(warp[y][x])];
00071 }
00072
00073 return ret;
00074 }
00075
00076
00077
00078
00079 int main(int argc, char** argv)
00080 {
00081 try
00082 {
00083
00084 GUI.parseArguments(argc, argv);
00085
00086 vector<Image<byte> > images;
00087 vector<vector<Image<array<float, 2> > > > warps;
00088
00089
00090 int n = GV3::get<int>("num", 2, 1);
00091 string dir = GV3::get<string>("dir", "./", 1);
00092 string format = GV3::get<string>("type", "cambridge", 1);
00093
00094
00095 rpair(images, warps) = load_data(dir, n, format);
00096
00097
00098 string out = GV3::get<string>("out", "./out/", 1) + "/" + GV3::get<string>("stub", "warped_%i_%i.jpg", 1);
00099
00100
00101
00102 for(int to = 0; to < n; to++)
00103 for(int from=0; from < n; from ++)
00104 if(from != to)
00105 {
00106 Image<byte> w = warp_image(images[from], warps[to][from]);
00107 img_save(w, sPrintf(out, to, from));
00108
00109 cout << "Done " << from << " -> " << to << endl;
00110 }
00111 else
00112 {
00113 img_save(images[from], sPrintf(out, to, from));
00114 }
00115 }
00116 catch(Exceptions::All e)
00117 {
00118 cerr << "Error: " << e.what << endl;
00119 }
00120 }