opencv 打开cv python无法打开视频

6mw9ycah  于 2022-11-24  发布在  Python
关注(0)|答案(1)|浏览(182)
import cv2
cap=cv2.VideoCapture(0)
filename="C://Users//deniz//Desktop//cfg13131lol.avi"
codec= cv2.VideoWriter_fourcc("W", "M", "V", "2")
frameRate=30
resolution=(600,600)
videoFileOutput=cv2.VideoWriter(filename, codec, frameRate, resolution)
while True:
    red,frame=cap.read()
    cv2.imshow("webcam.",frame)
    frame = cv2.flip(frame,-1)
    if cv2.waitKey(1)& 0xFF == ord("q"):
        break
videoFileOutput.release
cap.release
cv2.destroyAllWindows

路径是正确的,但当我试图打开它说“0xc10100be”。我尝试了mp4 avi等。

jv4diomz

jv4diomz1#

你在哪里写的框架内的循环。?,看起来你错过了这一行。内的循环。

videoFileOutput.write(frame)

将此行添加到循环内。

import cv2
cap=cv2.VideoCapture(0)
filename="C://Users//deniz//Desktop//cfg13131lol.avi"
codec= cv2.VideoWriter_fourcc("W", "M", "V", "2")
frameRate=30
resolution=(600,600)
videoFileOutput=cv2.VideoWriter(filename, codec, frameRate, resolution)
while True:
    red,frame=cap.read()
    cv2.imshow("webcam.",frame)
    frame = cv2.flip(frame,-1)
    videoFileOutput.write(frame)

    if cv2.waitKey(1)& 0xFF == ord("q"):
        break
videoFileOutput.release
cap.release
cv2.destroyAllWindows

相关问题