Horje
camera lags when using with opencv Code Example
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)




Python

Related
RuntimeWarning: invalid value encountered in true_divide Code Example RuntimeWarning: invalid value encountered in true_divide Code Example
is there a python command that clears the output Code Example is there a python command that clears the output Code Example
call materialized view in django postgres Code Example call materialized view in django postgres Code Example
how to get index of week in list in python Code Example how to get index of week in list in python Code Example
python locks Code Example python locks Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
6