python - 使用 cv2 时如何 'mirror' 实时网络摄像头视频?

标签 python cv2

我想要两个不同的网络摄像头视频输出,一个是普通的网络摄像头镜头,另一个是它的“镜像”版本。 cv2可以吗?

import time, cv2


video=cv2.VideoCapture(0)
a=0
while True:
    a=a+1
    check, frame= video.read()

    gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow("Capturing",gray)

    key=cv2.waitKey(1)

    if key==ord('q'):
        break
print(a)

video.release()
cv2.destroyAllWindows

最佳答案

简而言之,是的,可以使用 cv2。我对您的代码进行了一些修改以使其发生。

# Loading modules
import cv2
import numpy as np     # Numpy module will be used for horizontal stacking of two frames

video=cv2.VideoCapture(0)
a=0
while True:
    a=a+1
    check, frame= video.read()

    # Converting the input frame to grayscale
    gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)   

    # Fliping the image as said in question
    gray_flip = cv2.flip(gray,1)

    # Combining the two different image frames in one window
    combined_window = np.hstack([gray,gray_flip])

    # Displaying the single window
    cv2.imshow("Combined videos ",combined_window)
    key=cv2.waitKey(1)

    if key==ord('q'):
        break
print(a)

video.release()
cv2.destroyAllWindows

希望你得到你想要的:)

关于python - 使用 cv2 时如何 'mirror' 实时网络摄像头视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56474278/

相关文章:

python-3.x - 无法使用 OpenCV2 检测面部标志

python - 在任何地方用另一个替换一个 python 对象

python - 从具有非数字索引的数据框中删除行

python - 为梯度直方图获取 0 到 180 之间无符号角度的正确方法

opencv - 使用Opencv将JPG转换为TIFF

python-3.x - Asyncio Queue 等待直到它已满,然后才会返回某些内容

python - 打印 numpy 数组的全部内容

Python 2.0 将 -9/4 给出为 -3?不应该是-2吗?

Python - 输入标签内正则表达式中的转义引号

python - 如何测量独特 ROI 中的 RGB 均值?