38 #include <opencv2/highgui/highgui.hpp> 39 #include <opencv2/imgproc/imgproc.hpp> 40 #include <opencv2/imgproc/types_c.h> 41 #if CV_MAJOR_VERSION >= 3 42 #include <opencv2/videoio/videoio_c.h> 44 #include <pcl/visualization/cloud_viewer.h> 51 "rtabmap-rgbd_camera [options] driver\n" 52 " driver Driver number to use: 0=OpenNI-PCL (Kinect)\n" 53 " 1=OpenNI2 (Kinect and Xtion PRO Live)\n" 54 " 2=Freenect (Kinect)\n" 55 " 3=OpenNI-CV (Kinect)\n" 56 " 4=OpenNI-CV-ASUS (Xtion PRO Live)\n" 57 " 5=Freenect2 (Kinect v2)\n" 58 " 6=DC1394 (Bumblebee2)\n" 59 " 7=FlyCapture2 (Bumblebee2)\n" 62 " 10=Kinect for Windows 2 SDK\n" 65 " -rate #.# Input rate Hz (default 0=inf)\n" 66 " -save_stereo \"path\" Save stereo images in a folder or a video file (side by side *.avi).\n" 67 " -fourcc \"XXXX\" Four characters FourCC code (default is \"MJPG\") used\n" 68 " when saving stereo images to a video file.\n" 69 " See http://www.fourcc.org/codecs.php for more codes.\n");
77 printf(
"\nSignal %d caught...\n", sig);
81 int main(
int argc,
char * argv[])
89 std::string stereoSavePath;
91 std::string fourcc =
"MJPG";
98 for(
int i=1; i<argc; ++i)
100 if(strcmp(argv[i],
"-rate") == 0)
117 if(strcmp(argv[i],
"-save_stereo") == 0)
122 stereoSavePath = argv[i];
130 if(strcmp(argv[i],
"-fourcc") == 0)
136 if(fourcc.size() != 4)
138 UERROR(
"fourcc should be 4 characters.");
148 if(strcmp(argv[i],
"--help") == 0 || strcmp(argv[i],
"-help") == 0)
154 printf(
"Unrecognized option \"%s\"", argv[i]);
159 driver = atoi(argv[i]);
160 if(driver < 0 || driver > 11)
162 UERROR(
"driver should be between 0 and 11.");
167 UINFO(
"Using driver %d", driver);
172 if(!stereoSavePath.empty())
174 UWARN(
"-save_stereo option cannot be used with RGB-D drivers.");
175 stereoSavePath.clear();
186 UERROR(
"Not built with OpenNI2 support...");
195 UERROR(
"Not built with Freenect support...");
204 UERROR(
"Not built with OpenNI from OpenCV support...");
213 UERROR(
"Not built with OpenNI from OpenCV support...");
222 UERROR(
"Not built with Freenect2 support...");
232 UERROR(
"Not built with DC1394 support...");
241 UERROR(
"Not built with FlyCapture2/Triclops support...");
250 UERROR(
"Not built with ZED sdk support...");
255 else if (driver == 9)
259 UERROR(
"Not built with RealSense support...");
264 else if (driver == 10)
268 UERROR(
"Not built with Kinect for Windows 2 SDK support...");
273 else if (driver == 11)
277 UERROR(
"Not built with RealSense2 SDK support...");
289 printf(
"Camera init failed! Please select another driver (see \"--help\").\n");
297 printf(
"Cloud not get frame from the camera!\n");
303 UWARN(
"RGB (%d/%d) and depth (%d/%d) frames are not the same size! The registered cloud cannot be shown.",
306 pcl::visualization::CloudViewer * viewer = 0;
309 UWARN(
"Camera not calibrated! The registered cloud cannot be shown.");
313 viewer =
new pcl::visualization::CloudViewer(
"cloud");
319 cv::VideoWriter videoWriter;
321 if(!stereoSavePath.empty() &&
331 UERROR(
"You should set the input rate when saving stereo images to a video file.");
334 cv::Size targetSize = data.
imageRaw().size();
335 targetSize.width *= 2;
339 CV_FOURCC(fourcc.at(0), fourcc.at(1), fourcc.at(2), fourcc.at(3)),
346 UERROR(
"Images not the same size, cannot save stereo images to the video file.");
356 UERROR(
"Directory \"%s\" doesn't exist.", stereoSavePath.c_str());
357 stereoSavePath.clear();
367 while(!data.
imageRaw().empty() && (viewer==0 || !viewer->wasStopped()) &&
running)
374 if(depth.type() == CV_32FC1)
379 if(!rgb.empty() && rgb.cols % depth.cols == 0 && rgb.rows % depth.rows == 0 &&
388 viewer->showCloud(cloud,
"cloud");
390 else if(!depth.empty() &&
398 viewer->showCloud(cloud,
"cloud");
402 unsigned short min=0,
max = 2048;
403 uMinMax((
unsigned short*)depth.data, depth.rows*depth.cols, min,
max);
404 depth.convertTo(tmp, CV_8UC1, 255.0/
max);
406 cv::imshow(
"Video", rgb);
407 cv::imshow(
"Depth", tmp);
413 cv::imshow(
"Left", rgb);
414 cv::imshow(
"Right", right);
418 if(right.channels() == 3)
420 cv::cvtColor(right, right, CV_BGR2GRAY);
427 viewer->showCloud(cloud,
"cloud");
431 int c = cv::waitKey(10);
435 if(videoWriter.isOpened())
439 if(left.size() == right.size())
441 cv::Size targetSize = left.size();
442 targetSize.width *= 2;
443 cv::Mat targetImage(targetSize, left.type());
444 if(right.type() != left.type())
447 cv::cvtColor(right, tmp, left.channels()==3?CV_GRAY2BGR:CV_BGR2GRAY);
450 UASSERT(left.type() == right.type());
452 cv::Mat roiA(targetImage, cv::Rect( 0, 0, left.size().width, left.size().height ));
454 cv::Mat roiB( targetImage, cvRect( left.size().width, 0, left.size().width, left.size().height ) );
457 videoWriter.write(targetImage);
458 printf(
"Saved frame %d to \"%s\"\n",
id, stereoSavePath.c_str());
462 UERROR(
"Left and right images are not the same size!?");
465 else if(!stereoSavePath.empty())
469 printf(
"Saved frames %d to \"%s/left\" and \"%s/right\" directories\n",
id, stereoSavePath.c_str(), stereoSavePath.c_str());
474 printf(
"Closing...\n");
479 cv::destroyWindow(
"Video");
480 cv::destroyWindow(
"Depth");
static bool makeDir(const std::string &dirPath)
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP transformPointCloud(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const Transform &transform)
void uMinMax(const T *v, unsigned int size, T &min, T &max, unsigned int &indexMin, unsigned int &indexMax)
float UTILITE_EXP uStr2Float(const std::string &str)
Basic mathematics functions.
Some conversion functions.
std::string getExtension()
const cv::Mat & imageRaw() const
static void setLevel(ULogger::Level level)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP cloudFromDepth(const cv::Mat &imageDepth, const CameraModel &model, int decimation=1, float maxDepth=0.0f, float minDepth=0.0f, std::vector< int > *validIndices=0)
pcl::PointCloud< pcl::PointXYZRGB >::Ptr RTABMAP_EXP cloudFromDepthRGB(const cv::Mat &imageRgb, const cv::Mat &imageDepth, const CameraModel &model, int decimation=1, float maxDepth=0.0f, float minDepth=0.0f, std::vector< int > *validIndices=0)
virtual bool init(const std::string &calibrationFolder=".", const std::string &cameraName="")=0
#define UASSERT(condition)
SensorData takeImage(CameraInfo *info=0)
bool isValidForProjection() const
int main(int argc, char *argv[])
static void setType(Type type, const std::string &fileName=kDefaultLogFileName, bool append=true)
const cv::Mat & depthOrRightRaw() const
const std::vector< CameraModel > & cameraModels() const
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
ULogger class and convenient macros.
const StereoCameraModel & stereoCameraModel() const
static bool exists(const std::string &dirPath)
cv::Mat RTABMAP_EXP cvtDepthFromFloat(const cv::Mat &depth32F)
pcl::PointCloud< pcl::PointXYZRGB >::Ptr RTABMAP_EXP cloudFromStereoImages(const cv::Mat &imageLeft, const cv::Mat &imageRight, const StereoCameraModel &model, int decimation=1, float maxDepth=0.0f, float minDepth=0.0f, std::vector< int > *validIndices=0, const ParametersMap ¶meters=ParametersMap())
std::string UTILITE_EXP uNumber2Str(unsigned int number)