Warm tip: This article is reproduced from serverfault.com, please click

其他-如何使用 OpenCV Beta 3.0.0 和 Python 并排显示多个网络摄像头源?

(其他 - How do I display multiple webcam feeds side by side using OpenCV Beta 3.0.0 and Python?)

发布于 2015-02-22 21:52:45

我正在开展一个项目,该项目要求我并排显示 3 个(可能更多)网络摄像头馈送。为了解决这个项目,我使用 OpenCV Beta 3.0.0 和 Python 2.7.5,因为我对这门语言有点熟悉。另外,如何以彩色显示视频?

这是我当前的代码:

import cv2
import numpy as np

capture = cv2.VideoCapture(0)
capture1 = cv2.VideoCapture(1)

while True:
    ret, frame = capture.read()

    gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)

    cv2.imshow("frame",gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
capture.release()
cv2.destroyAllWindows()
Questioner
Christian Ermann
Viewed
11
chris 2015-02-23 06:13:05
import cv2
import numpy as np

capture = cv2.VideoCapture(0)
capture1 = cv2.VideoCapture(1)

while True:
    _, frame1 = capture.read()
    _, frame2 = capture1.read()
    frame1 = cv2.cvtColor(frame1,cv2.COLOR_BGR2RGB)
    frame2 = cv2.cvtColor(frame2,cv2.COLOR_BGR2RGB)
    cv2.imshow("frame1",frame1)
    cv2.imshow("frame2",frame2)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
capture1.release()
capture2.release()
cv2.destroyAllWindows()

要显示颜色,你只需不要转换为灰度。要同时显示两个帧,只需调用imshow()两次。至于并排,如果你真的想要,你可以玩框架位置。另请注意,我将帧从 BGR 转换为 RGB。