My video preview is lagging so bad, what's the problem?

Hello, I have problem that my video preview from cv2 is lagging around 2 fps even my webcam has 30 fps specification. And when I rendering my code, it needs more than 30 sec to respond. What’s the problem? My PC or anything else?

Thanks for help


print timestamps in your code at relevant points.

post your code, any data, the output including timestamps. also precisely describe all hardware that might be involved, certainly the make and model of your camera.

For my project, I use pyzbar module and this is my code

from cv2 import cv2
import numpy
from pyzbar.pyzbar import decode

#img = cv2.imread('12.jpg')
cap = cv2.VideoCapture(0)

while True:
    success, img =
    for barcode in decode(img):
        myData ='utf-8')
        pts = numpy.array([barcode.polygon],numpy.int32)
        pts = pts.reshape((-1,1,2))
        pts2 = barcode.rect


I use 2 camera actually in the same times. My Web camera is NYK A90 NEMESIS with specification 30 fps autofocus. there is no problem in normal use, but when I use to compile my code, i just get 1 frame per 2 sec. My PC has Intel Core i3 4th gen. Can you help me to solve this?

Thanks for helping me

(You don’t compile Rython code, you just run it…)
General debugging:

  • Use you success variable for its purpose: for deciding whether to do anything
    *Take off all barcode stuff to see if the problem is in capturing the frames of barcode decoding

…And then… Your waitKey waits 5000 ms for each frame…


Oh, my mistake :sweat_smile:
I dont know the purpose of waitkey actually haha. I’m newbie here so I’ll learn more. Sorry and thank you so much for your help

1 Like