- Displaying Color Frame
- Displaying Infrared Frame
Displaying Color Frame
In this demo, you will acquire color frame from the RealSense camera and display it using OpenCV. Before you start, make sure you have librealsense and OpenCV installed and working properly on your system. Using the editor of your choise create BGR_sample.cpp and copy-paste the following code-snippet:
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
for(int i = 0; i < 30; i++)
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", color);
waitKey(0);
return 0;
}
Context.
Definition rs.hpp:320
device * get_device(int index)
Definition rs.hpp:354
Provides convenience methods relating to devices.
Definition rs.hpp:568
void enable_stream(stream stream, int width, int height, format format, int framerate, output_buffer_format output_buffer_type=output_buffer_format::continous)
Enables specific stream and requests specific properties.
Definition rs.hpp:704
void start(rs::source source=rs::source::video)
Begins streaming on all enabled streams for this device.
Definition rs.hpp:879
const void * get_frame_data(stream stream) const
Retrieves contents of latest frame on a stream.
Definition rs.hpp:1050
void wait_for_frames()
Blocks until new frames are available.
Definition rs.hpp:985
Exposes librealsense functionality for C++ compilers.
Compile and run the application from terminal using the following command line:
g++ -std=c++11 BGR_sample.cpp -lrealsense -lopencv_core -lopencv_highgui -o BGR && ./BGR
Result:

Displaying Infrared Frame
Displaying Infrared and Depth data is not very different from Color data. Infrared frame is a single channel, 8 bits-per-pixel image. Copy the following code snippet into IR_sample.cpp:
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
for(int i = 0; i < 40; i++)
equalizeHist( ir, ir );
applyColorMap(ir, ir, COLORMAP_JET);
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", ir);
waitKey(0);
return 0;
}
Compile and run the program from the terminal, with the following command:
g++ -std=c++11 IR_sample.cpp -lrealsense -lopencv_core -lopencv_imgproc -lopencv_highgui -o ir && ./ir
Result :