here is a sample code for simultaneous stream of depth and colour streams using Astra SDK in Ubuntu 16.04
/*
#include <astra/astra.hpp>
#include <astra_core/astra_core.hpp>
#include
#include
#include <key_handler.h>
#include
#include
#include
#include
#include
#include <stdio.h>
#include “opencv2/opencv.hpp”
#include “opencv2/objdetect/objdetect.hpp”
#include “opencv2/highgui/highgui.hpp”
#include “opencv2/imgproc/imgproc.hpp”
#include <opencv2/core/core.hpp>
#include <opencv2/calib3d/calib3d.hpp>
*/
using namespace std;
using namespace cv;
/*
float elapsedMillis_{.0f};
using DurationType = std::chrono::milliseconds;
using ClockType = std::chrono::high_resolution_clock;
ClockType::time_point prev_;
using buffer_ptr = std::unique_ptr<astra::RgbPixel []>;
buffer_ptr buffer_;
unsigned int lastWidth_;
unsigned int lastHeight_;
*/
/*
astra::ColorStream configure_color(astra::StreamReader& reader)
{
auto colorStream = reader.streamastra::ColorStream();
auto oldMode = colorStream.mode();
//We don't have to set the mode to start the stream, but if you want to here is how:
astra::ImageStreamMode colorMode;
colorMode.set_width(640);
colorMode.set_height(480);
colorMode.set_pixel_format(astra_pixel_formats::ASTRA_PIXEL_FORMAT_RGB888);
colorMode.set_fps(30);
colorStream.set_mode(colorMode);
auto newMode = colorStream.mode();
printf("Changed color mode: %dx%d @ %d -> %dx%d @ %d\n",
oldMode.width(), oldMode.height(), oldMode.fps(),
newMode.width(), newMode.height(), newMode.fps());
return colorStream;
}
astra::DepthStream configure_depth(astra::StreamReader& reader)
{
auto depthStream = reader.streamastra::DepthStream();
auto oldMode = depthStream.mode();
//We don't have to set the mode to start the stream, but if you want to here is how:
astra::ImageStreamMode depthMode;
depthMode.set_width(640);
depthMode.set_height(480);
depthMode.set_pixel_format(astra_pixel_formats::ASTRA_PIXEL_FORMAT_DEPTH_MM);
depthMode.set_fps(30);
depthStream.set_mode(depthMode);
auto newMode = depthStream.mode();
printf("Changed depth mode: %dx%d @ %d -> %dx%d @ %d\n",
oldMode.width(), oldMode.height(), oldMode.fps(),
newMode.width(), newMode.height(), newMode.fps());
return depthStream;
}
*/
int main(int argc, char** argv)
{
astra::initialize();
set_key_handler();
astra::StreamSet streamSet;
astra::StreamReader reader = streamSet.create_reader();
reader.stream<astra::ColorStream>().start();
reader.stream<astra::DepthStream>().start();
// may use for manual configuration of streams
/* auto colorStream = configure_color(reader);
auto depthStream = configure_depth(reader);
colorStream.start();
depthStream.start();*/
do
{
astra::Frame frame = reader.get_latest_frame();
const astra::ColorFrame colorFrame = frame.get<astra::ColorFrame>();
const astra::DepthFrame depthFrame = frame.get<astra::DepthFrame>();
cv::Mat mImageRGB(colorFrame.height(), colorFrame.width(), CV_8UC3, (void*)colorFrame.data());
cv::Mat cImageBGR;
cv::cvtColor( mImageRGB, cImageBGR, CV_RGB2BGR );
cv::Mat mImageDepth(depthFrame.height(), depthFrame.width(), CV_16UC1, (void*)depthFrame.data());
cv::Mat mScaledDepth;
mImageDepth.convertTo( mScaledDepth, CV_8U, 255.0/3500 );
/*
cv::imshow( “Color Image”, cImageBGR ); // RGB image
cv::imshow( “Depth Image”, mScaledDepth ); // depth image
cv::imshow( “Depth Image 2”, mImageDepth ); // contains depth data
*/
/* std::cout << "colorStream – hFov: "
<< reader.streamastra::ColorStream().hFov()
<< " vFov: "
<< reader.streamastra::ColorStream().vFov()
<< std::endl;*/
/* std::cout << "depthStream – hFov: "
<< reader.streamastra::DepthStream().hFov()
<< " vFov: "
<< reader.streamastra::DepthStream().vFov()
<< std::endl;*/
/* check_fps();
*/
astra_update();
if( cv::waitKey(1) == 'q')
break;
} while (shouldContinue);
astra::terminate();
}
I don’t know why basic c++ includes are not formatted accordingly but it can be managed easily.
cheers,
Prasanna