import cv2
import numpy as np
cap = cv2.VideoCapture('1.MP4')
fourcc = cv2.FOURCC(*'XVID')
out = cv2.videoWriter('output.avi',fourcc,20.0,(640,480))
while (1):
#Capture frame-by-frame
#ret = cap.set(3,960),cap.set(4,720)
ret, frame = cap.read()
if ret == True:
frame = cv2.flip(frame,0)
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
如上所示,这是opencv文档中的demo,在我的电脑上可以运行。像这样的回溯:
Traceback (most recent call last):
File "E:\opencv\Pic\test.py", line 34, in <module>
fourcc = cv2.cv.FOURCC(*'XVID')
AttributeError: module 'cv2.cv2' has no attribute 'cv'
Run Code Online (Sandbox Code Playgroud)
我还看到了一些解决方案,例如将 cv2.cv 更改为 cv2 ,而回溯如下:
Traceback (most recent call last):
File "E:\opencv\Pic\test.py", line …Run Code Online (Sandbox Code Playgroud)