Comments (4)
This may or may not then cause the frame rate to be less regular than it could, as the grab times are clearly not directly representing a steady frame-to-frame interval:
import time
import cv2
stream = cv2.VideoCapture(0)
stream.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))
stream.set(cv2.CAP_PROP_FPS, 30)
stream.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
stream.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
assert stream.isOpened()
before = time.monotonic_ns()
grabbed = stream.grab()
after = time.monotonic_ns()
frame_time = stream.get(cv2.CAP_PROP_POS_MSEC)
stream.retrieve()
assert frame_time == stream.get(cv2.CAP_PROP_POS_MSEC)
print(f'VideoCapture.grab took {int(after/1e6-before/1e6)} ms')
while True:
last_frame_time = frame_time
before = time.monotonic_ns()
stream.grab()
after = time.monotonic_ns()
stream.retrieve()
frame_time = stream.get(cv2.CAP_PROP_POS_MSEC)
print(f'VideoCapture.grab took {int(after / 1e6 - before / 1e6)} ms | '
f'the frame to frame interval is {int(frame_time - last_frame_time)} ms')
VideoCapture.grab took 466 ms
VideoCapture.grab took 28 ms | the frame to frame interval is 36 ms
VideoCapture.grab took 25 ms | the frame to frame interval is 31 ms
VideoCapture.grab took 26 ms | the frame to frame interval is 31 ms
VideoCapture.grab took 30 ms | the frame to frame interval is 36 ms
VideoCapture.grab took 26 ms | the frame to frame interval is 32 ms
VideoCapture.grab took 26 ms | the frame to frame interval is 31 ms
VideoCapture.grab took 30 ms | the frame to frame interval is 36 ms
VideoCapture.grab took 26 ms | the frame to frame interval is 32 ms
VideoCapture.grab took 26 ms | the frame to frame interval is 31 ms
VideoCapture.grab took 26 ms | the frame to frame interval is 36 ms
VideoCapture.grab took 30 ms | the frame to frame interval is 32 ms
VideoCapture.grab took 26 ms | the frame to frame interval is 31 ms
VideoCapture.grab took 30 ms | the frame to frame interval is 36 ms
VideoCapture.grab took 26 ms | the frame to frame interval is 32 ms
VideoCapture.grab took 26 ms | the frame to frame interval is 31 ms
VideoCapture.grab took 30 ms | the frame to frame interval is 35 ms
VideoCapture.grab took 26 ms | the frame to frame interval is 32 ms
VideoCapture.grab took 26 ms | the frame to frame interval is 31 ms
VideoCapture.grab took 30 ms | the frame to frame interval is 36 ms
-
As this seems to skew the ability to get a smooth evenly spaced in time stream reading at the expected set frame rate, can we get a steady frame-to-frame interval through some other technique? as opposed to the above where it's seen we get a 7-10% variance in the frame-to-frame interval?
-
Is this very typical with many commodity hardware and platforms or backends, that a first grab is so slow?
-
Can it be addressed or circumvented by somehow resetting the stream to restart on its cadence of the requested frame rate, after it getting past its first exponentially slow grab? or more likely does the UVC standard not define any capability like that?
from opencv.
Please kindly relabel it as not 'bug' but 'question'.
from opencv.
Hello, if you think this is Question not Bug, please could you close this issue and ask in Q&A forum ( https://forum.opencv.org/ ) ?
( I'm sorry but this is Question so I cannot reply with you more in here).
And some initilizing process are including first grab() calling. So first calling will be slower than next calling in logically.
opencv/modules/videoio/src/cap_v4l.cpp
Lines 1159 to 1198 in 1db6a8a
from opencv.
Well thanks for the code link anyway. I doubt anything in there takes 500 ms. Must be the camera's own initialization, but I was hoping for a more authoritative response than the staple forums replies which are always in the same style of "you cannot assume anything about X".
from opencv.
Related Issues (20)
- Sporadic failure at Layer_Einsum_Test.Accuracy_01D/1, where GetParam() = ({ 1 }, {}, "i,->i") HOT 1
- (.note.gnu.property+0x0): data is too short error during IPP linkage with NDK 27 for Android x86 HOT 5
- Parallel support for filter engine
- Add type handling to TopK layer
- fitEllipse returns a very far ellipse HOT 3
- Missing opencv_world4100.dll and opencv_world4100d.dll in Bin Folder during Extraction using GitHub Actions
- blobRectsToImageRects,This function has an error
- cv::HoughLinesProbabilistic segmentation fault hough.cpp:692 HOT 1
- error: ‘cvLoadImage’ was not declared in this scope HOT 1
- Crashes when dealing with large images
- C++ no includes on get-started page on OpenCV.org HOT 1
- Unable to build openCV on Windows HOT 9
- x86_64-linux-gnu/libwayland-client.so.0: undefined reference to `ffi_type_void@LIBFFI_BASE_7.0 HOT 1
- Python bindings do not respect optional modules HOT 1
- enable_language() is called prior project() in root CMakeLists.txt HOT 1
- Question about deploying ONNX model using OpenCV DNN and CUDA HOT 1
- Unable to compile opencv on Ubuntu18.04 HOT 2
- Failed onnx conformance tests on Hardmax on openvino backend
- Linking CXX executable ../../bin/opencv_test_videostab, error: 'GInferOutputs' in namespace 'cv' does not name a type
- Make proper layers implementations to support the new dnn engine in 5.x HOT 1
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 opencv.