Documentation / Gemini 330 series /
C++ Sample Color Stream Viewer

C++ Sample Color Stream Viewer

Function description: This example mainly demonstrates the use of SDK to get color data and draw display, get resolution and select settings, display color images, and exit the program through the ESC_KEY key

| This example is based on the C++High Level API for demonstration

Firstly, it is necessary to create a pipeline, through which multiple types of streams can be easily opened and closed, and a set of frame data can be obtained

ob::Pipeline pipe;

Get all stream configurations of the color camera, including stream resolution, frame rate, and frame format

// Create a pipeline with default device
ob::Pipeline pipe;

// Configure which streams to enable or disable for the Pipeline by creating a Config
std::shared_ptr<ob::Config> config = std::make_shared<ob::Config>();

std::shared_ptr<ob::VideoStreamProfile> colorProfile = nullptr;
try {
// Get all stream profiles of the color camera, including stream resolution, frame rate, and frame format
auto profiles = pipe.getStreamProfileList(OB_SENSOR_COLOR);
try {
// Find the corresponding Profile according to the specified format, and choose the RGB888 format first
colorProfile = profiles->getVideoStreamProfile(640, 480, OB_FORMAT_YUYV, 30);
catch(ob::Error &e) {
// If the specified format is not found, select the first one (default stream profile)
colorProfile = std::const_pointer_cast<ob::StreamProfile>(profiles->getProfile(OB_PROFILE_DEFAULT))->as<ob::VideoStreamProfile>();
catch(ob::Error &e) {
std::cerr << "Current device is not support color sensor!" << std::endl;

Start the Stream configured in Configuration

Wait for a frame of data in a blocking manner, which is a composite frame containing frame data for all streams enabled in the configuration, and set the waiting timeout time for the frame

auto frameSet = pipe.waitForFrames(100);//Set the waiting time to 100ms

Print metadata every 30 frames

// print metadata every 30 frames
auto index = colorFrame->index();
if(index % 30 == 0) {
std::cout << "*************************** Color Frame #" << index << " Metadata List ********************************" << std::endl;
for(int metaDataType = 0; metaDataType < OB_FRAME_METADATA_TYPE_COUNT; metaDataType++) {
// Check if it is supported metaDataType for current frame
if(colorFrame->hasMetadata((OBFrameMetadataType)metaDataType)) {
// Get the value of the metadata
std::cout << metaDataTypes[metaDataType] << ": " << colorFrame->getMetadataValue((OBFrameMetadataType)metaDataType) << std::endl;
else {
std::cout << metaDataTypes[metaDataType] << ": " << "unsupported" << std::endl;
std::cout << "********************************************************************************" << std::endl << std::endl;

Stop Pipeline, no more frame data will be generated


Expected Output

Stay updated

Be the first to learn about our new
products and updates.