3

I have been using my raspberry pi and working with the camera module. The lowest time taken by regular raspistill to capture a single image is about 900ms. I use the picamera python interface with video-port set & use camera_sequence function for format = jpeg the time to capture a frame comes down to 80 ms & 30 ms for yuv. Now the project that i am working on requires the time taken to capture a single frame to be at 10ms at least. I know that its possible if we put our raw image data on RAM (possibly the bayers data). Any ideas on how it can be done?

import io
import time
import picamera
import cv2

with picamera.Picamera() as camera:
    camera.resolustion = (750 , 150)
    camera.framerate = 80
    time.sleep(2)
    camera.shutter_speed = 400
    outputs = [io.BytesIO]
    start = time.time()
    camera.capture_sequence(outputs , 'jpeg' , use_video_port=True)
    finish = time.time()
    print(finish-start)
0

1 Answer 1

1

There are two ways to make it really fast.

1 Use Asynchronous programming with AsynchIO to create separate process to shoot another photo while you still save the first one. Would be like

##Move those to some other function, preferably main
time.sleep(2) 
camera.shutter_speed = 400
##

outputs = [io.BytesIO] 
start = time.time() 

#Create i such processes:
def somefunction(semaphore)
    semaphore.Acquire() #Precreated semaphore get's taken by our process or process waits to be released
    camera.capture_sequence(outputs ,'jpeg' , use_video_port=True)
    #finish = time.time() print(finish-start)#Unneeded
    # Enable another process here
    semaphore.Release()
    # Do whatever you like here, time is not of the essence here (but be memory wise! it is limited in raspi!)

Should be pretty quick

2 Recursion could be the other solution

def somefunction(anchor, sequence)
    if sequence <= anchor :
        camera.capture_sequence(outputs ,'jpeg' , use_video_port=True)
        somefunction(anchor, sequence +1)
        #Save, or whatever, your photo here, be cautious about setting too large anchor, it might hang.

link to recursion

[EDIT1] Function should be placed like this:

with picamera.Picamera() as camera:
camera.resolustion = (750 , 150) 
camera.framerate = 80 
time.sleep(2) 
camera.shutter_speed = 400 
outputs = [io.BytesIO]
def function_taking_photo_as_short_as_possible_!_!_!(somearguments* somearguments_count**)
    #body
    pass

if __name__ = "__main__"
    #some simple console app waiting for
    #key to be pressed or whatever
    if keypressed:
        function_taking_photo_as_short_as_possible_!_!_!(none, none)
9
  • The less stuff you do in those functions that handle shooting photos the faster it gets. I doubt that it would be possible to make that 'picamera' package work faster then it already does. Jul 10, 2015 at 12:44
  • correct me if I am wrong , you are saying that I must use another function to save image data which runs parallel with my image capture function hence saving me some time ..agreed that should help me when taking multiple images ..but right now I am testing for a single image acquisition time ..which is still at 80 ms for a jpeg while my target is 10 ms or closer to that ..once I am able to do it for a single image I will make it work for multiple images...any ideas regarding that. Jul 10, 2015 at 12:59
  • Actually you are slightly wrong. I would say that taking photo is around 30-40 ms, because it would represent like 30-40% of elementary operations in that call from where you set 'start' variable to where you set 'finish'. Because calling time.time() has some operations done (like for example, you call a package 'time') and you set a variable, which is an operation as well. It is like trying to drive a car 5cm forward, when your engine is off i takes like a minute, but with engine on it takes like 10 seconds! So does this work, !single! frame will always be slow. Jul 10, 2015 at 13:05
  • Pretty rough calculations with those percents xD Jul 10, 2015 at 13:08
  • yes that's a valid point , so lets say I re move the time part I can cut around 30 ms because it has its own operations ...and also I figured out that my overclocking needs to be set at 900 MHz which is currently at 600 MHz , so maybe even that effects the speed..we need to look at what other possible ways can we cut the time. Jul 10, 2015 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.