我正在运行一个简单的程序来读取视频文件(.mp4格式)并在反转每一帧后将其写回。我收到错误和错误警告。
BUG: The current event queue and the main event queue are not the same. Events will not be handled correctly. This is probably because _TSGetMainThread was called for the first time off the main thread.
Error in CoreDragRemoveTrackingHandler: -1856
我正在使用El Captain OSX,我安装了python虚拟环境,使用Python 3.5和OpenCV 3.2.0-rc。有人可以帮我这个吗?
由于
import numpy as np
import cv2
cap = cv2.VideoCapture('Root.mp4')
# Define the codec and create VideoWriter object
#fourcc = cv2.VideoWriter_fourcc(*'AVRN')
#out = cv2.VideoWriter('Root1.mp4',fourcc, 20.0, (640,360))
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
out = cv2.VideoWriter('Root1.avi',fourcc, 20.0, (640,360))
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 :(得分:1)
似乎可以通过使用--with-ffmpeg标志重新安装opencv3来解决。
答案 1 :(得分:0)
我可以告诉你一件事,你在上面提到的脚本中没有问题:p,它在我的系统上正常运行。在新的虚拟环境中重新安装opencv和python。
答案 2 :(得分:0)
试试这个:
cap = cv2.VideoCapture(0)
fps = 15
capSize = (1280, 720)
#print cap.get(3)
#print cap.get(4)
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
out = cv2.VideoWriter('output.mov',fourcc, fps, capSize, True)
它对我有用,所以我希望它可以帮到你!