#include #include #include #include #include #include #include #include #include "ladybug_model.h" #include #include #include #include #include #include #include #include #include using namespace dgc; using namespace std; using namespace Eigen; namespace bfs = boost::filesystem; //! The camera number we've calibrated the velodyne-ladybug transform to. int g_base_cam; //! The camera number to visualize. int g_view_cam; double g_brightness = 1.0; char *g_intrinsics_path; char *g_extrinsics_path; double g_ladybug_sync_offset; double g_ladybug_synchronizer_angle; bool g_show_intensities = false; dgc_velodyne_config_p g_velodyne_config = NULL; char *g_cal_filename = NULL; dgc_transform_t g_velo_offset; dgc_velodyne_index g_velodyne_index; dgc_velodyne_file_p g_velodyne_file; bool g_show_points = false; bool g_pause = false; IplImage *g_vis = NULL; int displayOverlay(char* window, IplImage* img, const MatrixXf& pointcloud, const VectorXf& intensities, const LadybugModel& lb3) { // -- Draw the points in the image. if(g_show_points && g_view_cam != 5) { for(int j=0; jInstallParams(argc, argv, params, sizeof(params)/sizeof(params[0])); } int main(int argc, char** argv) { if(argc != 3 && argc != 4) { cout << "Usage: " << argv[0] << " VLF LLF [IMAGE_DIR]" << endl; cout << " If IMAGE_DIR is provided, it will be created and filled with images for later processing into video." << endl; return 1; } // -- Set up image dump. string image_dir; bool dump_images = false; if(argc == 4) { dump_images = true; image_dir = argv[3]; if(bfs::exists(image_dir)) { cout << image_dir << " already exists, will not overwrite." << endl; return -1; } bfs::create_directory(image_dir); } // -- Connect to IPC and get the velo offset and cal filename. IpcInterface *ipc = new IpcStandardInterface(); ParamInterface *pint = new ParamInterface(ipc); if(ipc->ConnectLocked("calibration_viewer") < 0) dgc_fatal_error("Could not connect to IPC network."); read_parameters(pint, argc, argv); delete ipc; delete pint; g_view_cam = g_base_cam; // -- Read in the velodyne calibration file to g_velodyne_config. dgc_velodyne_get_config(&g_velodyne_config); if(dgc_velodyne_read_calibration(g_cal_filename, g_velodyne_config) != 0) { fprintf(stderr, "# ERROR: could not read calibration file!\n"); exit(0); } // Set g_velodyne_config->offset to be g_velo_offset. dgc_velodyne_integrate_offset(g_velo_offset, g_velodyne_config); // -- Load logfiles. cout << "Loading Velodyne Log File " << argv[1] << endl; g_velodyne_file = dgc_velodyne_open_file(argv[1]); if(g_velodyne_file == NULL) { cout << "Could not open " << argv[1] << " for reading." << endl; return 1; } char index_filename[300]; strcpy(index_filename, argv[1]); strcat(index_filename, ".index.gz"); g_velodyne_index.load(index_filename); cout << "Loading Ladybug Log File " << argv[2] << endl; LadybugPlayback lbp; lbp.openLLF(argv[2]); // -- Load the ladybug model. cout << "Loading Ladybug intrinsics at " << g_intrinsics_path << endl; cout << "Base cam is " << g_base_cam << ", extrinsics at " << g_extrinsics_path << endl; //LadybugModel lb3(g_base_cam, g_extrinsics_path, g_intrinsics_path); LadybugModel lb3(g_extrinsics_path, g_intrinsics_path); for(int i = 0; i < 6; ++i) cout << lb3.intrinsics_.cameras_[i].status() << endl; // -- Get the first spin / ladybug image pair. int spin_num = findFirstMatchingPair(lbp, g_velodyne_index); cout << "First spin with matching ladybug data is spin " << spin_num << endl; dgc_velodyne_spin spin; double applanix_lat, applanix_lon, applanix_alt; spin.load(g_velodyne_file, g_velodyne_config, &g_velodyne_index, spin_num, &applanix_lat, &applanix_lon, &applanix_alt); // -- Skip the first few frames, as they tend to be bad for our logs. int skip = 50; spin_num += skip; double vlf_timestamp = g_velodyne_index.spin[spin_num].pose[0].timestamp; // Allows for un-sychronized velo & ladybug. lbp.readTimestampPacket(vlf_timestamp + g_ladybug_sync_offset); while(true) { // -- Display the results. IplImage* warp = dgcToIpl(*lbp.cameraImage(g_view_cam)); if(!warp) break; MatrixXf cloud; VectorXf intensity; getSpinInVeloCoords(spin, g_ladybug_synchronizer_angle, g_velo_offset, &cloud, &intensity); int increment = displayOverlay("Calibration", warp, cloud * lb3.extrinsics_.veloToCamera_[g_view_cam], intensity, lb3); if(dump_images) { ostringstream path; path << image_dir << "/" << setprecision(16) << lbp.getTimestamp() << "_cam" << g_view_cam << ".png"; cvSaveImage(path.str().c_str(), warp); } cvReleaseImage(&warp); // -- Get the next ladybug image. spin_num += increment; if(spin_num >= g_velodyne_index.num_spins) break; double vlf_timestamp = g_velodyne_index.spin[spin_num].pose[0].timestamp; // Allows for un-sychronized velo & ladybug. lbp.readTimestampPacket(vlf_timestamp + g_ladybug_sync_offset); // -- Load the next spin. spin.load(g_velodyne_file, g_velodyne_config, &g_velodyne_index, spin_num, &applanix_lat, &applanix_lon, &applanix_alt); } return 0; }