使用OpenCv流式传输视频错误

时间:2018-05-15 08:53:21

标签: python opencv camera video-streaming

我对流式视频的opencv文件存在一些问题,我无法解决。当我运行命令$ python stream.py时,其中' strem.py'是文件'名称,这是结果:

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

VIDEOIO ERROR:

V4L: index 1 is not correct!
Traceback (most recent call last):
  File "stream.py", line 21, in <module>
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: OpenCV(4.0.0-pre) /home/andrimig/opencv/modules/imgproc/src/color.hpp:253: error: (-215:Assertion failed) VScn::contains(scn) && VDcn::contains(dcn) && VDepth::contains(depth) in function 'CvtHelper'

我该如何解决?我想用外置摄像头流式传输视频,而不是使用笔记本电脑摄像头。这是我的档案:

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

这是我论文的一个项目。

0 个答案:

没有答案