CameraOpenNICV.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
19 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 
28 #include <rtabmap/utilite/UTimer.h>
29 #if CV_MAJOR_VERSION > 3
30 #include <opencv2/videoio/videoio_c.h>
31 #endif
32 
33 namespace rtabmap
34 {
35 
37 {
38  return cv::getBuildInformation().find("OpenNI: YES") != std::string::npos;
39 }
40 
41 CameraOpenNICV::CameraOpenNICV(bool asus, float imageRate, const rtabmap::Transform & localTransform) :
42  Camera(imageRate, localTransform),
43  _asus(asus),
44  _depthFocal(0.0f)
45 {
46 
47 }
48 
50 {
51  _capture.release();
52 }
53 
54 bool CameraOpenNICV::init(const std::string & calibrationFolder, const std::string & cameraName)
55 {
56  if(_capture.isOpened())
57  {
58  _capture.release();
59  }
60 
61  ULOGGER_DEBUG("Camera::init()");
62  _capture.open( _asus?CV_CAP_OPENNI_ASUS:CV_CAP_OPENNI );
63  if(_capture.isOpened())
64  {
65  _capture.set( CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE, CV_CAP_OPENNI_VGA_30HZ );
66  _depthFocal = _capture.get( CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH );
67  // Print some avalible device settings.
68  UINFO("Depth generator output mode:");
69  UINFO("FRAME_WIDTH %f", _capture.get( CV_CAP_PROP_FRAME_WIDTH ));
70  UINFO("FRAME_HEIGHT %f", _capture.get( CV_CAP_PROP_FRAME_HEIGHT ));
71  UINFO("FRAME_MAX_DEPTH %f mm", _capture.get( CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH ));
72  UINFO("BASELINE %f mm", _capture.get( CV_CAP_PROP_OPENNI_BASELINE ));
73  UINFO("FPS %f", _capture.get( CV_CAP_PROP_FPS ));
74  UINFO("Focal %f", _capture.get( CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH ));
75  UINFO("REGISTRATION %f", _capture.get( CV_CAP_PROP_OPENNI_REGISTRATION ));
76  if(_capture.get( CV_CAP_PROP_OPENNI_REGISTRATION ) == 0.0)
77  {
78  UERROR("Depth registration is not activated on this device!");
79  }
80  if( _capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR_PRESENT ) )
81  {
82  UINFO("Image generator output mode:");
83  UINFO("FRAME_WIDTH %f", _capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FRAME_WIDTH ));
84  UINFO("FRAME_HEIGHT %f", _capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FRAME_HEIGHT ));
85  UINFO("FPS %f", _capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FPS ));
86  }
87  else
88  {
89  UERROR("Camera: Device doesn't contain image generator.");
90  _capture.release();
91  return false;
92  }
93  }
94  else
95  {
96  ULOGGER_ERROR("Camera: Failed to create a capture object!");
97  _capture.release();
98  return false;
99  }
100  return true;
101 }
102 
104 {
105  return true;
106 }
107 
109 {
111  if(_capture.isOpened())
112  {
113  _capture.grab();
114  cv::Mat depth, rgb;
115  _capture.retrieve(depth, CV_CAP_OPENNI_DEPTH_MAP );
116  _capture.retrieve(rgb, CV_CAP_OPENNI_BGR_IMAGE );
117 
118  depth = depth.clone();
119  rgb = rgb.clone();
120 
121  UASSERT(_depthFocal>0.0f);
122  if(!rgb.empty() && !depth.empty())
123  {
125  _depthFocal, //fx
126  _depthFocal, //fy
127  float(rgb.cols/2) - 0.5f, //cx
128  float(rgb.rows/2) - 0.5f, //cy
129  this->getLocalTransform(),
130  0,
131  rgb.size());
132  data = SensorData(rgb, depth, model, this->getNextSeqID(), UTimer::now());
133  }
134  }
135  else
136  {
137  ULOGGER_WARN("The camera must be initialized before requesting an image.");
138  }
139  return data;
140 }
141 
142 } // namespace rtabmap
rtabmap::SensorData
Definition: SensorData.h:51
rtabmap::CameraOpenNICV::CameraOpenNICV
CameraOpenNICV(bool asus=false, float imageRate=0, const Transform &localTransform=Transform::getIdentity())
Definition: CameraOpenNICV.cpp:41
UINFO
#define UINFO(...)
UTimer::now
static double now()
Definition: UTimer.cpp:80
this
this
rtabmap::CameraModel
Definition: CameraModel.h:38
rtabmap::CameraOpenNICV::captureImage
virtual SensorData captureImage(SensorCaptureInfo *info=0)
Definition: CameraOpenNICV.cpp:108
rtabmap::CameraOpenNICV::isCalibrated
virtual bool isCalibrated() const
Definition: CameraOpenNICV.cpp:103
UTimer.h
ULOGGER_DEBUG
#define ULOGGER_DEBUG(...)
Definition: ULogger.h:53
rtabmap::SensorCaptureInfo
Definition: SensorCaptureInfo.h:36
data
int data[]
rtabmap::CameraOpenNICV::_depthFocal
float _depthFocal
Definition: CameraOpenNICV.h:59
rtabmap::CameraOpenNICV::_asus
bool _asus
Definition: CameraOpenNICV.h:57
UASSERT
#define UASSERT(condition)
rtabmap::CameraOpenNICV::~CameraOpenNICV
virtual ~CameraOpenNICV()
Definition: CameraOpenNICV.cpp:49
rtabmap::Camera
Definition: Camera.h:43
f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
CameraOpenNICV.h
rtabmap::Transform
Definition: Transform.h:41
rtabmap::CameraOpenNICV::available
static bool available()
Definition: CameraOpenNICV.cpp:36
ULOGGER_ERROR
#define ULOGGER_ERROR(...)
Definition: ULogger.h:56
rtabmap
Definition: CameraARCore.cpp:35
UERROR
#define UERROR(...)
trace.model
model
Definition: trace.py:4
rtabmap::CameraOpenNICV::_capture
cv::VideoCapture _capture
Definition: CameraOpenNICV.h:58
ULOGGER_WARN
#define ULOGGER_WARN(...)
Definition: ULogger.h:55
rtabmap::SensorCapture::getNextSeqID
int getNextSeqID()
Definition: SensorCapture.h:83
rtabmap::CameraOpenNICV::init
virtual bool init(const std::string &calibrationFolder=".", const std::string &cameraName="")
Definition: CameraOpenNICV.cpp:54


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:07