Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

camera lags when using with opencv

import threading
import cv2

# Define the thread that will continuously pull frames from the camera
class CameraBufferCleanerThread(threading.Thread):
    def __init__(self, camera, name='camera-buffer-cleaner-thread'):
        self.camera = camera
        self.last_frame = None
        super(CameraBufferCleanerThread, self).__init__(name=name)
        self.start()

    def run(self):
        while True:
            ret, self.last_frame = self.camera.read()

# Start the camera
camera = cv2.VideoCapture(0)

# Start the cleaning thread
cam_cleaner = CameraBufferCleanerThread(camera)

# Use the frame whenever you want
while True:
    if cam_cleaner.last_frame is not None:
        cv2.imshow('The last frame', cam_cleaner.last_frame)
    cv2.waitKey(10)
Comment

PREVIOUS NEXT
Code Example
Python :: making a python code without python 
Python :: graphics in python in repl 
Python :: double .get().get() dict python 
Python :: python nextcord bot slash command 
Python :: flask enumerate index 
Python :: insert QlineEdit into QMenu python 
Python :: pandas et numeric columns 
Python :: pandas filter and change value 
Python :: python list comprehension index, value 
Python :: how to install threading module in python 
Python :: colorama 
Python :: python elementtree build xml 
Python :: annaul sum resample pandas 
Python :: python temp directory 
Python :: browse list python 
Python :: count how many vowels in a string python 
Python :: pandas dataframe from multiple csv 
Python :: removing new line character in python from dataframe 
Python :: how to ask someone for their name in python 
Python :: matplotlib pie label size 
Python :: import matplotlib python 
Python :: rename coordinate netcdf python xarray 
Python :: python milliseconds to date 
Python :: python code to get all file names in a folder 
Python :: how to plotting points on matplotlib 
Python :: get hwid python 
Python :: count number of rows pandas condition 
Python :: zermelo python 
Python :: python exit program 
Python :: pandas rename column name 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =