def main(cameraNumber, camWidth, camHeight, outputFile): BUFFER_NAME = 'cloud3.avi' vs = VideoStream(fps=24, filename=BUFFER_NAME, framefill=True) disp = Display((camWidth, camHeight)) cam = Camera(cameraNumber, prop_set={"width": camWidth, "height": camHeight}) # while the user does not press 'esc' start_time = time() count = 0 while disp.isNotDone(): # KISS: just get the image... don't get fancy img = cam.getImage() print type(img) skimage.io.push(img) #img.show() # write the frame to videostream vs.writeFrame(img) # show the image on the display img.save(disp) current_time = time() if current_time-start_time>=5: outputFile = "testing_chunk_%d.mp4" % (count) print "Saving %s" % (outputFile) saveFilmToDisk(BUFFER_NAME, outputFile) start_time = time() count += 1
def main(cameraNumber, camWidth, camHeight, outputFile): BUFFER_NAME = 'motiontest.avi' # create the video stream for saving the video file #vs = VideoStream(fps=24, filename=fname, framefill=True) vs = VideoStream(fps=24, filename=BUFFER_NAME, framefill=True) # create a display with size (width, height) disp = Display((camWidth, camHeight)) # Initialize Camera cam = Camera(cameraNumber, prop_set={"width": camWidth, "height": camHeight}) # while the user does not press 'esc' while disp.isNotDone(): # KISS: just get the image... don't get fancy img = cam.getImage() #img.show() # write the frame to videostream vs.writeFrame(img) # show the image on the display img.save(disp) # Finished the acquisition of images now Transform into a film #self.makefilmProcess = Process(target=self.saveFilmToDisk, args=(BUFFER_NAME, outputFile)) #self.makefilmProcess.start() saveFilmToDisk(BUFFER_NAME, outputFile)
def recordVideo(self, cb, topic, length=5): global BUFFER_NAME BUFFER_NAME = topic + '_' + time.strftime("%Y_%m_%d_%H_%M_%S") + '.avi' vs = VideoStream(fps=24, filename=BUFFER_NAME, framefill=True) self.disp = Display((self.width, self.height)) cam = Camera(1, prop_set={"width":self.width,"height":self.height}) while self.continueRecord: gen = (i for i in range(0, 30 * length) if self.continueRecord) for i in gen: img = cam.getImage() vs.writeFrame(img) img.save(self.disp) self.continueRecord = False print "Broke capture loop" self.disp.quit() print "Saving video" # This is to run this process asynchronously - we will skip that # self.makefilmProcess = Process(target=saveFilmToDisk, args=(BUFFER_NAME, self.videoTitle)) # self.makefilmProcess.start() # Callback function cb()
def main(self): jc = JpegStreamCamera( "http://192.168.1.101/videostream.cgi?user=pi&pwd=pi") vs = VideoStream("MyVideo2.avi", 25, True) for i in range(0, 35): print "loop" img = jc.getImage() print "gotimg" imgName = "img/img_%s.jpg" % (i) self.makeSaveImg = Process(target=self.saveImgToDisk, args=(img, imgName)) self.makeSaveImg.start() #self.saveImgToDisk(img,imgName) vs.writeFrame(img) print i print "----------" #self.makefilmProcess = Process(target=self.saveFilmToDisk, args=("MyVideo2.avi", "MyoutputFile.mpeg")) #self.makefilmProcess.start() params = " -i {0} -c:v mpeg4 -b:v 700k -r 24 {1}".format( "MyVideo2.avi", "MyoutputFile.avi") # run avconv to compress the video since ffmpeg is deprecated (going to be). call('avconv' + params, shell=True)
def main(cameraNumber, camWidth, camHeight, outputFile): BUFFER_NAME = 'buffer.avi' # create the video stream for saving the video file vs = VideoStream(fps=24, filename=BUFFER_NAME, framefill=True) # create a display with size (width, height) disp = Display((camWidth, camHeight)) # Initialize Camera cam = Camera(cameraNumber, prop_set={"width": camWidth, "height": camHeight}) # while the user does not press 'esc' while disp.isNotDone(): # KISS: just get the image... don't get fancy img = cam.getImage() # write the frame to videostream vs.writeFrame(img) # show the image on the display img.save(disp) # Finished the acquisition of images now Transform into a film makefilmProcess = Process(self.saveFilmToDisk, args=(BUFFER_NAME, outputFile)) makefilmProcess.start() def saveFilmToDisk(self, bufferName, outname): # construct the encoding arguments params = " -i {0} -c:v mpeg4 -b:v 700k -r 24 {1}".format(bufferName, outname) # run avconv to compress the video since ffmpeg is deprecated (going to be). call('avconv'+params, shell=True)
def main(cameraNumber, outputFile): BUFFER_NAME = 'ipython1.avi' # create the video stream for saving the video file #vs = VideoStream(fps=24, filename=fname, framefill=True) #vs = VideoStream(fps=24, filename=BUFFER_NAME, framefill=True) vs=VideoStream(filename=BUFFER_NAME) # create a display with size (width, height) disp = Display() # Initialize Camera cam = Camera(cameraNumber) time_start=time.time() # while the user does not press 'esc' while time.time()-time_start<10: # Finally let's starte # KISS: just get the image... don't get fancy img = cam.getImage() #img.show() # write the frame to videostream vs.writeFrame(img) # show the image on the display img.save(disp) # Finished the acquisition of images now Transform into a film #self.makefilmProcess = Process(target=self.saveFilmToDisk, args=(BUFFER_NAME, outputFile)) #self.makefilmProcess.start() saveFilmToDisk(BUFFER_NAME, outputFile)
def recordVideo(self, length=5): BUFFER_NAME = 'buffer.avi' vs = VideoStream(fps=24, filename=BUFFER_NAME, framefill=True) self.disp = Display((self.width, self.height)) cam = Camera(prop_set={"width":self.width,"height":self.height}) while self.continueRecord: gen = (i for i in range(0, 30 * length) if self.continueRecord) for i in gen: img = cam.getImage() vs.writeFrame(img) img.save(self.disp) self.continueRecord = False print "Broke capture loop" self.disp.quit() print "Saving video"
def write_video(video_len): buffer_video_name = "{}.avi".format(get_buffer_name()) output_file_name = "{}.mp4".format(get_current_time()) vs = VideoStream(filename=buffer_video_name) delay = 1.0 / 25 current_video_len = 0 while current_video_len < video_len: if stop_lock.locked(): break img = capture_image() sleep(delay) vs.writeFrame(img) current_video_len = vs.framecount / 25 convert_to_mp4(buffer_video_name, output_file_name) remove(buffer_video_name)
def main(self): jc = JpegStreamCamera("http://192.168.1.101/videostream.cgi?user=pi&pwd=pi") vs = VideoStream("MyVideo2.avi",25, True) for i in range(0,35): print "loop" img = jc.getImage() print "gotimg" imgName = "img/img_%s.jpg"%(i) self.makeSaveImg = Process(target=self.saveImgToDisk, args=(img,imgName)) self.makeSaveImg.start() #self.saveImgToDisk(img,imgName) vs.writeFrame(img) print i print "----------" #self.makefilmProcess = Process(target=self.saveFilmToDisk, args=("MyVideo2.avi", "MyoutputFile.mpeg")) #self.makefilmProcess.start() params = " -i {0} -c:v mpeg4 -b:v 700k -r 24 {1}".format("MyVideo2.avi", "MyoutputFile.avi") # run avconv to compress the video since ffmpeg is deprecated (going to be). call('avconv'+params, shell=True)
def main(cameraNumber, camWidth, camHeight, outputFile): BUFFER_NAME = 'Trial3.avi' images = [] icount = 0 img = None START_OF_IMAGES = 0 # create the video stream for saving the video file #vs = VideoStream(fps=FRAMES_PER_SECOND, filename=fname, framefill=True) #vs = VideoStream(fps=FRAMES_PER_SECOND, filename=BUFFER_NAME, framefill=True) # Do this for the buffer? # USING fps=240/3=80 which is what I see on my computer. vs = VideoStream(fps=FPS_IN_LOOP, filename=BUFFER_NAME, framefill=False) # create a display with size (width, height) disp = Display((camWidth, camHeight)) # Initialize Camera cam = Camera(cameraNumber, prop_set={"width": camWidth, "height": camHeight}) previous = cam.getImage() # Grab a first image for comparison. time_start=time.time() # while the user does not press 'esc' no_motion = True recording_after_trigger = False #while time.time()-time_start<SECONDS_TO_RECORD: recorded_time_after_trigger = False while 1: # Finally let's started # KISS: just get the image... don't get fancy img = cam.getImage() # show the image on the display #img.save(disp) #''' #if icount<FRAMES_PER_SECOND*SECONDS_TO_RECORD: #if 1: if icount<MYBUFFER_LEN: #print icount images.append(img.copy()) else: #print icount START_OF_IMAGES = icount%MYBUFFER_LEN images[START_OF_IMAGES] = img.copy() #''' diff = img - previous matrix = diff.getNumpy() mean = matrix.mean() diff.show() #print icount,mean if mean>THRESHOLD and icount>20: no_motion = False recording_after_trigger = True if not recording_after_trigger: time_start = time.time() #''' if time.time()-time_start>SECONDS_TO_RECORD: break #''' print icount,no_motion,recorded_time_after_trigger,recording_after_trigger,time_start previous = img icount += 1 # Finished the acquisition of images now Transform into a film # Pulling the images out of our list and putting them into the BUFFER #''' print "Processing the images." nimages = len(images) print nimages for i in range(START_OF_IMAGES,START_OF_IMAGES+nimages): #i.save(disp) myindex = i print myindex if i>=nimages: myindex = i-nimages vs.writeFrame(images[myindex]) #''' saveFilmToDisk(BUFFER_NAME, outputFile)
#!/usr/bin/env python import os from time import sleep from SimpleCV import VideoStream from utils import PreparedCamera # Settings cam_size = {'width': 320, 'height': 240} vid_fps = 15 file_name = os.path.join('pictures', 'video.avi') cam = PreparedCamera(0, cam_size, debug=True) print("Recording video") vid = VideoStream(file_name, fps=vid_fps) for frame in range(0, vid_fps * 10): img = cam.getImage() vid.writeFrame(img) sleep(1.0/vid_fps)
from SimpleCV import JpegStreamer, Display, VirtualCamera, VideoStream import time import numpy as np cam = VirtualCamera( '../Recording/Videos/Flying kite images (for kite steering unit development)-YTMgX1bvrTo.flv', 'video') port = 8000 + np.random.randint(100) print port js = JpegStreamer(hostandport=port, st=0.1) vs = VideoStream("out.avi", fps=15) endReached = False t0 = time.time() FPS = 25 while not (endReached): t = time.time() - t0 toDisplay = cam.getFrame(np.ceil(t * FPS)) if toDisplay.size() != (0, 0): toDisplay.save(js) else: endReached = True time.sleep(0.05)
def main(cameraNumber, camWidth, camHeight, outputFile): BUFFER_NAME = "Trial3.avi" images = [] icount = 0 img = None # create the video stream for saving the video file # vs = VideoStream(fps=FRAMES_PER_SECOND, filename=fname, framefill=True) # vs = VideoStream(fps=FRAMES_PER_SECOND, filename=BUFFER_NAME, framefill=True) # Do this for the buffer? # USING fps=240/3=80 which is what I see on my computer. vs = VideoStream(fps=80, filename=BUFFER_NAME, framefill=False) # create a display with size (width, height) disp = Display((camWidth, camHeight)) # Initialize Camera cam = Camera(cameraNumber, prop_set={"width": camWidth, "height": camHeight}) time_start = time.time() # while the user does not press 'esc' while time.time() - time_start < SECONDS_TO_RECORD: # Finally let's started # KISS: just get the image... don't get fancy img = cam.getImage() # img.show() # write the frame to videostream # vs.writeFrame(img) # show the image on the display img.save(disp) #''' # if icount<FRAMES_PER_SECOND*SECONDS_TO_RECORD: # if 1: if icount < 200: # print icount images.append(img.copy()) else: # print icount images[icount % 200] = img.copy() #''' icount += 1 # Finished the acquisition of images now Transform into a film # Pulling the images out of our list and putting them into the BUFFER #''' print "Processing the images." print len(images) for i in images: # print i # i.save(disp) vs.writeFrame(i) #''' saveFilmToDisk(BUFFER_NAME, outputFile)
The first time you run the script you will need to authorize googlecl to use your account. ffmpeg can be found here http://www.ffmpeg.org/ see the ffmpeg website for installation instructions """ fname = 'test.avi' outname = 'output.mp4' tags = 'SimpleCV, Computer Vision, Python' title = "SimpleCV Output" summary = "See http://simplecv.org for more info." access = "public" # Options are "public" "private" "protected" # create the video stream for saving the video file vs = VideoStream(fps=20, filename=fname, framefill=False) # grab the camera cam = Camera() # create a display disp = Display((800, 600)) # while the user does not press 'esc' while disp.isNotDone(): # YOUR CODE GOES HERE! img = cam.getImage() img = img.edges() # write the frame vs.writeFrame(img) # save the image to the display img.save(disp) # construct the encoding arguments params = " -i {0} {1}".format(fname, outname)
The first time you run the script you will need to authorize googlecl to use your account. ffmpeg can be found here http://www.ffmpeg.org/ see the ffmpeg website for installation instructions """ fname = 'test.avi' outname = 'output.mp4' tags = 'SimpleCV, Computer Vision, Python' title = "SimpleCV Output" summary = "See http://simplecv.org for more info." access = "public" # Options are "public" "private" "protected" # create the video stream for saving the video file vs = VideoStream(fps=20,filename=fname,framefill=False) # grab the camera cam = Camera() # create a display disp = Display((800,600)) # while the user does not press 'esc' while disp.isNotDone(): # YOUR CODE GOES HERE! img = cam.getImage() img = img.edges() # write the frame vs.writeFrame(img) # save the image to the display img.save(disp) # construct the encoding arguments params = " -i {0} {1}".format(fname,outname)