it is reusing CAP_INTELPERC* enums as Intel PerC is deprecated and librealsense replaces it.pull/11532/head
parent
cd2b188c9a
commit
936d2963a2
8 changed files with 181 additions and 0 deletions
@ -0,0 +1,15 @@ |
||||
# 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) |
@ -0,0 +1,109 @@ |
||||
// 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 |
@ -0,0 +1,36 @@ |
||||
// 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 |
Loading…
Reference in new issue