Skip to content

Commit

Permalink
The sync_align sample has been modified to align images asynchronousl…
Browse files Browse the repository at this point in the history
…y, enhancing real-time performance.
  • Loading branch information
hzcyf committed Jul 9, 2024
1 parent 250b330 commit 074cc3b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
7 changes: 4 additions & 3 deletions examples/0.basic.quick_start/quick_start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ int main(void) try {
// Create a pipeline.
ob::Pipeline pipe;

// Start the pipeline with default config, more info please refer to the `misc/config/OrbbecSDKConfig_v1.0.xml`.
// Start the pipeline with default config.
// Modify the default configuration by the configuration file: "OrbbecSDKConfig.xml"
pipe.start();

// Create a window for rendering, and set the size of the window.
// Create a window for showing the frames, and set the size of the window.
ob_smpl::CVWindow win("QuickStart", 1280, 720, ob_smpl::ARRANGE_ONE_ROW);

while(win.run()) {
Expand All @@ -21,7 +22,7 @@ int main(void) try {
continue;
}

// Rendering display
// Push the frames to the window for showing.
win.pushFramesToView(frameSet);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/3.advanced.multi_devices/multi_device.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "libobsensor/ObSensor.hpp"
#include <libobsensor/ObSensor.hpp>

#include "utils_opencv.hpp"

Expand Down
42 changes: 19 additions & 23 deletions examples/3.advanced.sync_align/sync_align.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
/**
*Synchronous alignment example
*
* In this example, the mirror status of the depth and the color may be inconsistent because the depth or color sensor does not support mirroring.
* As a result, the images displayed by the depth and the color are reversed. If this happens, just set the mirror interface to keep the two mirror states
* consistent.
* In addition, the resolution obtained by some devices may not support the D2C function, so the resolutions that support D2C, please refer to the
* product manual.
* For example: the D2C resolution supported by DaBai DCW is 640x360, but the actual resolution obtained in this example may be 640x480, at this time the user
* must refer to the product manual to select 640x360 resolution.
*/
#include <libobsensor/ObSensor.hpp>

#include "utils_opencv.hpp"

#include "libobsensor/ObSensor.hpp"
#include <mutex>
#include <thread>

Expand All @@ -23,13 +12,13 @@ uint8_t align_mode = 0;
// key press event processing
void handleKeyPress(ob_smpl::CVWindow &win, std::shared_ptr<ob::Pipeline> pipe /*, std::shared_ptr<ob::Config> config*/) {
////Get the key value
int key = win.waitKey(10);
int key = win.waitKey(1);
if(key == 'F' || key == 'f') {
// Press the F key to switch synchronization
sync = !sync;

if(sync) {
// enable synchronization
// enable frame sync inside the pipeline, which is synchronized by frame timestamp
pipe->enableFrameSync();
}
else {
Expand Down Expand Up @@ -59,34 +48,41 @@ int main(void) try {
// Start the pipeline with config
pipe->start(config);

// Create a Align Filter to align depth frame to color frame
// Create a window for rendering and set the resolution of the window
ob_smpl::CVWindow win("Sync&Align", 1280, 720, ob_smpl::ARRANGE_OVERLAY);
win.setKeyPrompt("'T': Switch Align Mode, 'F': Toggle Synchronization");

// Create a filter to align depth frame to color frame
auto depth2colorAlign = std::make_shared<ob::Align>(OB_STREAM_COLOR);

// create a filter to align color frame to depth frame
auto color2depthAlign = std::make_shared<ob::Align>(OB_STREAM_DEPTH);

// Create a window for rendering and set the resolution of the window
ob_smpl::CVWindow win("Sync&Align", 1280, 720, ob_smpl::ARRANGE_OVERLAY);

win.setKeyPrompt("'T': Switch Align Mode, 'F': Toggle Synchronization");
// Set the callback function for the Align Filter to display the aligned frames in the window
depth2colorAlign->setCallBack([&win](std::shared_ptr<ob::Frame> frame) { win.pushFramesToView(frame); });
color2depthAlign->setCallBack([&win](std::shared_ptr<ob::Frame> frame) { win.pushFramesToView(frame); });

while(win.run()) {
// Handle key press event
handleKeyPress(win, pipe);

// Wait for a frameset from the pipeline
auto frameSet = pipe->waitForFrameset(100);
if(frameSet == nullptr) {
continue;
}

// Get filter according to the align mode
std::shared_ptr<ob::Filter> alignFilter = depth2colorAlign;
if(align_mode % 2 == 0) {
alignFilter = color2depthAlign;
}

auto alignedFrameSet = alignFilter->process(frameSet);

// render and display
win.pushFramesToView(alignedFrameSet);
// push the frameset to the Align Filter to align the frames.
// The frameset will be processed in an internal thread, and the resulting frames will be asynchronously output via the callback function.
alignFilter->pushFrame(frameSet);
}

// Stop the Pipeline, no frame data will be generated
pipe->stop();

Expand Down

0 comments on commit 074cc3b

Please sign in to comment.