Items with no label
3335 Discussions

Simple Path to get a working C++ program for depth data from D435 camera

JBirk
Beginner
4,731 Views

My D435 camera is still scheduled to arrive, despite it being over two months since it was ordered. I would like to make some progress in getting C++ code to access depth data. I have tried to get various GitHub code samples to work without success. For example, I started with rs-capture.cpp, then I needed example.hpp, then I needed stb_easy_font.h and still have lots of errors in Eclipse.

Please recommend the simplest path to copying a complete working program that should collect a depth sample. I am hoping there is such a solution, that doesn't have a seemingly endless stream of additional tidbits of needed knowledge. I am relatively new to C++, Linux, Eclipse, and Real Sense cameras.

0 Kudos
12 Replies
MartyG
Honored Contributor III
1,721 Views

The most recent official delivery estimate for the D435 that I saw back on March 21 was '9 to 10 weeks'. If you have been waiting two months then your order is probably getting closer to being fulfilled as the shippings are done in the order that they were received. People definitely are receiving their D435 cameras, as evidenced by their postings about them on this forum. Your patience is very much appreciated.

There does not seem to be a step by step guide to setting up a development environment from start to end, unfortunately. This may be due to the numerous different ways and languages that development can be approached from.

Could you tell me what camera you are using for your tests please if your D435 has not yet arrived. RealSense cameras contain special depth and infrared sensors, so an ordinary webcam camera would not be able to run most of the sample programs.

If you do not yet have a RealSense D415 or D435 camera to test with, the page linked to below provides some pre-recorded data that you can drop into the RealSense Viewer program to look at it.

https://github.com/IntelRealSense/librealsense/blob/master/doc/sample-data.md librealsense/sample-data.md at master · IntelRealSense/librealsense · GitHub

.

0 Kudos
JBirk
Beginner
1,721 Views

I don't have a Real Sense camera yet. I am just trying to get some Intel Real Sense SDK code to work. I downloaded the SDK and the files (lots) are in appropriate directories.

0 Kudos
MartyG
Honored Contributor III
1,721 Views

RealSense SDK scripts usually make a call to the camera right from their first lines and are dependent on the presence of a camera to function without errors. So you are not likely to have much success with running SDK scripts before you have a camera, unfortunately.

0 Kudos
JBirk
Beginner
1,721 Views

Marty,

Thanks for the info.

John

0 Kudos
JBirk
Beginner
1,721 Views

I now have a D435 camera, but am still having trouble getting a C++ program on Linux to work with it.

 

I picked one of the basic programs, namely rs-capture ( https://github.com/IntelRealSense/librealsense/tree/master/examples/capture https://github.com/IntelRealSense/librealsense/tree/master/examples/capture

), but it leads me toward "example.hpp" which leads me to stb_easy_font.h, which leads me to rs.h with an error of extern "C" {

 

I have an error "expected ' }' before end of line" in an exception program and an "expected declaration before end of line" in a line "# pragma GCC visibility push(default)"

 

Please help me locate a simple program to get started.

0 Kudos
MartyG
Honored Contributor III
1,721 Views

To edit and run C++ scripts, you need to have a script editing program set up. Are you using one of these, please?

The most popular one is Visual Studio. If you are using Linux, you can find a Linux version called Visual Studio Code here:

https://code.visualstudio.com/ Visual Studio Code - Code Editing. Redefined

Could you also confirm please that you are using the capture.cpp script file whose link is posted at the top of the page that you provided? If you are copying and pasting the text from the tutorial then the program will not work, as it is just quoting pieces from the script in order to explain them step by step.

An easy way to get the complete files without any script editing would be to right-click on the links in your web browser and select the save-file option (it may be called Save Link As or Save Target As, depending on the browser you are using).

Then save the files into a folder that you want to use as your project folder. Once you have got your script editing program such as Visual Studio Code set up, I believe that double-clicking on the capture.cpp file in your project folder should cause the script editor program to launch and load the capture.cpp script into its editing window.

Once you have successfully imported a script into Visual Studio, you need to tell the program where to find files such as example.cpp so that it can access them. This process is called 'linking'. I recently wrote a guide to doing so for Visual Studio 2017 on Windows. I do not know if the process is the same for Visual Studio Code on Linux.

0 Kudos
jb455
Valued Contributor II
1,721 Views

You can't just open one of the sample code files and run it - you have to build and compile the project first. Instructions for doing this in Ubuntu are here: https://github.com/IntelRealSense/librealsense/blob/master/doc/installation.md librealsense/installation.md at master · IntelRealSense/librealsense · GitHub

Then you'll get a solution file to open in visual studio with all the files linked together properly (assuming it's similar to the Windows process).

0 Kudos
MartyG
Honored Contributor III
1,721 Views

Thanks again JB. Explaining in beginner terms how to set up the development environment and start experimenting with scripting is always challenging because there isn't any beginner documentation for doing so with SDK 2.0 - a certain amount of previous knowledge about coding and compiling is assumed.

0 Kudos
JBirk
Beginner
1,721 Views

I have been using Codelite. I have three files in the same folder for compilation: rs-capture.cpp, example.hpp, and stb_easy_font.h

Here are errors I'm getting upon build.

/bin/sh -c '/usr/bin/make -j8 -e -f Makefile'

----------Building project:[ rs_capture - Debug ]----------

make[1]: Entering directory '/home/jbirk/Documents/rs-capture/rs-capture'

/usr/bin/x86_64-linux-gnu-g++ -o ./Debug/rs_capture @"rs_capture.txt" -L. -L. -LDebug -O0

./Debug/rs-capture.cpp.o: In function `draw_pointcloud(float, float, glfw_state&, rs2::points&)':

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:238: undefined reference to `glPopMatrix'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:239: undefined reference to `glPushAttrib'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:241: undefined reference to `glClearColor'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:242: undefined reference to `glClear'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:244: undefined reference to `glMatrixMode'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:245: undefined reference to `glPushMatrix'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:246: undefined reference to `gluPerspective'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:248: undefined reference to `glMatrixMode'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:249: undefined reference to `glPushMatrix'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:250: undefined reference to `gluLookAt'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:252: undefined reference to `glTranslatef'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:253: undefined reference to `glRotated'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:254: undefined reference to `glRotated'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:255: undefined reference to `glTranslatef'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:257: undefined reference to `glPointSize'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:258: undefined reference to `glEnable'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:259: undefined reference to `glEnable'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:260: undefined reference to `glBindTexture'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:262: undefined reference to `glTexParameterfv'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:263: undefined reference to `glTexParameteri'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:264: undefined reference to `glTexParameteri'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:265: undefined reference to `glBegin'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:275: undefined reference to `glVertex3fv'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:276: undefined reference to `glTexCoord2fv'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:281: undefined reference to `glEnd'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:282: undefined reference to `glPopMatrix'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:283: undefined reference to `glMatrixMode'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:284: undefined reference to `glPopMatrix'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:285: undefined reference to `glPopAttrib'

/home/jbirk/Documents/rs-capture/rs-capture/example.hpp:286: undefined reference to `glPushMatrix'

./Debug/rs-capture.cpp.o: In function `rs2::error::error(rs2_error*)':

/usr/include/librealsense2/hpp/rs_types.hpp:74: undefined reference to `rs2_get_error_message'

/usr/include/librealsense2/hpp/rs_types.hpp:76: undefined reference to `rs2_get_failed_function'

/usr/include/librealsense2/hpp/rs_types.hpp:76: undefined reference to `rs2_get_failed_function'

/usr/include/librealsense2/hpp/rs_types.hpp:77: undefined reference to `rs2_get_failed_args'

/usr/include/librealsense2/hpp/rs_types.hpp:77: undefined reference to `rs2_get_failed_args'

/usr/include/librealsense2/hpp/rs_types.hpp:78: undefined reference to `rs2_get_librealsense_exception_type'

/usr/include/librealsense2/hpp/rs_types.hpp:79: undefined reference to `rs2_free_error'

./Debug/rs-capture.cpp.o: In function `rs2::error::handle(rs2_error*)':

/usr/include/librealsense2/hpp/rs_types.hpp:125: undefined reference to `rs2_get_librealsense_exception_type'

./Debug/rs-capture.cpp.o: In function `rs2::stream_profile::stream_profile(rs2_stream_profile const*)':

/usr/include/librealsense2/hpp/rs_frame.hpp:109: undefined reference to `rs2_get_stream_profile_data'

/usr/include/librealsense2/hpp/rs_frame.hpp:112: undefined reference to `rs2_is_stream_profile_default'

./Debug/rs-capture.cpp.o: In function `rs2::frame::~frame()':

/usr/include/librealsense2/hpp/rs_frame.hpp:266: undefined reference to `rs2_release_frame'

./Debug/rs-capture.cpp.o: In function `rs2::frame::get_data() const':

/usr/include/librealsense2/hpp/rs_frame.hpp:340: undefined reference to `rs2_get_frame_data'

./Debug/rs-capture.cpp.o: In function `rs2::frame::get_profile() const':

/usr/include/librealsense2/hpp/rs_frame.hpp:348: undefined reference to `rs2_get_frame_stream_profile'

./Debug/rs-capture.cpp.o: In function `rs2::frame::add_ref() const':

/usr/include/librealsense2/hpp/rs_frame.hpp:378: undefined reference to `rs2_frame_add_ref'

./Debug/rs-capture.cpp.o: In function `rs2::frame::reset()':

/usr/include/librealsense2/hpp/rs_frame.hpp:386: undefined reference to `rs2_release_frame'

./Debug/rs-capture.cpp.o: In function `rs2::video_frame::video_frame(rs2::frame const&)':

/usr/include/librealsense2/hpp/rs_frame.hpp:414: undefined reference to `rs2_is_frame_extendable_to'

./Debug/rs-capture.cpp.o: In function `rs2::video_frame::get_width() const':

/usr/include/librealsense2/hpp/rs_frame.hpp:429: undefined reference to `rs2_get_frame_width'

./Debug/rs-capture.cpp.o: In function `rs2::video_frame::get_height() const':

/usr/include/librealsense2/hpp/rs_frame.hpp:441: undefined reference to `rs2_get_frame_height'

./Debug/rs-capture.cpp.o: In function `rs2::points::get_vertices() const':

/usr/include/librealsense2/hpp/rs_frame.hpp:508: undefined reference to `rs2_get_frame_vertices'

./Debug/rs-capture.cpp.o: In function `rs2::points::get_texture_coordinates() const':

/usr/include/librealsense2/hpp/rs_frame.hpp:525: undefined reference to `rs2_get_frame_texture_coordinates'

./Debug/rs-capture.cpp.o: In function `rs2::depth_frame::depth_frame(rs2::frame const&)':

/usr/include/librealsense2/hpp/rs_frame.hpp:546: undefined reference to `rs2_is_frame_extendable_to'

./Debug/rs-capture.cpp.o: In function `rs2::frameset::frameset(rs2::frame const&)':

/usr/include/librealsense2/hpp/rs_frame.hpp:638: undefined reference to `rs2_is_frame_extendable_to'

/usr/include/librealsense2/hpp/rs_frame.hpp:648: undefined reference to `rs2_embedded_frames_count'

./Debug/rs-capture.cpp.o: In function `rs2::processing_block::invoke(rs2::frame) const':

/usr/include/librealsense2/hpp/rs_processing.hpp:103: undefined reference to `rs2_process_frame'

./Debug/rs-capture.cpp.o: In function `rs2::frame_queue::frame_queue(unsigned int)':

/usr/include/librealsense2/hpp/rs_processing.hpp:145: undefined reference to `rs2_create_frame_queue'

/usr/include/librealsense2/hpp/rs_processing.hpp:145: undefined reference to `rs2_delete_frame_queue'

./Debug/rs-capture.cpp.o: In function `rs2::frame_queue::enqueue(rs2::frame) const':

/usr/include/librealsense2/hpp/rs_p...

0 Kudos
MartyG
Honored Contributor III
1,721 Views

That is a lot of missing linkages. Have you built the RealSense SDK 2.0 (also known as Librealsense2) like JB suggested above?

https://github.com/IntelRealSense/librealsense/blob/master/doc/installation.md librealsense/installation.md at master · IntelRealSense/librealsense · GitHub

0 Kudos
JBirk
Beginner
1,721 Views

I used the following URL to install the SDK. I have lots of files and directories relating to RealSense in /usr/include/realsense2

https://github.com/IntelRealSense/librealsense/blob/development/doc/distribution_linux.md https://github.com/IntelRealSense/librealsense/blob/development/doc/distribution_linux.mdhttps://github.com/IntelRealSense/librealsense/blob/development/doc/distribution_linux.md librealsense/distribution_linux.md at development · IntelRealSense/librealsense · GitHub which is like https://realsense.intel.com/sdk-2/ Download Intel RealSense SDK Cross Platform Library

Maybe I should check out the following, since I have Ubuntu: https://github.com/IntelRealSense/librealsense/blob/master/doc/installation.md librealsense/installation.md at master · IntelRealSense/librealsense · GitHub

0 Kudos
MartyG
Honored Contributor III
1,721 Views

Yes, it's a good idea to check through the steps on the installation page. There are quite a few occasions where I could have made life easier for myself and saved time if I had RTFM (Read The Flipping Manual).

0 Kudos
Reply