提交 936d2963 编写于 作者: P Pavel Rojtberg

videoio: add rudimentary librealsense 1.x support

it is reusing CAP_INTELPERC* enums as Intel PerC is deprecated and
librealsense replaces it.
上级 cd2b188c
......@@ -269,6 +269,7 @@ OCV_OPTION(WITH_OPENCLAMDFFT "Include AMD OpenCL FFT library support" ON
OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )
OCV_OPTION(WITH_DIRECTX "Include DirectX support" ON IF (WIN32 AND NOT WINRT) )
OCV_OPTION(WITH_INTELPERC "Include Intel Perceptual Computing support" OFF IF (WIN32 AND NOT WINRT) )
OCV_OPTION(WITH_LIBREALSENSE "Include Intel librealsense support" OFF IF (NOT WITH_INTELPERC) )
OCV_OPTION(WITH_MATLAB "Include Matlab support" ON IF (NOT ANDROID AND NOT IOS AND NOT WINRT))
OCV_OPTION(WITH_VA "Include VA support" OFF IF (UNIX AND NOT ANDROID) )
OCV_OPTION(WITH_VA_INTEL "Include Intel VA-API/OpenCL support" OFF IF (UNIX AND NOT ANDROID) )
......
# Main variables:
# LIBREALSENSE_LIBRARIES and LIBREALSENSE_INCLUDE to link Intel librealsense modules
# HAVE_LIBREALSENSE for conditional compilation OpenCV with/without librealsense
find_path(LIBREALSENSE_INCLUDE_DIR "librealsense/rs.hpp" PATHS "$ENV{LIBREALSENSE_INCLUDE}" DOC "Path to librealsense interface headers")
find_library(LIBREALSENSE_LIBRARIES "realsense" PATHS "$ENV{LIBREALSENSE_LIB}" DOC "Path to librealsense interface libraries")
if(LIBREALSENSE_INCLUDE_DIR AND LIBREALSENSE_LIBRARIES)
set(HAVE_LIBREALSENSE TRUE)
else()
set(HAVE_LIBREALSENSE FALSE)
message( WARNING, " librealsense include directory (set by LIBREALSENSE_INCLUDE_DIR variable) is not found or does not have librealsense include files." )
endif() #if(LIBREALSENSE_INCLUDE_DIR AND LIBREALSENSE_LIBRARIES)
mark_as_advanced(FORCE LIBREALSENSE_LIBRARIES LIBREALSENSE_INCLUDE_DIR)
\ No newline at end of file
......@@ -290,6 +290,11 @@ if(APPLE)
endif()
endif(APPLE)
# --- Intel librealsense ---
if(WITH_LIBREALSENSE)
include("${OpenCV_SOURCE_DIR}/cmake/OpenCVFindLibRealsense.cmake")
endif(WITH_LIBREALSENSE)
# --- Intel Perceptual Computing SDK ---
if(WITH_INTELPERC)
include("${OpenCV_SOURCE_DIR}/cmake/OpenCVFindIntelPerCSDK.cmake")
......
......@@ -147,6 +147,9 @@
/* OpenNI library */
#cmakedefine HAVE_OPENNI2
/* librealsense library */
#cmakedefine HAVE_LIBREALSENSE
/* PNG codec */
#cmakedefine HAVE_PNG
......
......@@ -212,6 +212,12 @@ if(HAVE_INTELPERC)
list(APPEND VIDEOIO_LIBRARIES ${INTELPERC_LIBRARIES})
endif(HAVE_INTELPERC)
if(HAVE_LIBREALSENSE)
list(APPEND videoio_srcs ${CMAKE_CURRENT_LIST_DIR}/src/cap_librealsense.cpp)
ocv_include_directories(${LIBREALSENSE_INCLUDE_DIR})
list(APPEND VIDEOIO_LIBRARIES ${LIBREALSENSE_LIBRARIES})
endif(HAVE_LIBREALSENSE)
if(HAVE_GPHOTO2)
list(APPEND videoio_srcs ${CMAKE_CURRENT_LIST_DIR}/src/cap_gphoto2.cpp)
endif(HAVE_GPHOTO2)
......
......@@ -43,6 +43,7 @@
#include <iostream>
using namespace std;
#include "cap_intelperc.hpp"
#include "cap_librealsense.hpp"
#include "cap_dshow.hpp"
#ifdef HAVE_MFX
......@@ -481,6 +482,7 @@ static Ptr<IVideoCapture> IVideoCapture_create(int index)
#if defined(HAVE_GSTREAMER) || \
defined(HAVE_DSHOW) || \
defined(HAVE_INTELPERC) || \
defined(HAVE_LIBREALSENSE) || \
defined(WINRT_VIDEO) || \
defined(HAVE_GPHOTO2) || \
(0)
......@@ -502,6 +504,10 @@ static Ptr<IVideoCapture> IVideoCapture_create(int index)
case CAP_INTELPERC:
capture = makePtr<VideoCapture_IntelPerC>();
break; // CAP_INTEL_PERC
#elif defined(HAVE_LIBREALSENSE)
case CAP_INTELPERC:
capture = makePtr<VideoCapture_LibRealsense>(index);
break;
#endif
#ifdef WINRT_VIDEO
case CAP_WINRT:
......
// 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.
#include "precomp.hpp"
#ifdef HAVE_LIBREALSENSE
#include "cap_librealsense.hpp"
namespace cv
{
VideoCapture_LibRealsense::VideoCapture_LibRealsense(int index)
{
try
{
mDev = mContext.get_device(index);
// Configure all streams to run at VGA resolution at 60 frames per second
mDev->enable_stream(rs::stream::depth, 640, 480, rs::format::z16, 60);
mDev->enable_stream(rs::stream::color, 640, 480, rs::format::bgr8, 60);
mDev->enable_stream(rs::stream::infrared, 640, 480, rs::format::y8, 60);
mDev->start();
}
catch (rs::error&)
{
mDev = nullptr;
}
}
VideoCapture_LibRealsense::~VideoCapture_LibRealsense(){}
double VideoCapture_LibRealsense::getProperty(int prop) const
{
double propValue = 0;
if(prop == CAP_PROP_INTELPERC_DEPTH_SATURATION_VALUE)
return mDev->get_depth_scale();
return propValue;
}
bool VideoCapture_LibRealsense::setProperty(int, double)
{
bool isSet = false;
return isSet;
}
bool VideoCapture_LibRealsense::grabFrame()
{
if (!isOpened())
return false;
try
{
mDev->wait_for_frames();
}
catch (rs::error&)
{
return false;
}
return true;
}
bool VideoCapture_LibRealsense::retrieveFrame(int outputType, cv::OutputArray frame)
{
rs::stream stream;
int type;
switch (outputType)
{
case CAP_INTELPERC_DEPTH_MAP:
stream = rs::stream::depth_aligned_to_color;
type = CV_16UC1;
break;
case CAP_INTELPERC_IR_MAP:
stream = rs::stream::infrared;
type = CV_8UC1;
break;
case CAP_INTELPERC_IMAGE:
stream = rs::stream::color;
type = CV_8UC3;
break;
default:
return false;
}
try
{
// we copy the data straight away, so const_cast should be fine
void* data = const_cast<void*>(mDev->get_frame_data(stream));
Mat(mDev->get_stream_height(stream), mDev->get_stream_width(stream), type, data).copyTo(frame);
}
catch (rs::error&)
{
return false;
}
return true;
}
int VideoCapture_LibRealsense::getCaptureDomain()
{
return CAP_INTELPERC;
}
bool VideoCapture_LibRealsense::isOpened() const
{
return mDev && mDev->is_streaming();
}
}
#endif
// 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.
#ifndef _CAP_LIBREALSENE_HPP_
#define _CAP_LIBREALSENE_HPP_
#ifdef HAVE_LIBREALSENSE
#include <librealsense/rs.hpp>
namespace cv
{
class VideoCapture_LibRealsense : public IVideoCapture
{
public:
VideoCapture_LibRealsense(int index);
virtual ~VideoCapture_LibRealsense();
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:
rs::context mContext;
rs::device* mDev = nullptr;
};
}
#endif
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册