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" 66 " 14=ZED Open Capture\n" 69 " -rate #.# Input rate Hz (default 0=inf)\n" 70 " -device # Device ID (number or string)\n" 71 " -save_stereo \"path\" Save stereo images in a folder or a video file (side by side *.avi).\n" 72 " -fourcc \"XXXX\" Four characters FourCC code (default is \"MJPG\") used\n" 73 " when saving stereo images to a video file.\n" 74 " See http://www.fourcc.org/codecs.php for more codes.\n");
82 printf(
"\nSignal %d caught...\n", sig);
94 std::string stereoSavePath;
96 std::string fourcc =
"MJPG";
104 for(
int i=1; i<argc; ++i)
106 if(strcmp(argv[i],
"-rate") == 0)
123 if (strcmp(argv[i],
"-device") == 0)
136 if(strcmp(argv[i],
"-save_stereo") == 0)
141 stereoSavePath = argv[i];
149 if(strcmp(argv[i],
"-fourcc") == 0)
155 if(fourcc.size() != 4)
157 UERROR(
"fourcc should be 4 characters.");
167 if(strcmp(argv[i],
"--help") == 0 || strcmp(argv[i],
"-help") == 0)
173 printf(
"Unrecognized option \"%s\"", argv[i]);
178 driver = atoi(argv[i]);
179 if(driver < 0 || driver > 15)
181 UERROR(
"driver should be between 0 and 15.");
186 UINFO(
"Using driver %d (device=%s)", driver, deviceId.empty()?
"0": deviceId.c_str());
191 if(!stereoSavePath.empty())
193 UWARN(
"-save_stereo option cannot be used with RGB-D drivers.");
194 stereoSavePath.clear();
205 UERROR(
"Not built with OpenNI2 support...");
214 UERROR(
"Not built with Freenect support...");
223 UERROR(
"Not built with OpenNI from OpenCV support...");
232 UERROR(
"Not built with OpenNI from OpenCV support...");
241 UERROR(
"Not built with Freenect2 support...");
251 UERROR(
"Not built with DC1394 support...");
260 UERROR(
"Not built with FlyCapture2/Triclops support...");
269 UERROR(
"Not built with ZED sdk support...");
274 else if (driver == 9)
278 UERROR(
"Not built with RealSense support...");
283 else if (driver == 10)
287 UERROR(
"Not built with Kinect for Windows 2 SDK support...");
292 else if (driver == 11)
296 UERROR(
"Not built with RealSense2 SDK support...");
301 else if (driver == 12)
305 UERROR(
"Not built with Kinect for Azure SDK support...");
310 else if (driver == 13)
314 UERROR(
"Not built with Mynt Eye S support...");
319 else if (driver == 14)
323 UERROR(
"Not built with Zed Open Capture support...");
328 else if (driver == 15)
332 UERROR(
"Not built with depthai-core support...");
344 printf(
"Camera init failed! Please select another driver (see \"--help\").\n");
352 printf(
"Cloud not get frame from the camera!\n");
358 UWARN(
"RGB (%d/%d) and depth (%d/%d) frames are not the same size! The registered cloud cannot be shown.",
361 pcl::visualization::CloudViewer * viewer = 0;
365 UWARN(
"Camera not calibrated! The registered cloud cannot be shown.");
369 viewer =
new pcl::visualization::CloudViewer(
"cloud");
372 cv::VideoWriter videoWriter;
374 if(!stereoSavePath.empty() &&
384 UERROR(
"You should set the input rate when saving stereo images to a video file.");
387 cv::Size targetSize = data.
imageRaw().size();
388 targetSize.width *= 2;
392 CV_FOURCC(fourcc.at(0), fourcc.at(1), fourcc.at(2), fourcc.at(3)),
399 UERROR(
"Images not the same size, cannot save stereo images to the video file.");
409 UERROR(
"Directory \"%s\" doesn't exist.", stereoSavePath.c_str());
410 stereoSavePath.clear();
420 while(!data.
imageRaw().empty() && (viewer==0 || !viewer->wasStopped()) &&
running)
427 if(depth.type() == CV_32FC1)
432 if(!rgb.empty() && rgb.cols % depth.cols == 0 && rgb.rows % depth.rows == 0 &&
441 viewer->showCloud(cloud,
"cloud");
443 else if(!depth.empty() &&
451 viewer->showCloud(cloud,
"cloud");
455 unsigned short min=0,
max = 2048;
456 uMinMax((
unsigned short*)depth.data, depth.rows*depth.cols, min,
max);
457 depth.convertTo(tmp, CV_8UC1, 255.0/
max);
459 cv::imshow(
"Video", rgb);
460 cv::imshow(
"Depth", tmp);
466 cv::imshow(
"Left", rgb);
467 cv::imshow(
"Right", right);
471 if(right.channels() == 3)
473 cv::cvtColor(right, right, CV_BGR2GRAY);
480 viewer->showCloud(cloud,
"cloud");
484 int c = cv::waitKey(10);
488 if(videoWriter.isOpened())
492 if(left.size() == right.size())
494 cv::Size targetSize = left.size();
495 targetSize.width *= 2;
496 cv::Mat targetImage(targetSize, left.type());
497 if(right.type() != left.type())
500 cv::cvtColor(right, tmp, left.channels()==3?CV_GRAY2BGR:CV_BGR2GRAY);
503 UASSERT(left.type() == right.type());
505 cv::Mat roiA(targetImage, cv::Rect( 0, 0, left.size().width, left.size().height ));
507 cv::Mat roiB( targetImage, cvRect( left.size().width, 0, left.size().width, left.size().height ) );
510 videoWriter.write(targetImage);
511 printf(
"Saved frame %d to \"%s\"\n",
id, stereoSavePath.c_str());
515 UERROR(
"Left and right images are not the same size!?");
518 else if(!stereoSavePath.empty())
522 printf(
"Saved frames %d to \"%s/left\" and \"%s/right\" directories\n",
id, stereoSavePath.c_str(), stereoSavePath.c_str());
525 data = camera->takeImage();
527 printf(
"Closing...\n");
532 cv::destroyWindow(
"Video");
533 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)
const cv::Mat & depthOrRightRaw() const
float UTILITE_EXP uStr2Float(const std::string &str)
const std::vector< StereoCameraModel > & stereoCameraModels() const
Basic mathematics functions.
Some conversion functions.
std::string getExtension()
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)
const std::vector< CameraModel > & cameraModels() const
const cv::Mat & imageRaw() const
int main(int argc, char *argv[])
static void setType(Type type, const std::string &fileName=kDefaultLogFileName, bool append=true)
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
ULogger class and convenient macros.
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)