I will use two webcams to process image on Raspberrypi3. I want to fix device video number to each camera. Because I need to know which camera is leftside or rightside. How to fix video numbers to each camera?
from collections import deque
import numpy as np
import argparse
import imutils
import cv2
import time
from multiprocessing import Process, Queue
class opencv:
def __init__(self):
self.FrameWidth = 1024
self.FrameHeight = 576
def rescale_frame(self, frame, percent=75):
width = int(frame.shape[1] * percent/ 100)
height = int(frame.shape[0] * percent/ 100)
dim = (width, height)
return cv2.resize(frame, dim, interpolation =cv2.INTER_AREA),width,height
def cam(self, video):
camera = cv2.VideoCapture(video)
camera.set(3, self.FrameWidth)
camera.set(4, self.FrameHeight)
while True:
(grab, frame) = camera0.read()
frame,width,height = self.rescale_frame(frame, percent=50) # pixcel 50%
cv2.imshow("Frame", frame)
key = cv2.waitKey(60) & 0xFF
if (key == 27):
break
if (key == ord('i')):
while True:
cv2.imshow("Frame", frame)
cv2.waitKey(0)
if key == ord('i'):
break
camera.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
cam0 = opencv()
cam1 = opencv()
p1 = Process(target = cam0.cam, args = (0,))
p2 = Process(target = cam1.cam, args = (1,))
p1.start()
p2.start()