OpenC流式视频错误

2024-09-29 23:17:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一些问题与一个opencv文件流视频,我没有解决。当我运行命令$ python stream.py时,其中'strem.py公司'是文件名,这是结果:

andrimig@andrimig-X555LD:~$ python stream.py

^{pr2}$

我怎么解决这个问题?我想用外置摄像头流式视频,而不是用笔记本电脑摄像头。这是我的档案:

import cv2
import numpy as np
import sys

sys.path.append('/home/andrimig/opencv/build/lib')

# Playing video from file:
# cap = cv2.VideoCapture('vtest.avi')
# Capturing video from webcam:
cap = cv2.VideoCapture(1)

currentFrame = 0
while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Handles the mirroring of the current frame
    frame = cv2.flip(frame,1)

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Saves image of the current frame in jpg file
    # name = 'frame' + str(currentFrame) + '.jpg'
    # cv2.imwrite(name, frame)

    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

    # To stop duplicate images
    currentFrame += 1

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

这是我论文的一个专题。在


Tags: thefrompyimportstream视频videosys

热门问题