refactor(api): move camera models

This commit is contained in:
John Zhao 2019-05-30 16:19:06 +08:00
parent bc7e4919e2
commit f54eef8ad1
9 changed files with 87 additions and 49 deletions

View File

@ -128,22 +128,25 @@ if(WITH_GLOG)
) )
endif() endif()
## camodocal ## camera_models
if(WITH_CAM_MODELS) if(WITH_CAM_MODELS)
set(EIGEN_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty) set(EIGEN_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty)
message(STATUS "EIGEN_INCLUDE_DIR: ${EIGEN_INCLUDE_DIR}") message(STATUS "EIGEN_INCLUDE_DIR: ${EIGEN_INCLUDE_DIR}")
include_directories( include_directories(
include
${CMAKE_CURRENT_BINARY_DIR}/include
${EIGEN_INCLUDE_DIR} ${EIGEN_INCLUDE_DIR}
src/mynteye/api/camodocal/include src/mynteye/api/camera_models
) )
add_library(camodocal STATIC add_library(camera_models STATIC
src/mynteye/api/camodocal/src/camera_models/Camera.cc src/mynteye/api/camera_models/camera.cc
src/mynteye/api/camodocal/src/camera_models/EquidistantCamera.cc src/mynteye/api/camera_models/equidistant_camera.cc
src/mynteye/api/camodocal/src/gpl/gpl.cc src/mynteye/api/camera_models/gpl.cc
) )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif() endif()
@ -252,7 +255,7 @@ if(OS_MAC)
target_link_libraries(${MYNTEYE_NAME} PUBLIC ${OSX_EXTRA_LIBS} ) target_link_libraries(${MYNTEYE_NAME} PUBLIC ${OSX_EXTRA_LIBS} )
endif() endif()
if(WITH_CAM_MODELS) if(WITH_CAM_MODELS)
target_link_libraries(${MYNTEYE_NAME} PRIVATE camodocal) target_link_libraries(${MYNTEYE_NAME} PRIVATE camera_models)
endif() endif()
target_link_threads(${MYNTEYE_NAME}) target_link_threads(${MYNTEYE_NAME})

View File

@ -12,9 +12,12 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include <opencv2/calib3d/calib3d.hpp> #include <opencv2/calib3d/calib3d.hpp>
#include "camodocal/camera_models/Camera.h"
namespace camodocal { #include "camera.h"
MYNTEYE_BEGIN_NAMESPACE
namespace models {
Camera::Parameters::Parameters(ModelType modelType) Camera::Parameters::Parameters(ModelType modelType)
: m_modelType(modelType), m_imageWidth(0), m_imageHeight(0) { : m_modelType(modelType), m_imageWidth(0), m_imageHeight(0) {
@ -208,4 +211,7 @@ void Camera::projectPoints(
imagePoints.push_back(cv::Point2f(p(0), p(1))); imagePoints.push_back(cv::Point2f(p(0), p(1)));
} }
} }
}
} // namespace models
MYNTEYE_END_NAMESPACE

View File

@ -11,15 +11,19 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#ifndef SRC_MYNTEYE_API_CAMODOCAL_INCLUDE_CAMODOCAL_CAMERA_MODELS_CAMERA_H_ #ifndef MYNTEYE_CAMERA_MODELS_CAMERA_H_
#define SRC_MYNTEYE_API_CAMODOCAL_INCLUDE_CAMODOCAL_CAMERA_MODELS_CAMERA_H_ #define MYNTEYE_CAMERA_MODELS_CAMERA_H_
#include <vector> #include <vector>
#include <memory> #include <memory>
#include "eigen3/Eigen/Dense" #include "eigen3/Eigen/Dense"
#include <opencv2/core/core.hpp> #include <opencv2/core/core.hpp>
namespace camodocal { #include "mynteye/mynteye.h"
MYNTEYE_BEGIN_NAMESPACE
namespace models {
class Camera { class Camera {
public: public:
@ -134,5 +138,7 @@ typedef std::shared_ptr<Camera> CameraPtr;
typedef std::shared_ptr<const Camera> CameraConstPtr; typedef std::shared_ptr<const Camera> CameraConstPtr;
} }
#endif // SRC_MYNTEYE_API_CAMODOCAL_INCLUDE_CAMODOCAL_CAMERA_MODELS_CAMERA_H_ MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_CAMERA_MODELS_CAMERA_H_

View File

@ -16,15 +16,19 @@
#include <cstdint> #include <cstdint>
#include <cmath> #include <cmath>
#include <cstdio> #include <cstdio>
#include "camodocal/camera_models/EquidistantCamera.h"
#include "eigen3/Eigen/Dense" #include "eigen3/Eigen/Dense"
#include <opencv2/calib3d/calib3d.hpp> #include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/core/eigen.hpp> #include <opencv2/core/eigen.hpp>
#include <opencv2/imgproc/imgproc.hpp> #include <opencv2/imgproc/imgproc.hpp>
#include "camodocal/gpl/gpl.h"
// #include "mynteye/logger.h"
namespace camodocal { #include "equidistant_camera.h"
#include "gpl.h"
MYNTEYE_BEGIN_NAMESPACE
namespace models {
#define PI M_PI #define PI M_PI
#define PI_2 1.5707963 #define PI_2 1.5707963
float ApproxAtan2(float y, float x) float ApproxAtan2(float y, float x)
@ -652,4 +656,7 @@ void EquidistantCamera::backprojectSymmetric(
} }
} }
} }
} // namespace camodocal
} // namespace models
MYNTEYE_END_NAMESPACE

View File

@ -11,14 +11,17 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#ifndef SRC_MYNTEYE_API_CAMODOCAL_INCLUDE_CAMODOCAL_CAMERA_MODELS_EQUIDISTANTCAMERA_H_ #ifndef MYNTEYE_CAMERA_MODELS_EQUIDISTANT_CAMERA_H_
#define SRC_MYNTEYE_API_CAMODOCAL_INCLUDE_CAMODOCAL_CAMERA_MODELS_EQUIDISTANTCAMERA_H_ #define MYNTEYE_CAMERA_MODELS_EQUIDISTANT_CAMERA_H_
#include <string> #include <string>
#include "Camera.h"
#include <opencv2/core/core.hpp> #include <opencv2/core/core.hpp>
namespace camodocal { #include "camera.h"
MYNTEYE_BEGIN_NAMESPACE
namespace models {
/** /**
* J. Kannala, and S. Brandt, A Generic Camera Model and Calibration Method * J. Kannala, and S. Brandt, A Generic Camera Model and Calibration Method
@ -227,5 +230,7 @@ void EquidistantCamera::spaceToPlane(
} }
} }
#endif // SRC_MYNTEYE_API_CAMODOCAL_INCLUDE_CAMODOCAL_CAMERA_MODELS_EQUIDISTANTCAMERA_H_ MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_CAMERA_MODELS_EQUIDISTANT_CAMERA_H_

View File

@ -11,7 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "camodocal/gpl/gpl.h" #include "gpl.h"
#include <set> #include <set>
#ifdef _WIN32 #ifdef _WIN32
@ -56,7 +56,9 @@ const double WGS84_ECCSQ = 0.00669437999013;
#define fminf(x, y) (((x) < (y)) ? (x) : (y)) #define fminf(x, y) (((x) < (y)) ? (x) : (y))
#endif #endif
namespace camodocal { MYNTEYE_BEGIN_NAMESPACE
namespace models {
double hypot3(double x, double y, double z) { double hypot3(double x, double y, double z) {
return sqrt(square(x) + square(y) + square(z)); return sqrt(square(x) + square(y) + square(z));
@ -524,5 +526,6 @@ char UTMLetterDesignator(double latitude) {
return letterDesignator; return letterDesignator;
} }
} // namespace camodocal } // namespace models
MYNTEYE_END_NAMESPACE

View File

@ -11,15 +11,19 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#ifndef SRC_MYNTEYE_API_CAMODOCAL_INCLUDE_CAMODOCAL_GPL_GPL_H_ #ifndef MYNTEYE_CAMERA_MODELS_GPL_H_
#define SRC_MYNTEYE_API_CAMODOCAL_INCLUDE_CAMODOCAL_GPL_GPL_H_ #define MYNTEYE_CAMERA_MODELS_GPL_H_
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <opencv2/core/core.hpp> #include <opencv2/core/core.hpp>
namespace camodocal { #include "mynteye/mynteye.h"
MYNTEYE_BEGIN_NAMESPACE
namespace models {
template <class T> template <class T>
const T clamp(const T &v, const T &a, const T &b) { const T clamp(const T &v, const T &a, const T &b) {
@ -105,5 +109,7 @@ void UTMtoLL(
double &latitude, double &longitude); // NOLINT double &latitude, double &longitude); // NOLINT
} }
#endif // SRC_MYNTEYE_API_CAMODOCAL_INCLUDE_CAMODOCAL_GPL_GPL_H_ MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_CAMERA_MODELS_GPL_H_

View File

@ -37,8 +37,8 @@ cv::Mat RectifyProcessor::rectifyrad(const cv::Mat& R) {
return R.clone(); return R.clone();
} }
void RectifyProcessor::stereoRectify(camodocal::CameraPtr leftOdo, void RectifyProcessor::stereoRectify(models::CameraPtr leftOdo,
camodocal::CameraPtr rightOdo, const CvMat* K1, const CvMat* K2, models::CameraPtr rightOdo, const CvMat* K1, const CvMat* K2,
const CvMat* D1, const CvMat* D2, CvSize imageSize, const CvMat* D1, const CvMat* D2, CvSize imageSize,
const CvMat* matR, const CvMat* matT, const CvMat* matR, const CvMat* matT,
CvMat* _R1, CvMat* _R2, CvMat* _P1, CvMat* _P2, double* T_mul_f, CvMat* _R1, CvMat* _R2, CvMat* _P1, CvMat* _P2, double* T_mul_f,
@ -249,8 +249,8 @@ struct CameraROSMsgInfo RectifyProcessor::getCalibMatData(
} }
std::shared_ptr<struct CameraROSMsgInfoPair> RectifyProcessor::stereoRectify( std::shared_ptr<struct CameraROSMsgInfoPair> RectifyProcessor::stereoRectify(
camodocal::CameraPtr leftOdo, models::CameraPtr leftOdo,
camodocal::CameraPtr rightOdo, models::CameraPtr rightOdo,
mynteye::IntrinsicsEquidistant in_left, mynteye::IntrinsicsEquidistant in_left,
mynteye::IntrinsicsEquidistant in_right, mynteye::IntrinsicsEquidistant in_right,
mynteye::Extrinsics ex_right_to_left) { mynteye::Extrinsics ex_right_to_left) {
@ -330,10 +330,10 @@ std::shared_ptr<struct CameraROSMsgInfoPair> RectifyProcessor::stereoRectify(
return std::make_shared<struct CameraROSMsgInfoPair>(info_pair); return std::make_shared<struct CameraROSMsgInfoPair>(info_pair);
} }
camodocal::CameraPtr RectifyProcessor::generateCameraFromIntrinsicsEquidistant( models::CameraPtr RectifyProcessor::generateCameraFromIntrinsicsEquidistant(
const mynteye::IntrinsicsEquidistant & in) { const mynteye::IntrinsicsEquidistant & in) {
camodocal::EquidistantCameraPtr camera( models::EquidistantCameraPtr camera(
new camodocal::EquidistantCamera("KANNALA_BRANDT", new models::EquidistantCamera("KANNALA_BRANDT",
in.width, in.width,
in.height, in.height,
in.coeffs[0], in.coeffs[0],
@ -354,9 +354,9 @@ void RectifyProcessor::InitParams(
calib_model = CalibrationModel::KANNALA_BRANDT; calib_model = CalibrationModel::KANNALA_BRANDT;
in_left.ResizeIntrinsics(); in_left.ResizeIntrinsics();
in_right.ResizeIntrinsics(); in_right.ResizeIntrinsics();
camodocal::CameraPtr camera_odo_ptr_left = models::CameraPtr camera_odo_ptr_left =
generateCameraFromIntrinsicsEquidistant(in_left); generateCameraFromIntrinsicsEquidistant(in_left);
camodocal::CameraPtr camera_odo_ptr_right = models::CameraPtr camera_odo_ptr_right =
generateCameraFromIntrinsicsEquidistant(in_right); generateCameraFromIntrinsicsEquidistant(in_right);
auto calib_info_tmp = stereoRectify(camera_odo_ptr_left, auto calib_info_tmp = stereoRectify(camera_odo_ptr_left,
camera_odo_ptr_right, camera_odo_ptr_right,

View File

@ -23,11 +23,13 @@
#include "mynteye/types.h" #include "mynteye/types.h"
#include "mynteye/api/processor.h" #include "mynteye/api/processor.h"
#include "mynteye/device/device.h" #include "mynteye/device/device.h"
#include <camodocal/camera_models/EquidistantCamera.h>
#include <opencv2/core/eigen.hpp> #include "equidistant_camera.h"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp> #include <opencv2/core/core.hpp>
#include <opencv2/core/eigen.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/highgui/highgui.hpp>
MYNTEYE_BEGIN_NAMESPACE MYNTEYE_BEGIN_NAMESPACE
@ -76,8 +78,8 @@ class RectifyProcessor : public Processor {
cv::Mat rectifyrad(const cv::Mat& R); cv::Mat rectifyrad(const cv::Mat& R);
void stereoRectify(camodocal::CameraPtr leftOdo, void stereoRectify(models::CameraPtr leftOdo,
camodocal::CameraPtr rightOdo, const CvMat* K1, const CvMat* K2, models::CameraPtr rightOdo, const CvMat* K1, const CvMat* K2,
const CvMat* D1, const CvMat* D2, CvSize imageSize, const CvMat* D1, const CvMat* D2, CvSize imageSize,
const CvMat* matR, const CvMat* matT, const CvMat* matR, const CvMat* matT,
CvMat* _R1, CvMat* _R2, CvMat* _P1, CvMat* _P2, double* T_mul_f, CvMat* _R1, CvMat* _R2, CvMat* _P1, CvMat* _P2, double* T_mul_f,
@ -93,13 +95,13 @@ class RectifyProcessor : public Processor {
const mynteye::IntrinsicsEquidistant& in); const mynteye::IntrinsicsEquidistant& in);
std::shared_ptr<struct CameraROSMsgInfoPair> stereoRectify( std::shared_ptr<struct CameraROSMsgInfoPair> stereoRectify(
camodocal::CameraPtr leftOdo, models::CameraPtr leftOdo,
camodocal::CameraPtr rightOdo, models::CameraPtr rightOdo,
mynteye::IntrinsicsEquidistant in_left, mynteye::IntrinsicsEquidistant in_left,
mynteye::IntrinsicsEquidistant in_right, mynteye::IntrinsicsEquidistant in_right,
mynteye::Extrinsics ex_right_to_left); mynteye::Extrinsics ex_right_to_left);
camodocal::CameraPtr generateCameraFromIntrinsicsEquidistant( models::CameraPtr generateCameraFromIntrinsicsEquidistant(
const mynteye::IntrinsicsEquidistant & in); const mynteye::IntrinsicsEquidistant & in);
CalibrationModel calib_model; CalibrationModel calib_model;