obsdk demo:stream_color

This commit is contained in:
tangchao0503
2026-03-30 17:23:04 +08:00
parent 65b0b307f6
commit fad9423121
10 changed files with 1249 additions and 22 deletions

View File

@ -0,0 +1,50 @@
// Copyright (c) Orbbec Inc. All Rights Reserved.
// Licensed under the MIT License.
#include <libobsensor/ObSensor.hpp>
#include "utils.hpp"
#include "utils_opencv.hpp"
int main(void) try {
// 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>();
// Enable color video stream.
config->enableVideoStream(OB_STREAM_COLOR);
// Start the pipeline with config.
pipe.start(config);
// Create a window for rendering and set the resolution of the window.
ob_smpl::CVWindow win("Color");
while (win.run()) {
// Wait for up to 100ms for a frameset in blocking mode.
auto frameSet = pipe.waitForFrameset();
if (frameSet == nullptr) {
continue;
}
// get color frame from frameset.
auto colorFrame = frameSet->getFrame(OB_FRAME_COLOR);
// Render colorFrame.
win.pushFramesToView(colorFrame);
}
// Stop the Pipeline, no frame data will be generated
pipe.stop();
return 0;
}
catch (ob::Error& e) {
std::cerr << "function:" << e.getFunction() << "\nargs:" << e.getArgs() << "\nmessage:" << e.what() << "\ntype:" << e.getExceptionType() << std::endl;
std::cout << "\nPress any key to exit.";
ob_smpl::waitForKeyPressed();
exit(EXIT_FAILURE);
}