From f4538f50202601ddfc16d99c63449ef6d2f8af3a Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Tue, 12 Aug 2025 15:46:28 +0300 Subject: [PATCH] Expose Orbbec color camera distortion coefficients as API. --- modules/videoio/include/opencv2/videoio.hpp | 10 +++- .../videoio/src/cap_obsensor_liborbbec.cpp | 50 ++++++++++++++++--- .../videoio/src/cap_obsensor_liborbbec.hpp | 10 +--- samples/cpp/videocapture_obsensor.cpp | 13 +++++ 4 files changed, 66 insertions(+), 17 deletions(-) diff --git a/modules/videoio/include/opencv2/videoio.hpp b/modules/videoio/include/opencv2/videoio.hpp index a3ce5dc6e9..2457703f78 100644 --- a/modules/videoio/include/opencv2/videoio.hpp +++ b/modules/videoio/include/opencv2/videoio.hpp @@ -718,7 +718,15 @@ enum VideoCaptureOBSensorProperties{ CAP_PROP_OBSENSOR_DEPTH_POS_MSEC=26006, CAP_PROP_OBSENSOR_DEPTH_WIDTH=26007, CAP_PROP_OBSENSOR_DEPTH_HEIGHT=26008, - CAP_PROP_OBSENSOR_DEPTH_FPS=26009 + CAP_PROP_OBSENSOR_DEPTH_FPS=26009, + CAP_PROP_OBSENSOR_COLOR_DISTORTION_K1=26010, + CAP_PROP_OBSENSOR_COLOR_DISTORTION_K2=26011, + CAP_PROP_OBSENSOR_COLOR_DISTORTION_K3=26012, + CAP_PROP_OBSENSOR_COLOR_DISTORTION_K4=26013, + CAP_PROP_OBSENSOR_COLOR_DISTORTION_K5=26014, + CAP_PROP_OBSENSOR_COLOR_DISTORTION_K6=26015, + CAP_PROP_OBSENSOR_COLOR_DISTORTION_P1=26016, + CAP_PROP_OBSENSOR_COLOR_DISTORTION_P2=26017 }; //! @} OBSENSOR diff --git a/modules/videoio/src/cap_obsensor_liborbbec.cpp b/modules/videoio/src/cap_obsensor_liborbbec.cpp index 40d8ba283f..3337d6f3ba 100644 --- a/modules/videoio/src/cap_obsensor_liborbbec.cpp +++ b/modules/videoio/src/cap_obsensor_liborbbec.cpp @@ -84,10 +84,19 @@ VideoCapture_obsensor::VideoCapture_obsensor(int, const cv::VideoCaptureParamete }); auto param = pipe->getCameraParam(); - camParam.p1[0] = param.rgbIntrinsic.fx; - camParam.p1[1] = param.rgbIntrinsic.fy; - camParam.p1[2] = param.rgbIntrinsic.cx; - camParam.p1[3] = param.rgbIntrinsic.cy; + camParam.intrinsicColor[0] = param.rgbIntrinsic.fx; + camParam.intrinsicColor[1] = param.rgbIntrinsic.fy; + camParam.intrinsicColor[2] = param.rgbIntrinsic.cx; + camParam.intrinsicColor[3] = param.rgbIntrinsic.cy; + + camParam.distortionColor[0] = param.depthDistortion.k1; + camParam.distortionColor[1] = param.depthDistortion.k2; + camParam.distortionColor[2] = param.depthDistortion.k3; + camParam.distortionColor[3] = param.depthDistortion.k4; + camParam.distortionColor[4] = param.depthDistortion.k5; + camParam.distortionColor[5] = param.depthDistortion.k6; + camParam.distortionColor[6] = param.depthDistortion.p1; + camParam.distortionColor[7] = param.depthDistortion.p2; } VideoCapture_obsensor::~VideoCapture_obsensor(){ @@ -101,17 +110,42 @@ double VideoCapture_obsensor::getProperty(int propIdx) const switch (propIdx) { case CAP_PROP_OBSENSOR_INTRINSIC_FX: - rst = camParam.p1[0]; + rst = camParam.intrinsicColor[0]; break; case CAP_PROP_OBSENSOR_INTRINSIC_FY: - rst = camParam.p1[1]; + rst = camParam.intrinsicColor[1]; break; case CAP_PROP_OBSENSOR_INTRINSIC_CX: - rst = camParam.p1[2]; + rst = camParam.intrinsicColor[2]; break; case CAP_PROP_OBSENSOR_INTRINSIC_CY: - rst = camParam.p1[3]; + rst = camParam.intrinsicColor[3]; break; + case CAP_PROP_OBSENSOR_COLOR_DISTORTION_K1: + rst = camParam.distortionColor[0]; + break; + case CAP_PROP_OBSENSOR_COLOR_DISTORTION_K2: + rst = camParam.distortionColor[1]; + break; + case CAP_PROP_OBSENSOR_COLOR_DISTORTION_K3: + rst = camParam.distortionColor[2]; + break; + case CAP_PROP_OBSENSOR_COLOR_DISTORTION_K4: + rst = camParam.distortionColor[3]; + break; + case CAP_PROP_OBSENSOR_COLOR_DISTORTION_K5: + rst = camParam.distortionColor[4]; + break; + case CAP_PROP_OBSENSOR_COLOR_DISTORTION_K6: + rst = camParam.distortionColor[5]; + break; + case CAP_PROP_OBSENSOR_COLOR_DISTORTION_P1: + rst = camParam.distortionColor[6]; + break; + case CAP_PROP_OBSENSOR_COLOR_DISTORTION_P2: + rst = camParam.distortionColor[7]; + break; + case CAP_PROP_POS_MSEC: case CAP_PROP_OBSENSOR_RGB_POS_MSEC: if (grabbedColorFrame) diff --git a/modules/videoio/src/cap_obsensor_liborbbec.hpp b/modules/videoio/src/cap_obsensor_liborbbec.hpp index 44df040030..aa8c1d4728 100644 --- a/modules/videoio/src/cap_obsensor_liborbbec.hpp +++ b/modules/videoio/src/cap_obsensor_liborbbec.hpp @@ -33,14 +33,8 @@ namespace cv struct CameraParam { - float p0[4]; - float p1[4]; - float p2[9]; - float p3[3]; - float p4[5]; - float p5[5]; - uint32_t p6[2]; - uint32_t p7[2]; + float intrinsicColor[4]; + float distortionColor[8]; }; class VideoCapture_obsensor : public IVideoCapture diff --git a/samples/cpp/videocapture_obsensor.cpp b/samples/cpp/videocapture_obsensor.cpp index 03f0c49381..823dcb8f88 100644 --- a/samples/cpp/videocapture_obsensor.cpp +++ b/samples/cpp/videocapture_obsensor.cpp @@ -78,7 +78,20 @@ int main(int argc, char** argv) double fy = obsensorCapture.get(CAP_PROP_OBSENSOR_INTRINSIC_FY); double cx = obsensorCapture.get(CAP_PROP_OBSENSOR_INTRINSIC_CX); double cy = obsensorCapture.get(CAP_PROP_OBSENSOR_INTRINSIC_CY); + + double k1 = obsensorCapture.get(CAP_PROP_OBSENSOR_COLOR_DISTORTION_K1); + double k2 = obsensorCapture.get(CAP_PROP_OBSENSOR_COLOR_DISTORTION_K2); + double k3 = obsensorCapture.get(CAP_PROP_OBSENSOR_COLOR_DISTORTION_K3); + double k4 = obsensorCapture.get(CAP_PROP_OBSENSOR_COLOR_DISTORTION_K4); + double k5 = obsensorCapture.get(CAP_PROP_OBSENSOR_COLOR_DISTORTION_K5); + double k6 = obsensorCapture.get(CAP_PROP_OBSENSOR_COLOR_DISTORTION_K6); + double p1 = obsensorCapture.get(CAP_PROP_OBSENSOR_COLOR_DISTORTION_P1); + double p2 = obsensorCapture.get(CAP_PROP_OBSENSOR_COLOR_DISTORTION_P1); + std::cout << "obsensor camera intrinsic params: fx=" << fx << ", fy=" << fy << ", cx=" << cx << ", cy=" << cy << std::endl; + std::cout << "obsensor camera distortion params: k,p=" << k1 << ", " << k2 << ", " << k3 << ", " + << k4 << ", " << k5 << ", " << k6 << ", " + << p1 << ", " << p2 << std::endl; Mat image; Mat depthMap;