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" 64 " 12=Kinect for Azure SDK\n" 67 " -rate #.# Input rate Hz (default 0=inf)\n" 68 " -device # Device ID (number or string)\n" 69 " -save_stereo \"path\" Save stereo images in a folder or a video file (side by side *.avi).\n" 70 " -fourcc \"XXXX\" Four characters FourCC code (default is \"MJPG\") used\n" 71 " when saving stereo images to a video file.\n" 72 " See http://www.fourcc.org/codecs.php for more codes.\n");
80 printf(
"\nSignal %d caught...\n", sig);
92 std::string stereoSavePath;
94 std::string fourcc =
"MJPG";
102 for(
int i=1; i<argc; ++i)
104 if(strcmp(argv[i],
"-rate") == 0)
121 if (strcmp(argv[i],
"-device") == 0)
134 if(strcmp(argv[i],
"-save_stereo") == 0)
139 stereoSavePath = argv[i];
147 if(strcmp(argv[i],
"-fourcc") == 0)
153 if(fourcc.size() != 4)
155 UERROR(
"fourcc should be 4 characters.");
165 if(strcmp(argv[i],
"--help") == 0 || strcmp(argv[i],
"-help") == 0)
171 printf(
"Unrecognized option \"%s\"", argv[i]);
176 driver = atoi(argv[i]);
177 if(driver < 0 || driver > 13)
179 UERROR(
"driver should be between 0 and 13.");
184 UINFO(
"Using driver %d (device=%s)", driver, deviceId.empty()?
"0": deviceId.c_str());
189 if(!stereoSavePath.empty())
191 UWARN(
"-save_stereo option cannot be used with RGB-D drivers.");
192 stereoSavePath.clear();
203 UERROR(
"Not built with OpenNI2 support...");
212 UERROR(
"Not built with Freenect support...");
221 UERROR(
"Not built with OpenNI from OpenCV support...");
230 UERROR(
"Not built with OpenNI from OpenCV support...");
239 UERROR(
"Not built with Freenect2 support...");
249 UERROR(
"Not built with DC1394 support...");
258 UERROR(
"Not built with FlyCapture2/Triclops support...");
267 UERROR(
"Not built with ZED sdk support...");
272 else if (driver == 9)
276 UERROR(
"Not built with RealSense support...");
281 else if (driver == 10)
285 UERROR(
"Not built with Kinect for Windows 2 SDK support...");
290 else if (driver == 11)
294 UERROR(
"Not built with RealSense2 SDK support...");
299 else if (driver == 12)
303 UERROR(
"Not built with Kinect for Azure SDK support...");
308 else if (driver == 13)
312 UERROR(
"Not built with Mynt Eye S support...");
324 printf(
"Camera init failed! Please select another driver (see \"--help\").\n");
332 printf(
"Cloud not get frame from the camera!\n");
338 UWARN(
"RGB (%d/%d) and depth (%d/%d) frames are not the same size! The registered cloud cannot be shown.",
341 pcl::visualization::CloudViewer * viewer = 0;
344 UWARN(
"Camera not calibrated! The registered cloud cannot be shown.");
348 viewer =
new pcl::visualization::CloudViewer(
"cloud");
351 cv::VideoWriter videoWriter;
353 if(!stereoSavePath.empty() &&
363 UERROR(
"You should set the input rate when saving stereo images to a video file.");
366 cv::Size targetSize = data.
imageRaw().size();
367 targetSize.width *= 2;
371 CV_FOURCC(fourcc.at(0), fourcc.at(1), fourcc.at(2), fourcc.at(3)),
378 UERROR(
"Images not the same size, cannot save stereo images to the video file.");
388 UERROR(
"Directory \"%s\" doesn't exist.", stereoSavePath.c_str());
389 stereoSavePath.clear();
399 while(!data.
imageRaw().empty() && (viewer==0 || !viewer->wasStopped()) &&
running)
406 if(depth.type() == CV_32FC1)
411 if(!rgb.empty() && rgb.cols % depth.cols == 0 && rgb.rows % depth.rows == 0 &&
420 viewer->showCloud(cloud,
"cloud");
422 else if(!depth.empty() &&
430 viewer->showCloud(cloud,
"cloud");
434 unsigned short min=0,
max = 2048;
435 uMinMax((
unsigned short*)depth.data, depth.rows*depth.cols, min,
max);
436 depth.convertTo(tmp, CV_8UC1, 255.0/
max);
438 cv::imshow(
"Video", rgb);
439 cv::imshow(
"Depth", tmp);
445 cv::imshow(
"Left", rgb);
446 cv::imshow(
"Right", right);
450 if(right.channels() == 3)
452 cv::cvtColor(right, right, CV_BGR2GRAY);
459 viewer->showCloud(cloud,
"cloud");
463 int c = cv::waitKey(10);
467 if(videoWriter.isOpened())
471 if(left.size() == right.size())
473 cv::Size targetSize = left.size();
474 targetSize.width *= 2;
475 cv::Mat targetImage(targetSize, left.type());
476 if(right.type() != left.type())
479 cv::cvtColor(right, tmp, left.channels()==3?CV_GRAY2BGR:CV_BGR2GRAY);
482 UASSERT(left.type() == right.type());
484 cv::Mat roiA(targetImage, cv::Rect( 0, 0, left.size().width, left.size().height ));
486 cv::Mat roiB( targetImage, cvRect( left.size().width, 0, left.size().width, left.size().height ) );
489 videoWriter.write(targetImage);
490 printf(
"Saved frame %d to \"%s\"\n",
id, stereoSavePath.c_str());
494 UERROR(
"Left and right images are not the same size!?");
497 else if(!stereoSavePath.empty())
501 printf(
"Saved frames %d to \"%s/left\" and \"%s/right\" directories\n",
id, stereoSavePath.c_str(), stereoSavePath.c_str());
504 data = camera->takeImage();
506 printf(
"Closing...\n");
511 cv::destroyWindow(
"Video");
512 cv::destroyWindow(
"Depth");
int UTILITE_EXP uStr2Int(const std::string &str)
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)
#define UASSERT(condition)
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())
const Transform & localTransform() const
std::string UTILITE_EXP uNumber2Str(unsigned int number)