1 | #include <iostream> |
---|
2 | #include <fstream> |
---|
3 | #include <time.h> // For speed checks |
---|
4 | #include <float.h> |
---|
5 | #include <vector> |
---|
6 | #include <iomanip> // For machine precision |
---|
7 | |
---|
8 | #include "main.h" |
---|
9 | #include "PNM.h" |
---|
10 | #include "Rectify/General2Im.h" |
---|
11 | |
---|
12 | // Keep the fortran 2 C libraries happy. (Give the fortran main function). |
---|
13 | extern "C" { |
---|
14 | void MAIN__() {} |
---|
15 | } |
---|
16 | |
---|
17 | /*********************/ |
---|
18 | /* The main function */ |
---|
19 | /*********************/ |
---|
20 | int main(int argc, char **argv) |
---|
21 | { |
---|
22 | // Default exit status to ok. |
---|
23 | int ExitStatus=0; |
---|
24 | |
---|
25 | if (argc!=7) { |
---|
26 | std::cerr << "syntax: " << argv[0] << " image1 image2 fmatrix matches outimage1 outimage2" << std::endl; |
---|
27 | std::cerr << std::endl << "where:" << std::endl; |
---|
28 | std::cerr << " image1, image2 Are the two images to be rectified" << std::endl; |
---|
29 | std::cerr << " fmatrix is the fundamental matrix" << std::endl; |
---|
30 | std::cerr << " outimage1, outimage2 are filenames for rectified images" << std::endl; |
---|
31 | exit(1); |
---|
32 | } |
---|
33 | |
---|
34 | // Load images |
---|
35 | Image::Image<unsigned int> image1, image2, rectim1, rectim2; |
---|
36 | |
---|
37 | PNMLoadSave::LoadImage(argv[1], image1); |
---|
38 | PNMLoadSave::LoadImage(argv[2], image2); |
---|
39 | |
---|
40 | // Load the fundamental matrix |
---|
41 | MultiViewGeom::FMatrix<double> FM; |
---|
42 | std::ifstream FMfile(argv[3], std::ios::in | std::ios::binary); |
---|
43 | if (!FMfile) { |
---|
44 | std::cerr << "couldn't open fundamental matrix file " << argv[3] << std::endl; |
---|
45 | exit(1); |
---|
46 | } |
---|
47 | FMfile >> std::setprecision(DBL_DIG); |
---|
48 | for (int row=0;row<3;++row) { |
---|
49 | for (int col=0;col<3;++col) { |
---|
50 | FMfile >> FM(row,col); |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | std::vector<std::pair<Geometry::Point2D<double>, Geometry::Point2D<double> > > Matches; |
---|
55 | std::ifstream Matchesfile(argv[4], std::ios::in | std::ios::binary); |
---|
56 | if (!Matchesfile) { |
---|
57 | std::cerr << "couldn't open file containing matches " << argv[4] << std::endl; |
---|
58 | exit(1); |
---|
59 | } |
---|
60 | Matchesfile >> std::setprecision(DBL_DIG); |
---|
61 | while (!Matchesfile.eof()) { |
---|
62 | double x,y,x2,y2; |
---|
63 | Matchesfile >> x >> y >> x2 >> y2; |
---|
64 | if (!Matchesfile.eof()) |
---|
65 | Matches.push_back(std::make_pair(Geometry::Point2D<double>(x,y), Geometry::Point2D<double>(x2,y2))); |
---|
66 | } |
---|
67 | |
---|
68 | Rectify::GeneralPlanarRectify rectify(image1.xsize(), image1.ysize(), image2.xsize(), image2.ysize(), FM, Matches); |
---|
69 | rectify.resampleIms(image1, image2, rectim1, rectim2, 0xFF000000); |
---|
70 | |
---|
71 | PNMLoadSave::SaveImage(argv[5], rectim1); |
---|
72 | PNMLoadSave::SaveImage(argv[6], rectim2); |
---|
73 | |
---|
74 | return ExitStatus; |
---|
75 | } |
---|