Git Product home page Git Product logo

Comments (15)

gy29289957 avatar gy29289957 commented on September 28, 2024 1

You can adjust the input image resolution in Webcam class

class Webcam(FramesSource):
"""Webcam frame grabbing and preprocessing."""

def __init__(self, camera_id=0, fps=60, w=1280, h=720, **kwargs):
    """Create queues and threads to read and preprocess data."""
    self._short_name = 'Webcam'

    self._capture = cv.VideoCapture(camera_id)
    self._capture.set(cv.CAP_PROP_FRAME_WIDTH, w)
    self._capture.set(cv.CAP_PROP_FRAME_HEIGHT, h)
    self._capture.set(cv.CAP_PROP_FOURCC, cv.VideoWriter_fourcc(*'MJPG'))
    self._capture.set(cv.CAP_PROP_FPS, fps)

or use another face detection to replace dlib

from gazeml.

filyp avatar filyp commented on September 28, 2024 1

For me, reducing the resolution helped, just as @gy29289957 said.

Other option is to keep the same resolution, but decrease fps. Unfortunately, --fps option doesn't work for me. I don't know if it falis in general, or it's just specific to my webcam. I ended up using this stupid hack:

def frame_generator(self):
        """Read frame from webcam."""
        while True:
            ret, bgr = self._capture.read()
            ret, bgr = self._capture.read()
            if ret:
                yield bgr

Which isn't elegant but was enough for me. The duplicated self._capture.read() causes frame_generator to skip every other frame, which in practice gives 30fps.

from gazeml.

meysam-safarzadeh avatar meysam-safarzadeh commented on September 28, 2024

hello,
How can I fix the lag when running realtime on webcam, I implement it by GPU and cuda10 & Cudnn, but it has a periodic lag that I think its because of the program problem,
thanks to anyone can help me

from gazeml.

keishatsai avatar keishatsai commented on September 28, 2024

I also got exactly the same problem, when I test on video. However, I saved result afterward, I can check it later. Have you tried --from_video, too?

from gazeml.

meysam-safarzadeh avatar meysam-safarzadeh commented on September 28, 2024

I also got exactly the same problem, when I test on video. However, I saved result afterward, I can check it later. Have you tried --from_video, too?

No, actually my need is running realtime

from gazeml.

keishatsai avatar keishatsai commented on September 28, 2024

Have you try to adjust "--fps" ? or what kind of lag is it? Does it lag in certain pattern, like after every 60 frames will lag? Author did a batch result during inference. Maybe this is the reason. You can edit the code without batch output.

from gazeml.

meysam-safarzadeh avatar meysam-safarzadeh commented on September 28, 2024

Have you try to adjust "--fps" ? or what kind of lag is it? Does it lag in certain pattern, like after every 60 frames will lag? Author did a batch result during inference. Maybe this is the reason. You can edit the code without batch output.

I tried "--fps" but didn't work, yeah it lags in a certain pattern but I don't know how can I disable the batch output.

could u help me with that?!

from gazeml.

keishatsai avatar keishatsai commented on September 28, 2024

@meysam97
Currently, haven't got time to look into this.
If you have already solved, please share with us.
Thank you.

from gazeml.

swook avatar swook commented on September 28, 2024

from gazeml.

saksham16085 avatar saksham16085 commented on September 28, 2024

The lag still persists. The lag actually happens in multiples of 60 frames. Is this lag related to the batch inference?

from gazeml.

hoangthang1607 avatar hoangthang1607 commented on September 28, 2024

You can comment these lines of _record_frame() function, it will solve the problem:

                    #now_time = time.time()
                    #if last_frame_time is not None:
                    #    time_diff = now_time - last_frame_time
                    #    while time_diff > 0.0:
                    #        video_out.write(frame)
                    #        time_diff -= out_frame_interval
                    #last_frame_time = now_time

from gazeml.

filyp avatar filyp commented on September 28, 2024

@hoangthang1607
Didn't help for me

from gazeml.

funkfuzz avatar funkfuzz commented on September 28, 2024

I am getting the same issue. Did anyone of you people find a solution to it? Commenting the lines mentioned by @hoangthang1607 didn't work for me.

from gazeml.

funkfuzz avatar funkfuzz commented on September 28, 2024

I managed to solve my problem as well. I built dlib from source with cuda enabled and managed to eliminate the bottleneck and got steady 23 fps. I then downloaded the tensorflow-gpu instead of the cpu version and managed to boost the speed up to steady 30 fps.

from gazeml.

Hyrtsi avatar Hyrtsi commented on September 28, 2024

I, too, have to problem with a powerful PC, Ubuntu 20.04, tf 1.14, CUDA 11.

It sometimes gets a weird lag peak even though mostly it's running with nice stable 30fps. Maybe the program is doing some heavy operations such as copying stuff to queue, moving them in memory or saving things on disk.

from gazeml.

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.