#include #include #include #include #include #include #include #include #include using namespace Eigen; using boost::shared_ptr; using namespace track_manager; using namespace std; using namespace vlr; using namespace dgc; #define PADDING 10 #define SKIP (getenv("SKIP") ? atoi(getenv("SKIP")) : 50) char *g_intrinsics_path; char *g_extrinsics_path; double g_ladybug_sync_offset; double g_ladybug_synchronizer_angle; bool getPointsInImage(int cam_num, const Frame& frame, const LadybugModel& lbmodel, MatrixXi* img_pts) { MatrixXd velo_pts; if(!frame.getCloudInVeloCoords(&velo_pts)) { cout << "Warning: No points in frame." << endl; return false; } if(!lbmodel.projectVeloToWarpedImage(cam_num, velo_pts, img_pts)) { //cerr << "Warning: none of the " << velo_pts.rows() << " velo points in the frame projected into the image." << endl; return false; } return true; } shared_ptr interpolateBoundingBox(const CvRect& r0, const CvRect& r1, double interpolation) { CvRect* r = new CvRect; r->x = r1.x*interpolation + r0.x*(1-interpolation); r->y = r1.y*interpolation + r0.y*(1-interpolation); r->width = r1.width*interpolation + r0.width*(1-interpolation); r->height = r1.height*interpolation + r0.height*(1-interpolation); shared_ptr rect(r); return rect; } void padBoundingBox(int pad, const IplImage* img, CvRect* box) { assert(box); assert(img); box->x = box->x - pad/2; box->width = box->width + pad; box->y = box->y - pad/2; box->height = box->height + pad; if(box->x < 0) box->x = 0; if(box->y < 0) box->y = 0; if(box->width + box->x >= img->width) box->width = img->width - box->x - 1; if(box->height + box->y >= img->height) box->height = img->height - box->y - 1; } //! Returns NULL if no box. shared_ptr getFrameBoundingBox(int cam_num, const Frame& frame, const LadybugModel& lbmodel) { shared_ptr box((CvRect*)NULL); MatrixXi img_pts; if(!getPointsInImage(cam_num, frame, lbmodel, &img_pts)) return box; // -- Get the bounding box. int max_u = 0, max_v = 0; int min_u = 1e6, min_v = 1e6; for(int i = 0; i < img_pts.rows(); ++i) { int u = img_pts(i, 0); int v = img_pts(i, 1); if(u > max_u) max_u = u; if(v > max_v) max_v = v; if(u < min_u) min_u = u; if(v < min_v) min_v = v; } box = shared_ptr(new CvRect); box->x = min_u; box->width = max_u - min_u; box->y = min_v; box->height = max_v - min_v; return box; } void read_parameters(ParamInterface *pint, int argc, char **argv) { Param params[] = { {"ladybug", "intrinsics_path", DGC_PARAM_FILENAME, &g_intrinsics_path, 0, NULL}, {"ladybug", "extrinsics_path", DGC_PARAM_FILENAME, &g_extrinsics_path, 0, NULL}, {"ladybug", "default_sync_offset", DGC_PARAM_DOUBLE, &g_ladybug_sync_offset, 0, NULL}, {"ladybug", "synchronizer_angle", DGC_PARAM_DOUBLE, &g_ladybug_synchronizer_angle, 0, NULL}, }; pint->InstallParams(argc, argv, params, sizeof(params)/sizeof(params[0])); } void displayForDebug(const ImageLabelManager& dataset) { int idx = dataset.size() - 1; cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl; cout << "Dataset contains " << dataset.size() << " images." << endl; cout << dataset.getPathForImage(idx) << endl; IplImage* labeled = dataset.getLabeledImage(idx); cvShowImage("labeled", labeled); cvWaitKey(100); cvReleaseImage(&labeled); vector