2 #include <opencv2/core/core.hpp> 7 inline double SQ(
double x)
12 int main(
int argc,
char **argv)
17 double model_data[20] = {0.0685, 0.6383, 0.4558, 0.7411, -0.7219, 0.7081, 0.7061, 0.2887, -0.9521, -0.2553,
18 0.4636, 0.0159, -0.1010, 0.2817, 0.6638, 0.1582, 0.3925, -0.7954, 0.6965, -0.7795};
21 double iprts_data[20] = {-0.0168, 0.0377, 0.0277, 0.0373, -0.0824, 0.0386, 0.0317, 0.0360, -0.1015, -0.0080,
22 0.0866, 0.1179, 0.1233, 0.1035, 0.0667, 0.1102, 0.0969, 0.1660, 0.0622, 0.1608};
40 Mat model = Mat::zeros(3, 10, CV_64F);
41 Mat iprts = Mat::ones(3, 10, CV_64F);
48 for(
int i=0; i < 10; i++) {
49 model.at<
double>(0,i) = model_data[i];
50 model.at<
double>(1,i) = model_data[i+10];
52 iprts.at<
double>(0,i) = iprts_data[i];
53 iprts.at<
double>(1,i) = iprts_data[i+10];
56 if(!
RPP::Rpp(model, iprts, rotation, translation, iterations, obj_err, img_err)) {
57 fprintf(stderr,
"Error with RPP\n");
61 printf(
"Input normalised image points (using 3x3 camera intrinsic matrix):\n");
62 for(
int i=0; i < 10; i++) {
63 printf(
"%d: (%g, %g)\n", i, iprts_data[i*2], iprts_data[i*2+1]);
67 printf(
"Input model points (fixed 3D points chosen by the user, z is fixed to 0.0):\n");
68 for(
int i=0; i < 10; i++) {
69 printf(
"%d: (%g, %g, 0.0)\n", i, model_data[i*2], model_data[i*2+1]);
73 printf(
"Pose found by RPP\n");
76 printf(
"Rotation matrix\n");
79 printf(
"Translation matrix\n");
82 printf(
"Number of iterations: %d\n", iterations);
83 printf(
"Object error: %f\n", obj_err);
84 printf(
"Image error: %f\n", img_err);
88 double tran_err = 0.0;
91 rot_err +=
SQ(rotation.at<
double>(0,0) - 0.85763);
92 rot_err +=
SQ(rotation.at<
double>(0,1) - -0.31179);
93 rot_err +=
SQ(rotation.at<
double>(0,2) - 0.40898);
94 rot_err +=
SQ(rotation.at<
double>(1,0) - 0.16047);
95 rot_err +=
SQ(rotation.at<
double>(1,1) - -0.59331);
96 rot_err +=
SQ(rotation.at<
double>(1,2) - -0.78882);
97 rot_err +=
SQ(rotation.at<
double>(2,0) - 0.48859);
98 rot_err +=
SQ(rotation.at<
double>(2,1) - 0.74214);
99 rot_err +=
SQ(rotation.at<
double>(2,2) - -0.45881);
101 tran_err +=
SQ(translation.at<
double>(0) - -0.10825);
102 tran_err +=
SQ(translation.at<
double>(1) - 1.26601);
103 tran_err +=
SQ(translation.at<
double>(2) - 11.19855);
108 printf(
"Rotation results look correct! Square error = %g\n", rot_err);
111 printf(
"Rotation results does not look correct :( Square error = %g\n", rot_err);
114 if(tran_err < 1e-4) {
115 printf(
"Translation results look correct! Square error = %g\n", tran_err);
118 printf(
"Translation results does not look correct :( Square error = %g\n", tran_err);
int main(int argc, char **argv)
bool Rpp(const cv::Mat &model_3D, const cv::Mat &iprts, cv::Mat &Rlu, cv::Mat &tlu, int &it1, double &obj_err1, double &img_err1, std::vector< Solution > &sol)
void Print(const cv::Mat &m)