Skip to content

Commit

Permalink
Optimize the CVWindow image scaling method and add operational prompts
Browse files Browse the repository at this point in the history
  • Loading branch information
hzcyf committed Jul 9, 2024
1 parent a793db5 commit b3539cb
Show file tree
Hide file tree
Showing 14 changed files with 201 additions and 99 deletions.
4 changes: 2 additions & 2 deletions examples/0.basic.quick_start/quick_start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int main(void) try {
pipe.start();

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

while(win.run()) {
// Wait for frameSet from the pipeline, the default timeout is 1000ms.
Expand All @@ -22,7 +22,7 @@ int main(void) try {
}

// Rendering display
win.pushFramesToShow(frameSet);
win.pushFramesToView(frameSet);
}

// Stop the Pipeline, no frame data will be generated
Expand Down
4 changes: 2 additions & 2 deletions examples/1.stream.callback/callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int main(void) try {
});

// Create a window for rendering, and set the size of the window.
ob_smpl::CVWindow win("quick start", 1280, 720, ob_smpl::RENDER_GRID);
ob_smpl::CVWindow win("Callback", 1280, 720, ob_smpl::ARRANGE_GRID);

while(win.run()) {
std::lock_guard<std::mutex> lock(frameMutex);
Expand All @@ -48,7 +48,7 @@ int main(void) try {
}

// Rendering display
win.pushFramesToShow(renderframeSet);
win.pushFramesToView(renderframeSet);
}

// Stop the Pipeline, no frame data will be generated
Expand Down
4 changes: 2 additions & 2 deletions examples/1.stream.color/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int main(void) try {
pipe.start(config);

// Create a window for rendering and set the resolution of the window.
ob_smpl::CVWindow win("ColorViewer", 1280, 720);
ob_smpl::CVWindow win("Color");

while(win.run()) {
// Wait for up to 100ms for a frameset in blocking mode.
Expand All @@ -29,7 +29,7 @@ int main(void) try {
// get color frame from frameset.
auto colorFrame = frameSet->getFrame(OB_FRAME_COLOR);
// Render colorFrame.
win.pushFramesToShow(colorFrame);
win.pushFramesToView(colorFrame);
}

// Stop the Pipeline, no frame data will be generated
Expand Down
4 changes: 2 additions & 2 deletions examples/1.stream.depth/depth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int main(void) try {
pipe.start(config);

// Create a window for rendering, and set the resolution of the window.
ob_smpl::CVWindow win("DepthViewer", 1280, 720);
ob_smpl::CVWindow win("Depth");

while(win.run()) {
// Wait for up to 100ms for a frameset in blocking mode.
Expand Down Expand Up @@ -49,7 +49,7 @@ int main(void) try {
}

// Render frame in the window.
win.pushFramesToShow(depthFrame);
win.pushFramesToView(depthFrame);
}

// Stop the pipeline
Expand Down
4 changes: 2 additions & 2 deletions examples/1.stream.infrared/infrared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int main() try {
pipe.start(config);

// Create a window for rendering and set the resolution of the window
ob_smpl::CVWindow win("InfraredViewer", 1280, 720, ob_smpl::RENDER_ONE_ROW);
ob_smpl::CVWindow win("Infrared", 1280, 720, ob_smpl::ARRANGE_ONE_ROW);
while(win.run()) {
// Wait for up to 100ms for a frameset in blocking mode.
auto frameSet = pipe.waitForFrameset(100);
Expand All @@ -44,7 +44,7 @@ int main() try {
}

// Render a set of frame in the window.
win.pushFramesToShow(frameSet);
win.pushFramesToView(frameSet);
}

// Stop the pipeline, no frame data will be generated
Expand Down
14 changes: 7 additions & 7 deletions examples/1.stream.multi_streams/multi_streams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ int main(void) try {

// Start the pipeline with config
std::mutex frameMutex;
std::shared_ptr<const ob::FrameSet> renderframeSet;
std::shared_ptr<const ob::FrameSet> renderFrameSet;
pipe.start(config, [&](std::shared_ptr<ob::FrameSet> frameSet) {
std::lock_guard<std::mutex> lock(frameMutex);
renderframeSet = frameSet;
renderFrameSet = frameSet;
});

// The IMU frame rate is much faster than the video, so it is advisable to use a separate pipeline to obtain IMU data.
Expand All @@ -52,21 +52,21 @@ int main(void) try {
imuConfig->enableAccelStream();
// start the imu pipeline.
imuPipeline->start(imuConfig, [&](std::shared_ptr<ob::FrameSet> frameSet) {
std::lock_guard<std::mutex> lockimu(imuFrameMutex);
std::lock_guard<std::mutex> lockImu(imuFrameMutex);
renderImuFrameSet = frameSet;
});

// Create a window for rendering and set the resolution of the window
ob_smpl::CVWindow win("MultiStream", 1280, 720, ob_smpl::RENDER_GRID);
ob_smpl::CVWindow win("MultiStream", 1280, 720, ob_smpl::ARRANGE_GRID);
while(win.run()) {
std::lock_guard<std::mutex> lockimu(imuFrameMutex);
std::lock_guard<std::mutex> lockImu(imuFrameMutex);
std::lock_guard<std::mutex> lock(frameMutex);

if(renderframeSet == nullptr || renderImuFrameSet == nullptr) {
if(renderFrameSet == nullptr || renderImuFrameSet == nullptr) {
continue;
}
// Render camera and imu frameset.
win.pushFramesToShow({ renderframeSet, renderImuFrameSet });
win.pushFramesToView({ renderFrameSet, renderImuFrameSet });
}

// Stop the Pipeline, no frame data will be generated.
Expand Down
6 changes: 3 additions & 3 deletions examples/2.device.net_device/net_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ int main(void) try {
});

// Create a window for rendering and set the resolution of the window
ob_smpl::CVWindow win("MultiDeviceViewer", 1280, 720, ob_smpl::RENDER_ONE_ROW);
ob_smpl::CVWindow win("NetDevice", 1280, 720, ob_smpl::ARRANGE_ONE_ROW);

while(win.run()) {
std::shared_ptr<ob::FrameSet> frameSet;
Expand All @@ -75,10 +75,10 @@ int main(void) try {
// Print the Color data frame information every 30 frames
std::cout << "Color Frame: index=" << colorFrame->getIndex() << ", timestamp=" << colorFrame->getTimeStampUs();
}
win.pushFramesToShow(depthFrame);
win.pushFramesToView(depthFrame);
}
else {
win.pushFramesToShow({ colorFrame, depthFrame });
win.pushFramesToView({ colorFrame, depthFrame });
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/3.advanced.common_usages/common_usages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void inputWatcher();
int main(void) try {

// create window for render
win = std::make_shared<ob_smpl::CVWindow>("CommonUsages", 1280, 720, ob_smpl::RENDER_GRID);
win = std::make_shared<ob_smpl::CVWindow>("CommonUsages", 1280, 720, ob_smpl::ARRANGE_GRID);

// Set log severity. disable log, please set OB_LOG_SEVERITY_OFF.
ob::Context::setLoggerSeverity(OB_LOG_SEVERITY_ERROR);
Expand Down Expand Up @@ -311,7 +311,7 @@ std::shared_ptr<ob::FrameSet> fileterAlign(std::shared_ptr<ob::FrameSet> framese
}
void handleFrameset(std::shared_ptr<ob::FrameSet> frameset) {
auto alignFrameSet = fileterAlign(frameset);
win->pushFramesToShow(alignFrameSet);
win->pushFramesToView(alignFrameSet);
}

void getDeviceInformation() {
Expand Down
4 changes: 2 additions & 2 deletions examples/3.advanced.hdr/hdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ int main(void) try {
}

// add merged depth frame to render queue
win.pushFramesToShow(mergedDepthFrame);
win.pushFramesToView(mergedDepthFrame);
}
else {
// add original depth frame to render queue
win.pushFramesToShow(depthFrame);
win.pushFramesToView(depthFrame);
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/3.advanced.multi_devices/multi_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int main() try {
StartStream(pipes);

// Create a window for rendering and set the resolution of the window
ob_smpl::CVWindow win("MultiDeviceViewer", 1280, 720, ob_smpl::RENDER_GRID);
ob_smpl::CVWindow win("MultiDevice", 1280, 720, ob_smpl::ARRANGE_GRID);

// Main loop to show the frames, press `ESC` to exit
while(win.run()) {
Expand All @@ -75,7 +75,7 @@ int main() try {
auto &frameset = item.second;

// push the frames to the window for show
win.pushFramesToShow(frameset, deviceIndex);
win.pushFramesToView(frameset, deviceIndex);
}
}

Expand Down
2 changes: 1 addition & 1 deletion examples/3.advanced.post_processing/post_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int main() try {
}

// Render frame in the window
win.pushFramesToShow(depthFrame);
win.pushFramesToView(depthFrame);
}

// Stop the pipeline
Expand Down
26 changes: 7 additions & 19 deletions examples/3.advanced.sync_align/sync_align.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,7 @@ uint8_t align_mode = 0;
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);
if(key == '+' || key == '=') {
// Press the + key to increase alpha
alpha += 0.1f;
if(alpha >= 1.0f) {
alpha = 1.0f;
}
win.setAlpha(alpha);
}
else if(key == '-' || key == '_') {
// press - key to decrease alpha
alpha -= 0.1f;
if(alpha <= 0.0f) {
alpha = 0.0f;
}
win.setAlpha(alpha);
}
else if(key == 'F' || key == 'f') {
if(key == 'F' || key == 'f') {
// Press the F key to switch synchronization
sync = !sync;

Expand All @@ -52,10 +36,12 @@ void handleKeyPress(ob_smpl::CVWindow &win, std::shared_ptr<ob::Pipeline> pipe /
// turn off sync
pipe->disableFrameSync();
}
win.addLog("Sync: " + std::string(sync ? "On" : "Off"));
}
else if(key == 't' || key == 'T') {
// Press the T key to switch align mode
align_mode = (align_mode + 1) % 2;
win.addLog("Align Mode: " + std::string(align_mode == 0 ? "Depth to Color" : "Color to Depth"));
}
}

Expand All @@ -80,7 +66,9 @@ int main(void) try {
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::RENDER_OVERLAY);
ob_smpl::CVWindow win("Sync&Align", 1280, 720, ob_smpl::ARRANGE_OVERLAY);

win.setKeyPrompt("'T': Switch Align Mode, 'F': Toggle Synchronization");

while(win.run()) {
handleKeyPress(win, pipe);
Expand All @@ -97,7 +85,7 @@ int main(void) try {
auto alignedFrameSet = alignFilter->process(frameSet);

// render and display
win.pushFramesToShow(alignedFrameSet);
win.pushFramesToView(alignedFrameSet);
}
// Stop the Pipeline, no frame data will be generated
pipe->stop();
Expand Down
Loading

0 comments on commit b3539cb

Please sign in to comment.