using namespace std;
using namespace cv;
vector Generate3DPoints();
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
const string fileName = "cam.xml";
FileStorage fs(fileName, FileStorage::READ);
if (!fs.isOpened())
cout << "can't open txt document" << endl;
FileNode n = fs.getFirstTopLevelNode();
if (n.type() != FileNode::SEQ)
cout << "node false" << endl;
FileNodeIterator it = n.begin(), it_end = n.end();
for (; it != it_end; ++it)
{
string fname = (string)*it;
string fpath = samples::findFile(fileName.substr(0, 1 + 1) + fname, false);
if (fpath.empty())
fpath = samples::findFile(fname);
fname = fpath;
}
#if 0
// Read 3D points
vector objectPoints = Generate3DPoints();
vector imagePoints;
// Intrisic matrix
Mat intrisicMat = (Mat_(3, 3) <<
1.6415318549788924e+003, 0, 0,
0, 1.7067753507885654e+003, 0,
5.3262822453148601e+002, 3.8095355839052968e+002, 1);
// Rotation vector
Mat rVec = (Mat_(3, 1) <<
-3.9277902400761393e-002,
3.7803824407602084e-002,
2.6445674487856268e-002
);
// Translation vector
cv::Mat tVec = (Mat_(3, 1) <<
2.1158489381208221e+000,
-7.6847683212704716e+000,
2.6169795190294256e+001);
// Distortion vector
cv::Mat distCoeffs = (Mat_(5,1) <<
-7.9134632415085826e-001,
1.5623584435644169e+000,
-3.3916502741726508e-002,
-1.3921577146136694e-002,
1.1430734623697941e-002);
std::vector projectedPoints;
cv::projectPoints(objectPoints, rVec, tVec, intrisicMat, distCoeffs, projectedPoints);
for (unsigned int i = 0; i < projectedPoints.size(); ++i)
{
cout << "Image point: " << objectPoints[i] << " Projected to " << projectedPoints[i] << endl;
}
cout << "Press any key to exit.";
cin.ignore();
cin.get();
#endif
return a.exec();
}
vector Generate3DPoints()
{
vector points;
float x, y, z;
x = .5; y = .5; z = -.5;
points.push_back(cv::Point3f(x, y, z));
x = .5; y = .5; z = .5;
points.push_back(cv::Point3f(x, y, z));
x = -.5; y = .5; z = .5;
points.push_back(cv::Point3f(x, y, z));
x = -.5; y = .5; z = -.5;
points.push_back(cv::Point3f(x, y, z));
x = .5; y = -.5; z = -.5;
points.push_back(cv::Point3f(x, y, z));
x = -.5; y = -.5; z = -.5;
points.push_back(cv::Point3f(x, y, z));
x = -.5; y = -.5; z = .5;
points.push_back(cv::Point3f(x, y, z));
//for (unsigned int i = 0; i < points.size(); ++i)
//{
// cout << points[i] << endl << endl;
//}
return points;
}