Giter Club home page Giter Club logo

Comments (4)

matanox avatar matanox commented on September 25, 2024

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
  1. 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?

  2. Is this very typical with many commodity hardware and platforms or backends, that a first grab is so slow?

  3. 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.

matanox avatar matanox commented on September 25, 2024

Please kindly relabel it as not 'bug' but 'question'.

from opencv.

Kumataro avatar Kumataro commented on September 25, 2024

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.

if (FirstCapture)
{
/* Some general initialization must take place the first time through */
/* This is just a technicality, but all buffers must be filled up before any
staggered SYNC is applied. SO, filler up. (see V4L HowTo) */
bufferIndex = -1;
for (__u32 index = 0; index < req.count; ++index) {
v4l2_buffer buf = v4l2_buffer();
v4l2_plane mplanes[VIDEO_MAX_PLANES];
buf.type = type;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = index;
if (V4L2_TYPE_IS_MULTIPLANAR(type)) {
buf.m.planes = mplanes;
buf.length = VIDEO_MAX_PLANES;
}
if (!tryIoctl(VIDIOC_QBUF, &buf)) {
CV_LOG_DEBUG(NULL, "VIDEOIO(V4L2:" << deviceName << "): failed VIDIOC_QBUF (buffer=" << index << "): errno=" << errno << " (" << strerror(errno) << ")");
return false;
}
}
if (!streaming(true)) {
return false;
}
// No need to skip this if the first read returns false
/* preparation is ok */
FirstCapture = false;
#if defined(V4L_ABORT_BADJPEG)
// skip first frame. it is often bad -- this is unnotied in traditional apps,
// but could be fatal if bad jpeg is enabled
if (!read_frame_v4l2())
return false;
#endif
}

from opencv.

matanox avatar matanox commented on September 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.