How to get the depth information from .raw file (python)?
I am very new in the area. So I am very sorry to ask a question like this but please help me! I use d435i to take the image by realsense viewer. I got .png, .raw file. I want to get the depth matrix from the .raw file. What is the structure of the .raw file that generate from realsense viewer? Please give me the example code that I can run with no error because I am also new to programming. Thank you in advance!
-
Hi Thanyachanok Sutt The best RealSense reference about reading depth data from a .raw file (which follows the UVC specification for the depth stream) is at the link below.
https://github.com/IntelRealSense/librealsense/issues/2231#issuecomment-416814331
You could also explore the possibility of loading a RealSense .raw file into the software tool MATLAB using programming.
https://github.com/IntelRealSense/librealsense/issues/5824#issuecomment-584780985
-
The UVC specification for the Z16 depth stream is at the link below:
https://linuxtv.org/downloads/v4l-dvb-apis/userspace-api/v4l/pixfmt-z16.html
-
MartyX Grover I run and found this error.

-
A RealSense user who ran this script also had errors. It apparently needs to be part of a larger script in order for headers to be defined, such as cv (which may be why cv:mat has a red error mark beside it in your script)..
https://github.com/IntelRealSense/librealsense/issues/2231#issuecomment-423095172
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<opencv2/opencv.hpp>;
using namespace std;
using namespace cv;
int main(){
int IMAGE_WIDTH = 424, IMAGE_HEIGHT = 240;
FILE* fp; char* imagedata;
int framesize = IMAGE_WIDTH*IMAGE_HEIGHT;
fp = fopen(filename, "rb");
imagedata = (char*)malloc(sizeof(short)* framesize);
fread(imagedata, sizeof(short), framesize, fp);
cv::Mat depthMat(Size(IMAGE_WIDTH, IMAGE_HEIGHT), CV_16U, (void*)imagedata, cv::Mat::AUTO_STEP);
printf("Depth RAW Central Value: %d mm", depthMat.at<short>(IMAGE_HEIGHT / 2, IMAGE_WIDTH / 2));
fclose(fp); free(imagedata);
return 0;
}
Please sign in to leave a comment.
Comments
4 comments