如何为摄像机分配固定编号

时间:2018-07-23 15:21:36

标签: python raspberry-pi3 webcam

enter image description here

我将使用两个网络摄像头来处理Raspberrypi3上的图像。我想将设备视频号固定到每个摄像机。因为我需要知道哪个摄像机位于左侧或右侧。如何为每个摄像机固定视频编号?

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()

1 个答案:

答案 0 :(得分:0)

通常,您不能使用openCV和USB网络摄像头。操作系统会以未知顺序找到它们-通常是它们启动的顺序。您可以尝试将它们与切换式USB集线器连接,然后以相同的顺序打开它们,彼此之间只有几秒钟的延迟。

除非有一些每个摄像机的序列号,您可以直接阅读。