Comments (7)
Yes, it takes advantage of the double buffering already available with UVC
from zed-open-capture.
Yes, a copy is always the best solution in similar cases... I will test it further
from zed-open-capture.
Hi @peds
thank you for reporting this issue.
I think that there are two possible solutions to fix it:
- double buffering (or triple...)
- returning a copied buffer
The first solution introduces a possible frame latency. The UVC driver already implements a multi-buffer mechanism (we use double buffering), but it can be not enough:
zed-open-capture/src/videocapture.cpp
Line 827 in 969d153
The second solution requires more memory and can be slow for hosts with slow memory.
Any thoughts?
from zed-open-capture.
@peds can you test if this branch solves the problem:
https://github.com/stereolabs/zed-open-capture/tree/fix_race_cond
from zed-open-capture.
Hi @peds thank you for reporting this issue. I think that there are two possible solutions to fix it:
1. double buffering (or triple...) 2. returning a copied buffer
The first solution introduces a possible frame latency. The UVC driver already implements a multi-buffer mechanism (we use double buffering), but it can be not enough:
zed-open-capture/src/videocapture.cpp
Line 827 in 969d153
The second solution requires more memory and can be slow for hosts with slow memory.
Any thoughts?
Hi @Myzhar,
Thank you for getting back to me so fast!
I did implement a solution that does work by making a copy of the last frame that is only updated when getLastFrame
is called. I think this is similar to your second proposed solution?
Did you implement double buffering in https://github.com/stereolabs/zed-open-capture/tree/fix_race_cond?
I will test this and get back to you.
from zed-open-capture.
The issue persists even with double buffering, but it seems to be more subtle.
I think the most reliable solution would be to return a copy of mLastFrame
. The following worked for me.
static void copyFrame(Frame& dstFrame, Frame& srcFrame){
if (srcFrame.data != nullptr) {
int bufSize = srcFrame.width * srcFrame.height * srcFrame.channels;
if(dstFrame.data == nullptr ){
dstFrame.data = new unsigned char[bufSize];
}
// memcpy( dstFrame.data, srcFrame.data, bufSize);
std::copy( srcFrame.data, srcFrame.data + bufSize, dstFrame.data);
}
dstFrame.frame_id = srcFrame.frame_id;
dstFrame.timestamp = srcFrame.timestamp;
dstFrame.width = srcFrame.width;
dstFrame.height = srcFrame.height;
dstFrame.channels = srcFrame.channels;
}
const Frame& VideoCapture::getLastFrame( uint64_t timeout_msec )
{
// ----> Wait for a new frame
uint64_t time_count = timeout_msec*10;
while( !mNewFrame )
{
if(time_count==0)
{
// const std::lock_guard<std::mutex> lock(mBufMutex);
// copyFrame(mLastFrameCopy, mLastFrame);
return mLastFrameCopy;
}
time_count--;
usleep(100);
}
// <---- Wait for a new frame
// Get the frame mutex
const std::lock_guard<std::mutex> lock(mBufMutex);
mNewFrame = false;
copyFrame(mLastFrameCopy, mLastFrame);
return mLastFrameCopy;
}
Declaration of Frame mLastFrameCopy
is also added to
zed-open-capture/include/videocapture.hpp
Line 489 in dfa0aee
And
if(mLastFrameCopy.data)
{
delete [] mLastFrameCopy.data;
mLastFrameCopy.data = nullptr;
}
is added to //deinint
in
zed-open-capture/src/videocapture.cpp
Line 186 in dfa0aee
Edit:
I commented out
const std::lock_guard<std::mutex> lock(mBufMutex);
copyFrame(mLastFrameCopy, mLastFrame);
in getLastFrame
before the timeout return, because the last frame has not changed.
from zed-open-capture.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment otherwise it will be automatically closed in 5 days
from zed-open-capture.
Related Issues (20)
- [Question] How to get the synchronized IMU and image data? HOT 13
- [Question] Cannot open camera video capture See verbosity level for more details. HOT 17
- Python version HOT 3
- Don't receive any IMU data sometimes HOT 2
- The type of IMU sensor used in ZED mini? HOT 1
- use with zed SDK HOT 1
- Is there any method to record SVO file without CUDA? HOT 1
- Two ZED 2i camera - Green hue in one half of the images HOT 12
- segfault when used as a library HOT 6
- missing cxxapi.h HOT 2
- Positional Tracking feature on CPU only HOT 1
- Support for ZED X and ZED X Mini? HOT 3
- Fixed HOT 1
- Inappropriate ioctl for device HOT 8
- Why only support one resolution option of VGA? HOT 2
- Availability of raw data HOT 2
- Sensor_example working but Fails to run the video_example on zed2i HOT 4
- Cannot open camera video capture for examples HOT 2
- zed_open_capture_depth_example not working HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zed-open-capture.