CVPR:A Two-point Method for PTZ Camera Calibration in Sports的C++程序分析(7)
这篇论文的代码分析快到尾声了,那就把剩下的一点看完,
Eigen::Vector3d opt_ptz;
double reprojection_error = cvx_pgl::optimizePTZ(pp, inlier_pan_tilt, inlier_image_pts, hypotheses[i].ptz_, opt_ptz);
hypotheses[i].ptz_ = opt_ptz;
hypotheses[i].inlier_indices_.clear();
hypotheses[i].inlier_candidate_pan_tilt_indices_.clear();
if (hypotheses.size() == 1 && verbose) {
printf("hypotheses rank %lu, reprojection error %f pixels\n", hypotheses.size(), reprojection_error)
}
上一次分析了optimizePTZ,看了调用Eigen进行LM非线性优化的过程,
优化结束,就把得到的结果赋给hypotheses[i]。值得注意的是,第一次执行这个循环的时候有32个假设集,所以第一次一共循环32次。经过层层筛选,第五次执行这个循环的时候就只有1个假设集了,优化完毕后,就彻底结束了preemptiveRANSACOneToMany(终于分析完了)
再次回到main函数,
printf("Prediction and camera pose estimation cost time: %f seconds.\n", (clock() - tt)/CLOCKS_PER_SEC);
if (is_opt) {
cout<<"ptz estimation error: "<<(ptz_gt - estimated_ptz).transpose()<<endl;
}
else {
printf("-------------------------------------------- Optimize PTZ failed.\n");
printf("valid feature number is %lu\n\n", image_points.size());
}
gt_ptz_all.row(index) = ptz_gt;
estimated_ptz_all.row(index) = estimated_ptz;
index++;
显示该算法处理这一帧特征点花的时间,PTZ的估计误差,以及这一帧图片的有效特征点数目
gt_ptz_all和estimated_ptz_all把每次估计的值和真值收集起来
注意,我们用来做测试的图片有很多张,比如10帧图片,每处理完一帧,index就会自动加一,加到十结束。
最后,会打印所有图片的计算结果,
std::vector<std::string> var_name;
std::vector<Eigen::MatrixXd> data;
var_name.push_back("ground_truth_ptz");
var_name.push_back("estimated_ptz");
data.push_back(gt_ptz_all);
data.push_back(estimated_ptz_all);
matio::writeMultipleMatrix(save_file, var_name, data);
// simple statistics
// void meanMedianError(const vector<T> & errors, T & mean, T & median);
vector<Eigen::VectorXd> errors;
for (int r = 0; r<gt_ptz_all.rows(); r++) {
Eigen::VectorXd err = estimated_ptz_all.row(r) - gt_ptz_all.row(r);
errors.push_back(err);
}
Eigen::VectorXd mean_error, median_error;
dt::meanMedianError(errors, mean_error, median_error);
cout<<"PTZ mean error: "<<mean_error.transpose()<<endl;
cout<<"PTZ median error: "<<median_error.transpose()<<endl;
matio可有可无,opencv自带数据写入写出的类FileStorage
最后,感谢自己的坚持,哈哈!