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)
  • 2
    Could you post some of the code here? It could be possible to start separate process to save file. Most likely data is already in RAM before saved to file, question is how does exactly, that package you use, handle that. What is the name of the package? – Piotr Kamoda Jul 10 '15 at 8:15
  • well... is it...? I don't see anything except your profile – Piotr Kamoda Jul 10 '15 at 12:03
  • sorry ...I have edited it now .. – user5049377 Jul 10 '15 at 12:13
  • it would be useful to format it for readability... Please read help section on formatting... But it appears that your solution is right there - outputs is simple blob (binary large blob). Read on Python async, you can start the same function as separate process and tidy up in your first process. – Piotr Kamoda Jul 10 '15 at 12:20
  • I am completely new to python & image processing ..can you just explain how it can be done ..this is quite critical for my project ..I have formatted the code – user5049377 Jul 10 '15 at 12:33
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)
  • 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. – Piotr Kamoda Jul 10 '15 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. – user5049377 Jul 10 '15 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. – Piotr Kamoda Jul 10 '15 at 13:05
  • Pretty rough calculations with those percents xD – Piotr Kamoda Jul 10 '15 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. – user5049377 Jul 10 '15 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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