我从这个站点安装了OpenCV 3.3.0:https://www.pyimagesearch.com/2017/09/04/raspbian-stretch-install-opencv-3-python-on-your-raspberry-pi/

我正在使用此代码使用PS3相机保存视频,我收到以下错误:

AttributeError:'module'对象没有属性'VideoWriter_fourcc'我尝试使用模块相机Raspberry Pi 3 V2.1,我得到了同样的错误 .

import numpy as np
import cv2
import random
import time

def camara1():

cap = cv2.VideoCapture(1)

fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))

while(cap.isOpened()):
         ret, frame = cap.read()
         if ret==True:
             frame = cv2.flip(frame,0)

             out.write(frame)

             cv2.imshow('frame',frame)
             if cv2.waitKey(1) & 0xFF == ord('q'):
                 break
         else:
             break
#Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()
camara1()