Ask Your Question

jj364's profile - activity

2020-03-16 06:28:34 -0600 received badge  Popular Question (source)
2017-07-06 03:03:31 -0600 commented question Gaining high frame rate from ELP camera (python)

I decided to upgrade to OpenCV 3 and this has made all the difference. Frame rate immediately rose greatly. Thanks for all your help, Berak.

2017-07-05 05:07:07 -0600 commented question Gaining high frame rate from ELP camera (python)

Ah ok. So this is causing the bottleneck? Is there any method to use to improve the frame rate?

2017-07-05 04:48:20 -0600 commented question Gaining high frame rate from ELP camera (python)

In the demo I'm doing absolutely nothing with them. I had assumed that because (most of the time) when a frame is requested None is returned that the requests are coming in far faster than the camera can output them and therefore the queue never has more than one frame on it.

2017-07-05 04:27:20 -0600 received badge  Editor (source)
2017-07-05 04:27:01 -0600 commented question Gaining high frame rate from ELP camera (python)

I'm struggling to get the embedded code to format, sorry.

2017-07-05 04:26:59 -0600 asked a question Gaining high frame rate from ELP camera (python)

I'm using an ELP USB camera that is supposedly rated at 100fps at 640x480 quality but I don't seem to be getting anywhere near that frame rate. I was wondering if anyone has used an ELP camera with openCV and managed to achieve a frame rate close to 100 fps? Or if anyone has any advice to help increase the frame rate? I am using Ubuntu 14.04 with openCV version 2.4.8.

I have already tested that the output is MJPEG at 640x420 and I am running cv2.VideoCapture in one thread and placing the frame on a queue. From the main thread I repeatedly ask for frames but only return when the results is not None. This gives a frame rate hovering around 30fps. One I have the image I am performing contour detection but essentially I would like to get the frame rate up as high as possible. Below is the code I'm using just to test the frame rate.

import cv2
import time
import numpy as np
from datetime import datetime
from threading import Thread, Lock, Condition
import time
from Queue import Queue

class WebcamVideoStream:

def __init__(self, src=0):
    # initialize the video camera stream 
    self.stream = cv2.VideoCapture(src)
    # initialize the variable used to indicate if the thread should
    # be stopped
    self.stopped = False
    self.frame = None

def start(self):
    global qt
    self.stopped = False
    qt = Queue(10)
    # start the thread to read frames from the video stream
    thread1 = Thread(target=self.update, args=())
    thread1.start()
    return self

def update(self):
    global qt
    # keep looping infinitely until the thread is stopped
    while True:
        if self.stopped:
            return
        _, self.frame = self.stream.read()
        qt.put(self.frame)

def read(self):
    global qt
    if(not qt.empty()):
        self.CurrFrame=qt.get()
        if self.CurrFrame is not None:
            return self.CurrFrame
    if self.stopped:
        return

def stop(self):
    print('Stop')
    # indicate that the thread should be stopped
    self.stopped = True
    return self

vs = WebcamVideoStream(src=-1).start()
time.sleep(1)

i = 0
t0 = time.time()
while i < 100:
frame = vs.read()
while frame is None:
    frame = vs.read()
i = i + 1

rate = 100/(time.time()-t0)
print(rate)

cv2.destroyAllWindows()
vs.stop()

Thanks in advance