mirror of https://github.com/opencv/opencv.git
Merge pull request #24877 from zzuliys:feature/mac
Orbbec Camera supports MacOS,Gemini2 and Gemini2L support Y16 format #24877 note: 1.Gemini2 and Gemini2L must use the latest firmware -- https://github.com/orbbec/OrbbecFirmware; 2.Administrator privileges are necessary to run on MacOS.pull/25294/head
parent
01dc010436
commit
2b9d1a2ff8
11 changed files with 357 additions and 60 deletions
@ -0,0 +1,18 @@ |
||||
function(download_orbbec_sdk root_var) |
||||
set(ORBBECSDK_DOWNLOAD_DIR "${OpenCV_BINARY_DIR}/3rdparty/orbbecsdk") |
||||
set(ORBBECSDK_FILE_HASH_CMAKE "2624c84837d3416fd8b3e95750e6e725") |
||||
ocv_download(FILENAME "v1.9.4.tar.gz" |
||||
HASH ${ORBBECSDK_FILE_HASH_CMAKE} |
||||
URL "https://github.com/orbbec/OrbbecSDK/archive/refs/tags/v1.9.4/" |
||||
DESTINATION_DIR ${ORBBECSDK_DOWNLOAD_DIR} |
||||
ID OrbbecSDK |
||||
STATUS res |
||||
UNPACK RELATIVE_URL |
||||
) |
||||
if(${res}) |
||||
message(STATUS "orbbec sdk downloaded to: ${ORBBECSDK_DOWNLOAD_DIR}") |
||||
set(${root_var} "${ORBBECSDK_DOWNLOAD_DIR}/OrbbecSDK-1.9.4" PARENT_SCOPE) |
||||
else() |
||||
message(FATAL_ERROR "Failed to download orbbec sdk") |
||||
endif() |
||||
endfunction() |
@ -1,28 +1,54 @@ |
||||
# --- obsensor --- |
||||
if(NOT HAVE_OBSENSOR) |
||||
if(WIN32) |
||||
check_include_file(mfapi.h HAVE_MFAPI) |
||||
check_include_file(vidcap.h HAVE_VIDCAP) |
||||
if(HAVE_MFAPI AND HAVE_VIDCAP) |
||||
set(HAVE_OBSENSOR TRUE) |
||||
set(HAVE_OBSENSOR_MSMF TRUE) |
||||
ocv_add_external_target(obsensor "" "" "HAVE_OBSENSOR;HAVE_OBSENSOR_MSMF") |
||||
else() |
||||
set(HAVE_OBSENSOR OFF) |
||||
set(HAVE_OBSENSOR_MSMF OFF) |
||||
if(NOT HAVE_MFAPI) |
||||
MESSAGE(STATUS "Could not find mfapi.h. Turning HAVE_OBSENSOR OFF") |
||||
endif() |
||||
if(NOT HAVE_VIDCAP) |
||||
MESSAGE(STATUS "Could not find vidcap.h. Turning HAVE_OBSENSOR OFF") |
||||
if(APPLE) |
||||
# force to use orbbec sdk on mac |
||||
set(OBSENSOR_USE_ORBBEC_SDK ON) |
||||
endif() |
||||
|
||||
if(OBSENSOR_USE_ORBBEC_SDK) |
||||
include(${CMAKE_SOURCE_DIR}/3rdparty/orbbecsdk/orbbecsdk.cmake) |
||||
download_orbbec_sdk(ORBBEC_SDK_ROOT_DIR) |
||||
message(STATUS "ORBBEC_SDK_ROOT_DIR: ${ORBBEC_SDK_ROOT_DIR}") |
||||
if(ORBBEC_SDK_ROOT_DIR) |
||||
set(OrbbecSDK_DIR "${ORBBEC_SDK_ROOT_DIR}") |
||||
find_package(OrbbecSDK REQUIRED) |
||||
message(STATUS "OrbbecSDK_FOUND: ${OrbbecSDK_FOUND}") |
||||
message(STATUS "OrbbecSDK_INCLUDE_DIRS: ${OrbbecSDK_INCLUDE_DIRS}") |
||||
if(OrbbecSDK_FOUND) |
||||
set(HAVE_OBSENSOR TRUE) |
||||
set(HAVE_OBSENSOR_ORBBEC_SDK TRUE) |
||||
ocv_add_external_target(obsensor "${OrbbecSDK_INCLUDE_DIRS}" "${OrbbecSDK_LIBRARY}" "HAVE_OBSENSOR;HAVE_OBSENSOR_ORBBEC_SDK") |
||||
file(COPY ${OrbbecSDK_DLL_FILES} DESTINATION ${CMAKE_BINARY_DIR}/bin) |
||||
file(COPY ${OrbbecSDK_DLL_FILES} DESTINATION ${CMAKE_BINARY_DIR}/lib) |
||||
install(FILES ${OrbbecSDK_DLL_FILES} DESTINATION ${OPENCV_LIB_INSTALL_PATH}) |
||||
ocv_install_3rdparty_licenses(OrbbecSDK ${OrbbecSDK_DIR}/LICENSE.txt) |
||||
endif() |
||||
endif() |
||||
elseif(UNIX) |
||||
check_include_file(linux/videodev2.h HAVE_CAMV4L2_OBSENSOR) |
||||
if(HAVE_CAMV4L2_OBSENSOR) |
||||
set(HAVE_OBSENSOR TRUE) |
||||
set(HAVE_OBSENSOR_V4L2 TRUE) |
||||
ocv_add_external_target(obsensor "" "" "HAVE_OBSENSOR;HAVE_OBSENSOR_V4L2") |
||||
else() |
||||
if(WIN32) |
||||
check_include_file(mfapi.h HAVE_MFAPI) |
||||
check_include_file(vidcap.h HAVE_VIDCAP) |
||||
if(HAVE_MFAPI AND HAVE_VIDCAP) |
||||
set(HAVE_OBSENSOR TRUE) |
||||
set(HAVE_OBSENSOR_MSMF TRUE) |
||||
ocv_add_external_target(obsensor "" "" "HAVE_OBSENSOR;HAVE_OBSENSOR_MSMF") |
||||
else() |
||||
set(HAVE_OBSENSOR OFF) |
||||
set(HAVE_OBSENSOR_MSMF OFF) |
||||
if(NOT HAVE_MFAPI) |
||||
MESSAGE(STATUS "Could not find mfapi.h. Turning HAVE_OBSENSOR OFF") |
||||
endif() |
||||
if(NOT HAVE_VIDCAP) |
||||
MESSAGE(STATUS "Could not find vidcap.h. Turning HAVE_OBSENSOR OFF") |
||||
endif() |
||||
endif() |
||||
elseif(UNIX) |
||||
check_include_file(linux/videodev2.h HAVE_CAMV4L2_OBSENSOR) |
||||
if(HAVE_CAMV4L2_OBSENSOR) |
||||
set(HAVE_OBSENSOR TRUE) |
||||
set(HAVE_OBSENSOR_V4L2 TRUE) |
||||
ocv_add_external_target(obsensor "" "" "HAVE_OBSENSOR;HAVE_OBSENSOR_V4L2") |
||||
endif() |
||||
endif() |
||||
endif() |
||||
endif() |
||||
|
@ -0,0 +1,154 @@ |
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
/*
|
||||
* Copyright(C) 2024 by ORBBEC Technology., Inc. |
||||
* Authors: |
||||
* Huang Zhenchang <yufeng@orbbec.com> |
||||
* Yu Shuai <daiyin@orbbec.com> |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
#if defined(HAVE_OBSENSOR) && defined(HAVE_OBSENSOR_ORBBEC_SDK) |
||||
#include "libobsensor/ObSensor.hpp" |
||||
#include "cap_obsensor_liborbbec.hpp" |
||||
|
||||
namespace cv |
||||
{ |
||||
Ptr<IVideoCapture> create_obsensor_capture(int index) |
||||
{ |
||||
return makePtr<VideoCapture_obsensor>(index); |
||||
} |
||||
|
||||
VideoCapture_obsensor::VideoCapture_obsensor(int) |
||||
{ |
||||
ob::Context::setLoggerToFile(OB_LOG_SEVERITY_OFF, ""); |
||||
config = std::make_shared<ob::Config>(); |
||||
pipe = std::make_shared<ob::Pipeline>(); |
||||
auto colorProfiles = pipe->getStreamProfileList(OB_SENSOR_COLOR); |
||||
auto colorProfile = colorProfiles->getProfile(OB_PROFILE_DEFAULT); |
||||
config->enableStream(colorProfile->as<ob::VideoStreamProfile>()); |
||||
|
||||
auto depthProfiles = pipe->getStreamProfileList(OB_SENSOR_DEPTH); |
||||
auto depthProfile = depthProfiles->getProfile(OB_PROFILE_DEFAULT); |
||||
config->enableStream(depthProfile->as<ob::VideoStreamProfile>()); |
||||
|
||||
config->setAlignMode(ALIGN_D2C_SW_MODE); |
||||
|
||||
pipe->start(config, [&](std::shared_ptr<ob::FrameSet> frameset) { |
||||
std::unique_lock<std::mutex> lk(videoFrameMutex); |
||||
colorFrame = frameset->colorFrame(); |
||||
depthFrame = frameset->depthFrame(); |
||||
}); |
||||
|
||||
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; |
||||
} |
||||
|
||||
VideoCapture_obsensor::~VideoCapture_obsensor(){ |
||||
pipe->stop(); |
||||
} |
||||
|
||||
double VideoCapture_obsensor::getProperty(int propIdx) const |
||||
{ |
||||
double rst = 0.0; |
||||
propIdx = propIdx & (~CAP_OBSENSOR_GENERATORS_MASK); |
||||
switch (propIdx) |
||||
{ |
||||
case CAP_PROP_OBSENSOR_INTRINSIC_FX: |
||||
rst = camParam.p1[0]; |
||||
break; |
||||
case CAP_PROP_OBSENSOR_INTRINSIC_FY: |
||||
rst = camParam.p1[1]; |
||||
break; |
||||
case CAP_PROP_OBSENSOR_INTRINSIC_CX: |
||||
rst = camParam.p1[2]; |
||||
break; |
||||
case CAP_PROP_OBSENSOR_INTRINSIC_CY: |
||||
rst = camParam.p1[3]; |
||||
break; |
||||
} |
||||
return rst; |
||||
} |
||||
|
||||
bool VideoCapture_obsensor::setProperty(int, double) |
||||
{ |
||||
return false; |
||||
} |
||||
|
||||
bool VideoCapture_obsensor::grabFrame() |
||||
{ |
||||
std::unique_lock<std::mutex> lk(videoFrameMutex); |
||||
grabbedColorFrame = colorFrame; |
||||
grabbedDepthFrame = depthFrame; |
||||
|
||||
return grabbedColorFrame || grabbedDepthFrame; |
||||
} |
||||
|
||||
bool VideoCapture_obsensor::retrieveFrame(int outputType, cv::OutputArray frame) |
||||
{ |
||||
switch (outputType) |
||||
{ |
||||
case CAP_OBSENSOR_BGR_IMAGE: |
||||
if(grabbedColorFrame != nullptr){ |
||||
auto format = grabbedColorFrame->format(); |
||||
if(format != OB_FORMAT_MJPEG){ |
||||
CV_LOG_WARNING(NULL, "Unsupported color frame format"); |
||||
return false; |
||||
} |
||||
auto mjpgMat = Mat(1, grabbedColorFrame->dataSize() , CV_8UC1, grabbedColorFrame->data()).clone(); |
||||
auto bgrMat = imdecode(mjpgMat, IMREAD_COLOR); |
||||
if(bgrMat.empty()){ |
||||
CV_LOG_WARNING(NULL, "Failed to decode color frame"); |
||||
return false; |
||||
} |
||||
bgrMat.copyTo(frame); |
||||
return true; |
||||
} |
||||
break; |
||||
case CAP_OBSENSOR_DEPTH_MAP: |
||||
if(grabbedDepthFrame != nullptr){ |
||||
auto format = grabbedDepthFrame->format(); |
||||
if(format != OB_FORMAT_Y16){ |
||||
CV_LOG_WARNING(NULL, "Unsupported depth frame format"); |
||||
return false; |
||||
} |
||||
Mat(grabbedDepthFrame->height(), grabbedDepthFrame->width(), CV_16UC1, grabbedDepthFrame->data()).copyTo(frame); |
||||
return true; |
||||
} |
||||
break; |
||||
default: |
||||
return false; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
int VideoCapture_obsensor::getCaptureDomain() |
||||
{ |
||||
return CAP_OBSENSOR; |
||||
} |
||||
|
||||
bool VideoCapture_obsensor::isOpened() const |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
} |
||||
#endif |
@ -0,0 +1,74 @@ |
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
/*
|
||||
* Copyright(C) 2024 by ORBBEC Technology., Inc. |
||||
* Authors: |
||||
* Huang Zhenchang <yufeng@orbbec.com> |
||||
* Yu Shuai <daiyin@orbbec.com> |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
#ifndef _CAP_LIBORBBEC_HPP_ |
||||
#define _CAP_LIBORBBEC_HPP_ |
||||
|
||||
#if defined(HAVE_OBSENSOR) && defined(HAVE_OBSENSOR_ORBBEC_SDK) |
||||
|
||||
#include <libobsensor/ObSensor.hpp> |
||||
#include <mutex> |
||||
|
||||
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]; |
||||
}; |
||||
|
||||
class VideoCapture_obsensor : public IVideoCapture |
||||
{ |
||||
public: |
||||
VideoCapture_obsensor(int index); |
||||
virtual ~VideoCapture_obsensor(); |
||||
|
||||
virtual double getProperty(int propIdx) const CV_OVERRIDE; |
||||
virtual bool setProperty(int propIdx, double propVal) CV_OVERRIDE; |
||||
|
||||
virtual bool grabFrame() CV_OVERRIDE; |
||||
virtual bool retrieveFrame(int outputType, OutputArray frame) CV_OVERRIDE; |
||||
virtual int getCaptureDomain() CV_OVERRIDE; |
||||
virtual bool isOpened() const CV_OVERRIDE; |
||||
|
||||
protected: |
||||
std::mutex videoFrameMutex; |
||||
std::shared_ptr<ob::VideoFrame> colorFrame; |
||||
std::shared_ptr<ob::VideoFrame> depthFrame; |
||||
std::shared_ptr<ob::VideoFrame> grabbedColorFrame; |
||||
std::shared_ptr<ob::VideoFrame> grabbedDepthFrame; |
||||
std::shared_ptr<ob::Pipeline> pipe; |
||||
std::shared_ptr<ob::Config> config; |
||||
CameraParam camParam; |
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif |
||||
#endif |
Loading…
Reference in new issue