2016-05-09 23 views
2

これはなぜ動作しないのか理解できません。私は、ビデオファイルのためのウェブカメラを交換するときしかし、出力がビデオを生成しませんPython OpenCVオープニングWebカメラ対オープニングWebカメラ

import numpy as np 
import cv2 
cap = cv2.VideoCapture(0) 
# Define the codec and create VideoWriter object 
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) 
     # write the flipped frame 
     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() 

次のコードは完全に私のウェブカメラを使用して動作します。 output.aviという名前の5.7kbファイルだけ:

import numpy as np 
import cv2 
cap = cv2.VideoCapture('Input.avi') 
# Define the codec and create VideoWriter object 
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) 
     # write the flipped frame 
     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() 

ビデオが処理中だが保存されていないことがわかります。私はまた、最初のビデオファイルと一致するように解像度を変更しようとしました。

+0

whileループを完全にコメントアウトすると、どうしてもoutput.aviを開いたり閉じたりするとどうなりますか? – deets

答えて

0

私はUbuntuでのOpenCVを使用していて、これは私のために働いていた:それはWindows上で動作するかどう

out = cv2.VideoWriter("output.avi", cv.CV_FOURCC(*'DIVX'), fps, (640, 480)) 

を参照してください。

関連する問題