Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

capturing-video-from-two-cameras-in-opencv-at-once

import cv2
import threading

class camThread(threading.Thread):
    def __init__(self, previewName, camID):
        threading.Thread.__init__(self)
        self.previewName = previewName
        self.camID = camID
    def run(self):
        print("Starting " + self.previewName)
        camPreview(self.previewName, self.camID)

def camPreview(previewName, camID):
    cv2.namedWindow(previewName)
    cam = cv2.VideoCapture(camID)
    if cam.isOpened():
        rval, frame = cam.read()
    else:
        rval = False

    while rval:
        cv2.imshow(previewName, frame)
        rval, frame = cam.read()
        key = cv2.waitKey(20)
        if key == 27:  # exit on ESC
            break
    cv2.destroyWindow(previewName)

# Create threads as follows
thread1 = camThread("Camera 1", 0)
thread2 = camThread("Camera 2", 1)
thread3 = camThread("Camera 3", 2)

thread1.start()
thread2.start()
thread3.start()
print()
print("Active threads", threading.activeCount())
Comment

PREVIOUS NEXT
Code Example
Python :: callbacks to function pysimplegui 
Python :: convert outlook email to text file python 
Python :: python von konsoleeinlesen 
Python :: discord.py embed length greater than 1024 
Python :: numpy rolling 2d 
Python :: salir programa python 
Python :: numpy count occurrences in interval array 
Python :: how tofind records between two values in pyspark 
Python :: styling filter form django 
Python :: Drip bucket limiter python 
Python :: python split clever looping 
Python :: i=int(input("enter the number")); sum=0; pro=1; while(i0): d=1%10; if (d%2==0): sum=sum+d; else: pro=pro*d; i=i//10; print("sum=",sum,"product=",pro); 
Python :: python thunks 
Python :: Solution to Remove Recursion Limitation in python 
Python :: dataproc initialization_actions error 
Python :: micropython button interrups 
Python :: chrome drivers documentation 
Python :: what is a good django orm cookbook 
Python :: python list all youtube channel videos 
Python :: save impt 
Python :: PHP echo multiple lines example Using Heredoc 
Python :: python why is it important to check the __name__ 
Python :: off-by-one error in python 
Python :: create matrix with complex python 
Python :: how to send one variable to python using xlwings 
Python :: numpy.where() for substring 
Python :: float python precision 
Python :: date component 
Python :: predict probabilities with xg boost 
Python :: Half String 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =