int main(int argc, char** argv) { arg_base::set_help_option("--help"); arg_parse(argc, argv); ntk::ntk_debug_level = 1; namedWindow("corners"); if (std::string(global::opt_pattern_type()) == "chessboard") global::pattern_type = PatternChessboard; else if (std::string(global::opt_pattern_type()) == "circles") global::pattern_type = PatternCircles; else if (std::string(global::opt_pattern_type()) == "asymcircles") global::pattern_type = PatternAsymCircles; else fatal_error(format("Invalid pattern type: %s\n", global::opt_pattern_type()).c_str()); global::calibration.loadFromFile(global::opt_input_file()); global::initial_focal_length = global::calibration.rgb_pose->focalX(); global::images_dir = QDir(global::opt_image_directory()); ntk_ensure(global::images_dir.exists(), (global::images_dir.absolutePath() + " is not a directory.").toLatin1()); global::images_list = global::images_dir.entryList(QStringList("view????*"), QDir::Dirs, QDir::Name); OpenniRGBDProcessor processor; processor.setFilterFlag(RGBDProcessorFlags::ComputeMapping, true); std::vector<ntk::RGBDImage> images; loadImageList(global::images_dir, global::images_list, &processor, &global::calibration, images); std::vector< std::vector<Point2f> > good_corners; std::vector< std::vector<Point2f> > all_corners; getCalibratedCheckerboardCorners(images, global::opt_pattern_width(), global::opt_pattern_height(), global::pattern_type, all_corners, good_corners, true, global::opt_infrared()); if (global::opt_infrared()) calibrateFromInfrared(images, good_corners, all_corners); else calibrateFromColor(images, good_corners, all_corners); writeNestkMatrix(); return 0; }
void calibrate_kinect_depth(std::vector< DepthCalibrationPoint >& depth_values) { std::vector< std::vector<Point3f> > pattern_points; calibrationPattern(pattern_points, global::opt_pattern_width(), global::opt_pattern_height(), global::opt_square_size(), global::images_list.size()); for (int i_image = 0; i_image < global::images_list.size(); ++i_image) { // Generate depth calibration points QString filename = global::images_list[i_image]; QDir cur_image_dir (global::images_dir.absoluteFilePath(filename)); std::string full_filename = cur_image_dir.absoluteFilePath("raw/color.png").toStdString(); RGBDImage image; OpenniRGBDProcessor processor; processor.setFilterFlag(RGBDProcessorFlags::ComputeMapping, true); image.loadFromDir(cur_image_dir.absolutePath().toStdString(), &global::calibration, &processor); imshow_normalized("mapped depth", image.mappedDepth()); imshow("color", image.rgb()); std::vector<Point2f> current_view_corners; calibrationCorners(full_filename, "corners", global::opt_pattern_width(), global::opt_pattern_height(), current_view_corners, image.rgb(), 1, global::pattern_type); if (current_view_corners.size() != (global::opt_pattern_width()*global::opt_pattern_height())) { ntk_dbg(1) << "Corners not detected in " << cur_image_dir.absolutePath().toStdString(); continue; } // FIXME: why rvecs and tvecs from calibrateCamera seems to be nonsense ? // calling findExtrinsics another time to get good chessboard estimations. cv::Mat1f H; estimate_checkerboard_pose(pattern_points[0], current_view_corners, global::calibration.rgb_intrinsics, H); Pose3D pose; pose.setCameraParametersFromOpencv(global::calibration.rgb_intrinsics); pose.setCameraTransform(H); ntk_dbg_print(pose, 1); cv::Mat3b debug_img; image.rgb().copyTo(debug_img); foreach_idx(pattern_i, pattern_points[0]) { Point3f p = pose.projectToImage(pattern_points[0][pattern_i]); ntk_dbg_print(p, 1); float kinect_raw = image.mappedDepth()(p.y, p.x); ntk_dbg_print(kinect_raw, 1); if (kinect_raw < 1e-5) continue; float err = kinect_raw-p.z; cv::putText(debug_img, format("%d", (int)(err*1000)), Point(p.x, p.y), CV_FONT_NORMAL, 0.4, Scalar(255,0,0)); ntk_dbg_print(pattern_points[0][pattern_i], 1); ntk_dbg_print(p, 1); ntk_dbg_print(kinect_raw, 1); depth_values.push_back(DepthCalibrationPoint(kinect_raw, p.z)); } imshow("errors", debug_img); cv::waitKey(0); }