diff --git a/CMakeLists.txt b/CMakeLists.txt index 124b8c9e0..17b0d5fbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,7 @@ if(VLIB_FORCESLIM) set(prophesee_core_FOUND OFF) endif() +option(BUILD_ZYNQGRABBER "Build the zynqGrabber module" ON) add_subdirectory(cpp_tools) #install the package diff --git a/cpp_tools/CMakeLists.txt b/cpp_tools/CMakeLists.txt index d981e6e37..0dcf42754 100755 --- a/cpp_tools/CMakeLists.txt +++ b/cpp_tools/CMakeLists.txt @@ -1,4 +1,6 @@ -add_subdirectory(zynqGrabber) +if(BUILD_ZYNQGRABBER) + add_subdirectory(zynqGrabber) +endif() add_subdirectory(hexViewer) #add_subdirectory(binaryDumper) diff --git a/ev2/event-driven/vis/IPT.cpp b/ev2/event-driven/vis/IPT.cpp index 442d686a4..1bf63a7e4 100644 --- a/ev2/event-driven/vis/IPT.cpp +++ b/ev2/event-driven/vis/IPT.cpp @@ -62,6 +62,9 @@ bool vIPT::importIntrinsics(int cam, Bottle ¶meters) cam_matrix[cam].at(2, 2) = 1.0; cam_matrix[cam].at(0, 2) = parameters.find("cx").asFloat64(); cam_matrix[cam].at(1, 2) = parameters.find("cy").asFloat64(); + if(cam == 0) { + distortion_model = parameters.find("distortion_model").asString(); + } dist_coeff[cam] = cv::Mat(4, 1, CV_64FC1); dist_coeff[cam].at(0, 0) = parameters.find("k1").asFloat64(); @@ -104,9 +107,19 @@ bool vIPT::computeForwardReverseMaps(int cam) mat_reverse_map[cam] = cv::Mat(size_shared, CV_32FC2); //mat_reverse_map fill - cv::initUndistortRectifyMap(cam_matrix[cam], dist_coeff[cam], rotation[cam], - projection[cam], size_shared, CV_32FC2, - mat_reverse_map[cam], cv::noArray()); + + if(distortion_model == "b'radtan'") { + cv::initUndistortRectifyMap(cam_matrix[cam], dist_coeff[cam], rotation[cam], + projection[cam], size_shared, CV_32FC2, + mat_reverse_map[cam], cv::noArray()); + } else if (distortion_model == "equidistant") { + std::vector maps(2); + cv::split(mat_reverse_map[cam], maps); + cv::fisheye::initUndistortRectifyMap(cam_matrix[cam], dist_coeff[cam], rotation[cam], + projection[cam], size_shared, CV_32F, + maps[0], maps[1]); + cv::merge(maps, mat_reverse_map[cam]); + } if(mat_reverse_map[cam].empty()) { yError() << "Camera Calibration failed"; @@ -164,6 +177,20 @@ const cv::Mat& vIPT::getQ(){ return Q; } +const cv::Mat& vIPT::getK(int cam) { + if(cam == 1) { + return cam_matrix[1]; + } + return cam_matrix[0]; +} + +const cv::Size& vIPT::getRes(int cam) { + if(cam == 1) { + return size_cam[1]; + } + return size_cam[0]; +} + bool vIPT::configure(const string &calib_file_path, int size_scaler) { @@ -192,12 +219,19 @@ bool vIPT::configure(const string &calib_file_path, int size_scaler) //compute stereo + rectification Q = cv::Mat(4, 4, CV_64FC1); - //Computing homographies for left and right image - cv::stereoRectify(cam_matrix[0], dist_coeff[0], cam_matrix[1], - dist_coeff[1], size_cam[0], stereo_rotation, stereo_translation, - rotation[0], rotation[1], projection[0],projection[1], Q, - CALIB_ZERO_DISPARITY, 1, size_shared); + if(distortion_model == "b'radtan'") { + cv::stereoRectify(cam_matrix[0], dist_coeff[0], cam_matrix[1], + dist_coeff[1], size_cam[0], stereo_rotation, stereo_translation, + rotation[0], rotation[1], projection[0],projection[1], Q, + CALIB_ZERO_DISPARITY, 1, size_shared); + } + else if(distortion_model == "equidistant") { + cv::fisheye::stereoRectify(cam_matrix[0], dist_coeff[0], cam_matrix[1], + dist_coeff[1], size_cam[0], stereo_rotation, stereo_translation, + rotation[0], rotation[1], projection[0],projection[1], Q, + CALIB_ZERO_DISPARITY, size_shared); + } } else { if(valid_cam1) diff --git a/ev2/event-driven/vis/IPT.h b/ev2/event-driven/vis/IPT.h index a817d9637..b4a77413e 100644 --- a/ev2/event-driven/vis/IPT.h +++ b/ev2/event-driven/vis/IPT.h @@ -36,6 +36,7 @@ class vIPT { cv::Mat projection[2]; cv::Mat rotation[2]; cv::Mat Q; + std::string distortion_model; cv::Mat point_forward_map[2]; cv::Mat point_reverse_map[2]; @@ -52,6 +53,8 @@ class vIPT { vIPT(); const cv::Mat& getQ(); + const cv::Mat& getK(int cam = 0); + const cv::Size& getRes(int cam = 0); void setProjectedImageSize(int height, int width); bool configure(const std::string &calib_file_path, int size_scaler = 2); bool showMapProjections(double seconds = 0);