Commit 773d3d7b authored by fhs41601's avatar fhs41601
Browse files

Implemented rectification

parent 4433eb3b
Branches
No related merge requests found
Showing with 85 additions and 0 deletions
#include <iostream>
#include <map>
#include <string>
#include "opencv2/core.hpp"
#include "opencv2/opencv.hpp"
#include <opencv2/core/persistence.hpp>
using namespace std;
using namespace cv;
map<string, Mat> *getProperties(const char *filename);
void dumpMap(map<string, Mat> m);
int main(const int argc, const char * const argv[]) {
map<string, Mat> *mapInt;
map<string, Mat> *mapExt;
if(argc != 5) {
cerr << "Usage: " << argv[0] << "<input image 0> <input image 1> <intrinsic data file> <extrinsic data file>" << endl;
return 1;
}
Mat lImg = imread(argv[1]);
Mat rImg = imread(argv[2]);
FileStorage fsInt(argv[3], FileStorage::FORMAT_YAML);
FileStorage fsExt(argv[4], FileStorage::FORMAT_YAML);
Mat R1, R2, P1, P2, Q;
// Get intrinsic
mapInt = getProperties(argv[3]);
dumpMap(*mapInt);
cout << "---\n";
mapExt = getProperties(argv[4]);
dumpMap(*mapExt);
stereoRectify(
(*mapInt)["M1"],
(*mapInt)["D1"],
(*mapInt)["M2"],
(*mapInt)["D2"],
lImg.size(),
(*mapExt)["R"],
(*mapExt)["T"],
R1,
R2,
P1,
P2,
Q
);
return 0;
}
map<string, Mat> *getProperties(const char *filename) {
map<string, Mat> *propMap = new map<string, Mat>();
FileStorage fs(filename, FileStorage::FORMAT_YAML);
// FileNodeIterator code adapted from
// https://stackoverflow.com/questions/16416763/how-to-retrieve-the-key-value-pairs-from-an-opencv-filenode-map/16435272
FileNode fn = fs.root();
for(FileNodeIterator fit = fn.begin(); fit != fn.end(); ++fit) {
FileNode item = *fit;
Mat tmp;
item >> tmp;
propMap->insert({item.name(), tmp});
}
return propMap;
}
void dumpMap(map<string, Mat> m) {
// Map iteration adapted from
// https://stackoverflow.com/questions/14070940/how-can-i-print-out-c-map-values/55278718
for(auto &i : m) {
cout << i.first << ":\n";
cout << i.second << "\n";
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment