简体   繁体   中英

Opencv: same capture code gives low FPS on a high-end laptop and high FPS on a TX1

I am unexpectedly getting a very low FPS (~16 fps) while capturing from the internal webcam (1280x720 @ 30fps) of a recent Dell XPS 9560.

This is the trivial code I'm using ( python3, OpenCV 3.4.0 )

import cv2, time

cam = cv2.VideoCapture(0)
n_frames = 0
execution_time = 0

while True:

    t_start = time.time()
    rv, frame = cam.read()
    n_frames+=1

    if rv:
        #also tried to comment imshow. Same FPS.
        cv2.imshow('window', frame)
        if cv2.waitKey(1) >= 0:
            break
        pass
    else:
        print('Cannot read Frame')

    t_end = time.time()

    execution_time += (t_end-t_start)*1000

    if execution_time > 10000:
        print ('avg FPS in 10 seconds: %.2f' % (n_frames*1000/execution_time))
        n_frames = 0
        execution_time = 0

I tried to write the same simple program in C++ and got the same result, the same ~16 FPS.

Occasionally, both the C++ and Python program can generate a higher FPS for a shorter amount of time.

By monitoring CPU usage with i7z, I could see that all 4 cores where running at a very low frequency, close to the minimum, for most of the time, with occasional spikes that seemed not to affect very much the average FPS.

I then transferred the exact same code to a Jetson TX1. For those who don't know it, it's an ARM-based system on a chip, running a dedicated Ubuntu 16.10. It is connected to an USB 2.0 camera, 1920x1080 @ 25fps.

Needless to say, I got exactly 25 FPS as expected.

Can anybody explain this behaviour? Is it something related to differences at operating system level?

How to get full FPS in any case?

Thanks for your help

EDIT: after VTT comment, I attached the same external (supposed 30 fps) USB camera to both systems, and I get 15 FPS on both. This points to crappy cameras/usb bus. I will need to dismantle the jetson device internal camera and connect it to the laptop to double-check this is camera-related.

I dropped this problem out of frustration only to discover its answer some days ago while I was chasing another one... I just had to turn on the lights to find the answer!

It turns out that my camera automatically lowers its FPS when in poor light condition. When you think about it, it may surely happen when the exposure time needs to be longer than the 1/30s.

So, in the end it looks like the 30fps should be intended as "Maximum fps=30". But it can and will be lower than that. Very annoying in my opinion, too bad I had to learn it the hard way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM