Why does get_latest_frame() deliver no frame?

Hello everyone,

I’m trying to get a depth image from the Orbbec Astra Pro. The Program stops at the line
astra::Frame frame = reader.get_latest_frame();
Is this a source code problem or are there project dependencies which i don’t know?

I am using Visual Studio 2015 and copied and modified the example solution from the Astra SDK.

Here is a MWE:

#include <astra/astra.hpp>
#include "DepthCam.hpp"
#include <cstdio>
#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

Mat depthframe2mat(astra::DepthFrame depthframe)
{
    int width = depthframe.width();
    int height = depthframe.height();
    int grayval = 0;
    Mat image(height, width, CV_8UC1);

    for (int y = 0; y < height; y++)
    {
        for (int x = 0; x < width; x++)
        {
            grayval = depthframe.data()[x+y*width] / (3500/256);
	    image.at<uchar>(y, x) = grayval;
	}
    }
    return image;
}

int main(int argc, char** argv)
{
    astra::initialize();
    Mat depthimage;

    astra::StreamSet streamSet;
    astra::StreamReader reader = streamSet.create_reader();
    reader.stream<astra::DepthStream>().start();

    namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
	
    do 
    {
        astra::Frame frame = reader.get_latest_frame();
        const auto depthFrame = frame.get<astra::DepthFrame>();

	depthimage = depthframe2mat(depthFrame);
	imshow("MyWindow", depthimage);

	if(waitKey(30) >= 0) break;

    } while (1);

    astra::terminate();
    return 0;
}

Thank you!

I have found the Problem:
Change the USB Port! But it is strange that no error message appears that the orbbec sensor is not correctly connected.

1 Like

Hi JWi3B3,

i am using your depthframe2Mat method and it worked for me, but i am trying to make somthing similar for the color image but cant get it work.

Can you help me out ?

Hello smoli,

I am using the Astra Pro, and as far as I know, the Astra SDK doesnt support color image grabbing for the Astra Pro.

So if you have also an Astra Pro, i would recommend you that you use the OpenCV-Function for grabbing the color image:
http://docs.opencv.org/3.0-beta/modules/videoio/doc/reading_and_writing_video.html

But if you get the color image with Astra SDK you can try this:
(Maybe it need a little bit of debugging, because I cant test it)

Mat colorframe2mat(astra::ColorFrame colorframe)
{
    int width = depthframe.width();
    int height = depthframe.height();
    Mat image(height, width, CV_8UC3);

    const astra::RgbPixel* colorData = colorframe.data();

    for (int y = 0; y < height; y++)
    {
        for (int x = 0; x < width; x++)
        {
            image.at<cv::Vec3b>(y,x)[0] = colorData[y * width + x].b;
            image.at<cv::Vec3b>(y,x)[1] = colorData[y * width + x].g;
            image.at<cv::Vec3b>(y,x)[2] = colorData[y * width + x].r;
	}
    }
    return image;
}
2 Likes

Hi,

thank you
for de snippet. I will try it now.

I am using
the opencv 3.1, and when i access the depth image and the color image simultaneously,
i cannot use VideoCapture.

It Work. I can now access Depth and RGB image with Mat format.

Hi,

I am trying
to access simultaneously the depth and the Ir image. But I am experimenting a
crash, and I don’t know if I have configured the readers wright.

astra::Frame frame = readerD.get_latest_frame();
    const auto depthFrame = frame.get<astra::DepthFrame>();

    astra::Frame cFrame = readerC.get_latest_frame();
    const auto colorFrame = cFrame.get<astra::ColorFrame>();

    astra::Frame irFrame = readerIr.get_latest_frame();
    const auto IrFrame = irFrame.get<astra::InfraredFrame16>();

I’m having this same problem right now.
I’ve tried all USB ports, and it still shows this error. I don’t know what to do, other than give up and use OpenNI2.

To solve this issue just copy the following files and folders from the bin* folder to your target folder:
OpenNI2 (folder)
Plugins (folder)
OpenNI.ini
OpenNI2.dll
OpenNI2.lib

* The bin folder is where the precompiled samples exist after you unzip Astra SDK (AstraSDK-vX.X.X…/bin)

1 Like