import numpy as np
import cv2
cap = cv2.VideoCapture(0)
fourcc = cv2.cv.CV_FOURCC(*'XVID')
out = cv2.VideoWriter('drop.avi', fourcc, 20.0, (640,480))
while cv2.VideoCaptured('drop.avi') is True:
# Captures frame x frame
ret , frame = cap.read()
#Frame operations
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
name = "frame%d.jpg"%count #saves frames and a JPEG image file
cv2.imwrite(name, frame)
#Display the resulting frame
cv2.imshow('frame', gray)
if cv2.waitKey(30):`enter code here`
break
cv.VideoCapture.release()
当我希望代码严格读取文件而不是从我的网络摄像头读取视频时。我知道我需要删除cap = cv2.VideoCpature(0)
。但是,我收到错误'module' object has no attribute 'VideoCapture'
.这段代码来自官方的OpenCV教程,所以我不确定问题是什么。我的猜测是某些内容不在正确的文件夹中。
在视频中阅读的正确代码片段是:
cap = cv2.VideoCapture(PATH_VIDEO)
cap.open(PATH_VIDEO)
print cap.isOpened()
while(cap.isOpened()):
ret, frame = cap.read()
frame = cv2.resize(frame, (frame.shape[1]/3, frame.shape[0]/3))