mirror of
https://github.com/introlab/rtabmap_ros.git
synced 2026-10-03 16:27:46 +08:00
Fixed build if PCL is not built with OpenNI
This commit is contained in:
@@ -72,7 +72,7 @@ class RTABMAP_EXP CameraOpenni :
|
|||||||
public Camera
|
public Camera
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static bool available() {return true;}
|
static bool available();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// default local transform z in, x right, y down));
|
// default local transform z in, x right, y down));
|
||||||
@@ -80,11 +80,12 @@ public:
|
|||||||
float imageRate = 0,
|
float imageRate = 0,
|
||||||
const Transform & localTransform = Transform::getIdentity());
|
const Transform & localTransform = Transform::getIdentity());
|
||||||
virtual ~CameraOpenni();
|
virtual ~CameraOpenni();
|
||||||
|
#ifdef HAVE_OPENNI
|
||||||
void image_cb (
|
void image_cb (
|
||||||
const boost::shared_ptr<openni_wrapper::Image>& rgb,
|
const boost::shared_ptr<openni_wrapper::Image>& rgb,
|
||||||
const boost::shared_ptr<openni_wrapper::DepthImage>& depth,
|
const boost::shared_ptr<openni_wrapper::DepthImage>& depth,
|
||||||
float constant);
|
float constant);
|
||||||
|
#endif
|
||||||
|
|
||||||
virtual bool init(const std::string & calibrationFolder = ".", const std::string & cameraName = "");
|
virtual bool init(const std::string & calibrationFolder = ".", const std::string & cameraName = "");
|
||||||
virtual bool isCalibrated() const;
|
virtual bool isCalibrated() const;
|
||||||
|
|||||||
@@ -38,8 +38,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <rtabmap/utilite/UTimer.h>
|
#include <rtabmap/utilite/UTimer.h>
|
||||||
#include <rtabmap/utilite/UMath.h>
|
#include <rtabmap/utilite/UMath.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_OPENNI
|
||||||
#include <pcl/io/openni_grabber.h>
|
#include <pcl/io/openni_grabber.h>
|
||||||
#include <pcl/io/oni_grabber.h>
|
#include <pcl/io/oni_grabber.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_FREENECT
|
#ifdef WITH_FREENECT
|
||||||
#include <libfreenect.h>
|
#include <libfreenect.h>
|
||||||
@@ -86,8 +88,18 @@ CameraOpenni::CameraOpenni(const std::string & deviceId, float imageRate, const
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CameraOpenni::available()
|
||||||
|
{
|
||||||
|
#ifdef HAVE_OPENNI
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
CameraOpenni::~CameraOpenni()
|
CameraOpenni::~CameraOpenni()
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_OPENNI
|
||||||
UDEBUG("");
|
UDEBUG("");
|
||||||
if(connection_.connected())
|
if(connection_.connected())
|
||||||
{
|
{
|
||||||
@@ -101,8 +113,9 @@ CameraOpenni::~CameraOpenni()
|
|||||||
delete interface_;
|
delete interface_;
|
||||||
interface_ = 0;
|
interface_ = 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
#ifdef HAVE_OPENNI
|
||||||
void CameraOpenni::image_cb (
|
void CameraOpenni::image_cb (
|
||||||
const boost::shared_ptr<openni_wrapper::Image>& rgb,
|
const boost::shared_ptr<openni_wrapper::Image>& rgb,
|
||||||
const boost::shared_ptr<openni_wrapper::DepthImage>& depth,
|
const boost::shared_ptr<openni_wrapper::DepthImage>& depth,
|
||||||
@@ -126,9 +139,11 @@ void CameraOpenni::image_cb (
|
|||||||
dataReady_.release();
|
dataReady_.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool CameraOpenni::init(const std::string & calibrationFolder, const std::string & cameraName)
|
bool CameraOpenni::init(const std::string & calibrationFolder, const std::string & cameraName)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_OPENNI
|
||||||
if(interface_)
|
if(interface_)
|
||||||
{
|
{
|
||||||
interface_->stop();
|
interface_->stop();
|
||||||
@@ -167,25 +182,36 @@ bool CameraOpenni::init(const std::string & calibrationFolder, const std::string
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
#else
|
||||||
|
UERROR("PCL not built with OpenNI! Cannot initialize CameraOpenNI");
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CameraOpenni::isCalibrated() const
|
bool CameraOpenni::isCalibrated() const
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_OPENNI
|
||||||
return true;
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CameraOpenni::getSerial() const
|
std::string CameraOpenni::getSerial() const
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_OPENNI
|
||||||
if(interface_)
|
if(interface_)
|
||||||
{
|
{
|
||||||
return interface_->getName();
|
return interface_->getName();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
SensorData CameraOpenni::captureImage()
|
SensorData CameraOpenni::captureImage()
|
||||||
{
|
{
|
||||||
SensorData data;
|
SensorData data;
|
||||||
|
#ifdef HAVE_OPENNI
|
||||||
if(interface_ && interface_->isRunning())
|
if(interface_ && interface_->isRunning())
|
||||||
{
|
{
|
||||||
if(!dataReady_.acquire(1, 2000))
|
if(!dataReady_.acquire(1, 2000))
|
||||||
@@ -211,6 +237,9 @@ SensorData CameraOpenni::captureImage()
|
|||||||
depthConstant_ = 0.0f;
|
depthConstant_ = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
UERROR("CameraOpenNI: RTAB-Map is not built with PCL having OpenNI support!");
|
||||||
|
#endif
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1289,7 +1318,7 @@ SensorData CameraFreenect2::captureImage()
|
|||||||
float fx=0,fy=0,cx=0,cy=0;
|
float fx=0,fy=0,cx=0,cy=0;
|
||||||
if(irFrame && depthFrame)
|
if(irFrame && depthFrame)
|
||||||
{
|
{
|
||||||
cv::Mat irMat(irFrame->height, irFrame->width, CV_32FC1, irFrame->data);
|
cv::Mat irMat((int)irFrame->height, (int)irFrame->width, CV_32FC1, irFrame->data);
|
||||||
//convert to gray scaled
|
//convert to gray scaled
|
||||||
float maxIr_ = 0x7FFF;
|
float maxIr_ = 0x7FFF;
|
||||||
float minIr_ = 0x0;
|
float minIr_ = 0x0;
|
||||||
@@ -1303,7 +1332,7 @@ SensorData CameraFreenect2::captureImage()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cv::Mat(depthFrame->height, depthFrame->width, CV_32FC1, depthFrame->data).convertTo(depth, CV_16U, 1);
|
cv::Mat((int)depthFrame->height, (int)depthFrame->width, CV_32FC1, depthFrame->data).convertTo(depth, CV_16U, 1);
|
||||||
|
|
||||||
cv::flip(rgb, rgb, 1);
|
cv::flip(rgb, rgb, 1);
|
||||||
cv::flip(depth, depth, 1);
|
cv::flip(depth, depth, 1);
|
||||||
@@ -1331,7 +1360,7 @@ SensorData CameraFreenect2::captureImage()
|
|||||||
{
|
{
|
||||||
//rgb + ir or rgb + depth
|
//rgb + ir or rgb + depth
|
||||||
|
|
||||||
cv::Mat rgbMatC4(rgbFrame->height, rgbFrame->width, CV_8UC4, rgbFrame->data);
|
cv::Mat rgbMatC4((int)rgbFrame->height, (int)rgbFrame->width, CV_8UC4, rgbFrame->data);
|
||||||
cv::Mat rgbMat; // rtabmap uses 3 channels RGB
|
cv::Mat rgbMat; // rtabmap uses 3 channels RGB
|
||||||
cv::cvtColor(rgbMatC4, rgbMat, CV_BGRA2BGR);
|
cv::cvtColor(rgbMatC4, rgbMat, CV_BGRA2BGR);
|
||||||
cv::flip(rgbMat, rgb, 1);
|
cv::flip(rgbMat, rgb, 1);
|
||||||
@@ -1343,14 +1372,14 @@ SensorData CameraFreenect2::captureImage()
|
|||||||
if(irFrame)
|
if(irFrame)
|
||||||
{
|
{
|
||||||
//rectify IR
|
//rectify IR
|
||||||
cv::Mat(irFrame->height, irFrame->width, CV_32FC1, irFrame->data).convertTo(depth, CV_16U, 1);
|
cv::Mat((int)irFrame->height, (int)irFrame->width, CV_32FC1, irFrame->data).convertTo(depth, CV_16U, 1);
|
||||||
cv::flip(depth, depth, 1);
|
cv::flip(depth, depth, 1);
|
||||||
depth = stereoModel_.left().rectifyImage(depth);
|
depth = stereoModel_.left().rectifyImage(depth);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//rectify depth
|
//rectify depth
|
||||||
cv::Mat(depthFrame->height, depthFrame->width, CV_32FC1, depthFrame->data).convertTo(depth, CV_16U, 1);
|
cv::Mat((int)depthFrame->height, (int)depthFrame->width, CV_32FC1, depthFrame->data).convertTo(depth, CV_16U, 1);
|
||||||
cv::flip(depth, depth, 1);
|
cv::flip(depth, depth, 1);
|
||||||
depth = stereoModel_.left().rectifyDepth(depth);
|
depth = stereoModel_.left().rectifyDepth(depth);
|
||||||
|
|
||||||
@@ -1382,11 +1411,11 @@ SensorData CameraFreenect2::captureImage()
|
|||||||
//use data from libfreenect2
|
//use data from libfreenect2
|
||||||
if(irFrame)
|
if(irFrame)
|
||||||
{
|
{
|
||||||
cv::Mat(irFrame->height, irFrame->width, CV_32FC1, irFrame->data).convertTo(depth, CV_16U, 1);
|
cv::Mat((int)irFrame->height, (int)irFrame->width, CV_32FC1, irFrame->data).convertTo(depth, CV_16U, 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cv::Mat(depthFrame->height, depthFrame->width, CV_32FC1, depthFrame->data).convertTo(depth, CV_16U, 1);
|
cv::Mat((int)depthFrame->height, (int)depthFrame->width, CV_32FC1, depthFrame->data).convertTo(depth, CV_16U, 1);
|
||||||
|
|
||||||
//registration of the depth
|
//registration of the depth
|
||||||
if(reg_)
|
if(reg_)
|
||||||
@@ -1397,7 +1426,7 @@ SensorData CameraFreenect2::captureImage()
|
|||||||
cv::resize(rgb, tmp, cv::Size(), 0.5, 0.5, cv::INTER_AREA);
|
cv::resize(rgb, tmp, cv::Size(), 0.5, 0.5, cv::INTER_AREA);
|
||||||
rgb = tmp;
|
rgb = tmp;
|
||||||
}
|
}
|
||||||
cv::Mat depthFrameMat = cv::Mat(depthFrame->height, depthFrame->width, CV_32FC1, depthFrame->data);
|
cv::Mat depthFrameMat = cv::Mat((int)depthFrame->height, (int)depthFrame->width, CV_32FC1, depthFrame->data);
|
||||||
depth = cv::Mat::zeros(rgb.rows, rgb.cols, CV_16U);
|
depth = cv::Mat::zeros(rgb.rows, rgb.cols, CV_16U);
|
||||||
for(int dx=0; dx<depthFrameMat.cols-1; ++dx)
|
for(int dx=0; dx<depthFrameMat.cols-1; ++dx)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -175,6 +175,10 @@ PreferencesDialog::PreferencesDialog(QWidget * parent) :
|
|||||||
{
|
{
|
||||||
_ui->graphOptimization_type->setItemData(1, 0, Qt::UserRole - 1);
|
_ui->graphOptimization_type->setItemData(1, 0, Qt::UserRole - 1);
|
||||||
}
|
}
|
||||||
|
if(!CameraOpenni::available())
|
||||||
|
{
|
||||||
|
_ui->comboBox_cameraRGBD->setItemData(0, 0, Qt::UserRole - 1);
|
||||||
|
}
|
||||||
if(!CameraFreenect::available())
|
if(!CameraFreenect::available())
|
||||||
{
|
{
|
||||||
_ui->comboBox_cameraRGBD->setItemData(1, 0, Qt::UserRole - 1);
|
_ui->comboBox_cameraRGBD->setItemData(1, 0, Qt::UserRole - 1);
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ int main(int argc, char * argv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
camera = new rtabmap::CameraVideo(path, rate);
|
camera = new rtabmap::CameraVideo(path, false, rate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(UDirectory::exists(path))
|
else if(UDirectory::exists(path))
|
||||||
|
|||||||
@@ -302,11 +302,11 @@ int main(int argc, char * argv[])
|
|||||||
Camera * camera = 0;
|
Camera * camera = 0;
|
||||||
if(UDirectory::exists(path))
|
if(UDirectory::exists(path))
|
||||||
{
|
{
|
||||||
camera = new CameraImages(path, startAt, false, false, 1/rate);
|
camera = new CameraImages(path, startAt, false, false, 1.0f/rate);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
camera = new CameraVideo(path, 1/rate);
|
camera = new CameraVideo(path, false, 1.0f/rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!camera || !camera->init())
|
if(!camera || !camera->init())
|
||||||
|
|||||||
Reference in New Issue
Block a user