Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ffmpeg
- import sys
- import cv2
- import numpy as np
- from matplotlib import pyplot as plt, patches
- import os
- try:
- def main():
- path = 'figures'
- for i in range(5):
- _fig, ax = plt.subplots()
- x = range(3 * i)
- y = [n * n for n in x]
- ax.add_patch(patches.Rectangle(xy=(i, 1), width=1, height=10))
- plt.step(x, y, linewidth=3, where="mid")
- out = 'fig_{}.png'.format(i)
- dest = os.path.join(path, out)
- plt.savefig(dest)
- plt.clf()
- print("Just about done!")
- main()
- cap = cv2.VideoCapture(0)
- if(cap.isOpened() == False):
- print("Cannot get the video feed!")
- frame_width = int(cap.get(5))
- frame_height = int(cap.get(5))
- out = cv2.VideoWriter("outs.mpg", cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), 10, (frame_width, frame_height))
- while(True):
- ret, frame = cap.read()
- if ret == True:
- out.write(frame)
- else:
- break
- #cap.release()
- #out.release()
- #cv2.destroyAllWindows()
- def read_frame_as_jpeg(out, err):
- out, err = (
- ffmpeg
- .input("outs.mpg3")
- .filter('select', 'gte(n,{})'.format(40))
- .output('pipe:', vframes=1, format='image2', vcodec='mjpeg')
- .run(capture_stdout=True)
- )
- return out
- cap.release()
- out.release()
- cv2.destroyAllWindows()
- except KeyboardInterrupt:
- print("Peace!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement