Kaon
Posts: 14
Joined: Fri Apr 24, 2015 12:20 am

High fps raw bayer image recording

Fri Apr 24, 2015 12:57 am

Hi all,
I need access to the full sensor resolution raw bayer data at a maximum fps. I am currently accessing the raw data with the -raw command in raspistill timelapse mode but this appends it to a jpeg image. Is there any way to directly access and save this bayer data without processing of JPEG images and other time consuming operations?
Any suggestions welcome, thanks!

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7290
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: High fps raw bayer image recording

Fri Apr 24, 2015 6:33 am

You're effectively asking the same question as viewtopic.php?f=43&t=32455 and similar (it's been asked several times about different sensors people want to use)
There's currently no way of getting access to the raw data other than raspistill -raw, and I wasn't anticipating adding any off the camera component.
The downside for your application in just giving you the raw data is that it'll be down to you to sort out all the I2C setup for the sensor (and OV5647 datasheet is under NDA), and you'll lose all AGC control loops so will have to do manual exposure time and gain control.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Kaon
Posts: 14
Joined: Fri Apr 24, 2015 12:20 am

Re: High fps raw bayer image recording

Fri Apr 24, 2015 1:17 pm

Thanks for the reply!
Is this I2C interfacing something I will be able to learn or am I unable to proceed without access to the OV5647 datasheet?

I plan to expose the sensor to short pulses of a uniform light source so exposure time and gain settings would be set at a fixed value with no need to vary these. Does this simplify the problem at all?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7290
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: High fps raw bayer image recording

Fri Apr 24, 2015 2:33 pm

Kaon wrote:Thanks for the reply!
Is this I2C interfacing something I will be able to learn or am I unable to proceed without access to the OV5647 datasheet?

I plan to expose the sensor to short pulses of a uniform light source so exposure time and gain settings would be set at a fixed value with no need to vary these. Does this simplify the problem at all?
I2C is just a communications interface to the camera for setting it up. The datasheet tells you the details of what to put on that interface to get the data out you want. There are copies of an early version on the internet (Google is your friend), but support can not be offered on any use of that as the complete datasheet is under NDA. We can't stop people putting I2C analysers on the bus and working backwards to determine the command set that is in use.

It still doesn't help though, as currently there is no access to the CSI-2 receiver peripheral. I think viewtopic.php?f=43&t=32455#p533751 and viewtopic.php?f=43&t=32455#p534950 (and most of that thread) sum up the official position at the moment.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23654
Joined: Sat Jul 30, 2011 7:41 pm

Re: High fps raw bayer image recording

Fri Apr 24, 2015 2:55 pm

Kaon wrote:Hi all,
I need access to the full sensor resolution raw bayer data at a maximum fps. I am currently accessing the raw data with the -raw command in raspistill timelapse mode but this appends it to a jpeg image. Is there any way to directly access and save this bayer data without processing of JPEG images and other time consuming operations?
Any suggestions welcome, thanks!
Worth noting that the JPEG side of things isn't particular time consuming. Biggest issue I think is data transfer time from GPU to CPU, but you could set a very low quality threshold, which reduces the size of the JPEG data considerably and will improve speed, but with -raw you still get full res bayer. Of course the bayer data is still pretty huge, which you cannot do anything about. The transfer time is always going to be the biggest issue to high fps.

That might speed things up a bit. Good luck with the bayer data!
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7290
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: High fps raw bayer image recording

Fri Apr 24, 2015 3:31 pm

jamesh wrote:Worth noting that the JPEG side of things isn't particular time consuming. Biggest issue I think is data transfer time from GPU to CPU, but you could set a very low quality threshold, which reduces the size of the JPEG data considerably and will improve speed, but with -raw you still get full res bayer. Of course the bayer data is still pretty huge, which you cannot do anything about. The transfer time is always going to be the biggest issue to high fps.

That might speed things up a bit. Good luck with the bayer data!
If that is suspected to be the limitation, then bump up the buffer size so that it uses fewer round trips of the buffer(s).
Zero copy does also now work (Dom is just sorting a mod so that more than root can use it), so that would also save some time.
I'd say that it's more likely that saving the thing to SD card is the slowest part. Nothing stopping the ARM parsing the buffers as they come in, and only saving the raw rather the JPEG, but that's still 6MB of data per image.

One thing that should improve capture speed is a hack in the CAMERA_CONFIG_T structure to set max_preview_video_w and max_preview_video_h to 2592 and 1944 respectively. It'll grab more memory, but will also allow the camera to keep streaming between captures. Normally it'll allocate memory for 3 buffers at whatever resolution is needed for preview, or 1 stills frame. If preview only needs the 1296x976 mode, then it only has memory for one still capture and has to stop streaming every time.
Also add -bm (burst mode) to the command line, otherwise the camera is being switched back to preview after each capture. Burst mode holds the sensor in the capture mode between captures as it is expecting more. (It does currently lock AGC and AWB whilst burst mode is set. I don't know if that matters to you or not).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

gordon77
Posts: 4164
Joined: Sun Aug 05, 2012 3:12 pm

Re: High fps raw bayer image recording

Fri Apr 24, 2015 4:22 pm

"(It does currently lock AGC and AWB whilst burst mode is set) "

Does locking the AGC affect the auto exposure? I've noticed running with -bm continuously can end up with a very bright picture as if the auto exposure hasn't coped.

Gordon77

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7290
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: High fps raw bayer image recording

Fri Apr 24, 2015 5:18 pm

gordon77 wrote:"(It does currently lock AGC and AWB whilst burst mode is set) "

Does locking the AGC affect the auto exposure? I've noticed running with -bm continuously can end up with a very bright picture as if the auto exposure hasn't coped.
Auto Gain Control and Auto Exposure are technically different things, but are generally treated either the same or to work in tandem within the tuner.

See threads such as viewtopic.php?f=43&t=67793 and from viewtopic.php?f=43&t=82306&start=25#p587850 onwards, for some of the discussions over the issue.
The reason behind the lock is that if you've run an AF cycle you typically want AGC/AE adapting during the cycle as it throws the AF numbers off. Likewise if using a flash then the precapture calcs don't want the auto algo tweaking things that have been carefully set up. After the first capture then neither of those factors really matter, so it should be possible to unlock, although I'd need to check any other implications.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23654
Joined: Sat Jul 30, 2011 7:41 pm

Re: High fps raw bayer image recording

Fri Apr 24, 2015 7:38 pm

6by9 wrote:
jamesh wrote:Worth noting that the JPEG side of things isn't particular time consuming. Biggest issue I think is data transfer time from GPU to CPU, but you could set a very low quality threshold, which reduces the size of the JPEG data considerably and will improve speed, but with -raw you still get full res bayer. Of course the bayer data is still pretty huge, which you cannot do anything about. The transfer time is always going to be the biggest issue to high fps.

That might speed things up a bit. Good luck with the bayer data!
If that is suspected to be the limitation, then bump up the buffer size so that it uses fewer round trips of the buffer(s).
Zero copy does also now work (Dom is just sorting a mod so that more than root can use it), so that would also save some time.
I'd say that it's more likely that saving the thing to SD card is the slowest part. Nothing stopping the ARM parsing the buffers as they come in, and only saving the raw rather the JPEG, but that's still 6MB of data per image.

One thing that should improve capture speed is a hack in the CAMERA_CONFIG_T structure to set max_preview_video_w and max_preview_video_h to 2592 and 1944 respectively. It'll grab more memory, but will also allow the camera to keep streaming between captures. Normally it'll allocate memory for 3 buffers at whatever resolution is needed for preview, or 1 stills frame. If preview only needs the 1296x976 mode, then it only has memory for one still capture and has to stop streaming every time.
Also add -bm (burst mode) to the command line, otherwise the camera is being switched back to preview after each capture. Burst mode holds the sensor in the capture mode between captures as it is expecting more. (It does currently lock AGC and AWB whilst burst mode is set. I don't know if that matters to you or not).
I thought the OP was processing the bayer in RAM, but having re-read the post, he appears to want to save it, so the SD card write could well be the bottleneck (or at least another bottleneck!). Although I would think the Linux caching would help a little bit with that. Depends on how many images are taken I guess.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

Kaon
Posts: 14
Joined: Fri Apr 24, 2015 12:20 am

Re: High fps raw bayer image recording

Sat Apr 25, 2015 2:07 am

Thanks for the suggestions!!
I will try these out over the next few days and see how it goes!
I do want to save the images. Ideally I am wanting at least 5 fps for a max duration of ~ 3 minutes to get an idea of the number of images required.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23654
Joined: Sat Jul 30, 2011 7:41 pm

Re: High fps raw bayer image recording

Sat Apr 25, 2015 9:16 am

Kaon wrote:Thanks for the suggestions!!
I will try these out over the next few days and see how it goes!
I do want to save the images. Ideally I am wanting at least 5 fps for a max duration of ~ 3 minutes to get an idea of the number of images required.
So each image is about 6MB, you want three minutes at 5fps, that is 900 images, so in total 5400MB. So much more than available RAM, so you cannot keep it all in RAM. What you might try is storing in RAM, but having a separate thread to save the images in the background. Eventually the storage requirement will overtake the ability to save to SD card, but you might get away with that much.

Or it may be that the Linux disk cache system may in effect give you that sort of operation for free.

Or, compress the bayer image using zlib and then save. Pi2 should be fast enough for that. That might give you enough bandwidth to keep going.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7290
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: High fps raw bayer image recording

Fri May 01, 2015 9:36 pm

Hopefully good news for you - viewtopic.php?f=43&t=109137
So there is now a way of getting access to the raw Bayer frames at a much higher framerate. Your use case is still going to struggle over the memory/storage requirements though.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

twVolc
Posts: 21
Joined: Wed Mar 16, 2016 11:41 am

Re: High fps raw bayer image recording

Wed Mar 16, 2016 12:21 pm

Hi all,

I have a similar problem, but perhaps not at such a high FPS as is being discussed here. I'm new here and a relative novice with the picam/coding in general, so if things can be explained in laymen's terms as much as possible that would be great.

I'm aiming to acquire raw bayer data at 1Hz (the faster the better, but this seems like a reasonable aim), but for a long period of time - maybe hours. As I simplistically understand it, with each image being ~6.5MB and class 10 SD write speed of 10 MB/s, this should be possible, unless other bottlenecks exist. My shutter speeds are long - 0.5s, but I would have thought I should still be able to get 1Hz out of the camera at this shutter speed (am I being over ambitious?).

I'm acquiring with in python with the picamera module and looping through something simple like:

Code: Select all

import datetime
import picamera
import time

with picamera.PiCamera() as camera:
        camera.framerate = 1 
        camera.resolution = (20,20) # I make this low to reduce file size a little
        camera.start_preview()
        time.sleep(5)
        camera.shutter_speed = 500000 
        camera.exposure_mode = 'off'
        for i in range(10):
                a = datetime.datetime.now()
                sec = a.second + (a.microsecond/1000000.0)
                imgName = 'Image_%i' % i
                camera.capture(imgName, format='jpeg', bayer=True)
                a=datetime.datetime.now()
                sec = [sec,(a.second+(a.microsecond/1000000.0))]
                print (sec[1] - sec[0])
In general, I get gaps between the start and end of imaging of ~1.8 seconds. Curiously, if I remove the "bayer=True" setting, this delay increases to ~2.6 seconds - I'm not concerned about this as I'm only interested in the raw data, but this is an interesting result - I was expecting to drastically improve framerate by removing the bayer extraction, as it significantly reduces file size. Also, when retrieving the raw bayer data, if I take enough images (approximately the 15th frame I think) I eventually get a gap of >5 seconds for one image, then the higher framerate resumes for subsequent images, until the same thing happens again.

My questions are, is there anything I can do to improve this - a more efficient way of taking images - would I be better off sending a raspistill command from python, or is camera.capture() just as efficient? Is there any chance of getting to ~ 1Hz for sustained periods of time? And also, more importantly, do you now what is likely to be the cause of the reduction in acquisition speed for a single frame every now and then - is there a way to prevent this? Consistency is quite crucial to the work I'm doing, so I'd be happy to settle at 0.5 Hz if I could remove this inconsistency (but obviously consistently 1Hz would be better!).

Thanks for any help you can give me.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7290
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: High fps raw bayer image recording

Wed Mar 16, 2016 2:29 pm

The full camera stack really has the Bayer images tacked on the side, and is aimed at preview normally with the odd capture.
Your delays are probably due to the buffering setup. Having set resolution to (20,20) the input stage buffering won't be sufficient to hold multiple 5MP images, so it will have to stop the sensor after each capture. Stopping and restarting takes time. I'd suggest you try setting "sensor_mode=2" to force the 5MP mode under all conditions.
You will also be switching forwards and backwards between preview and stills capture modes and that isn't instantaneous. Setting sensor_mode should help a bit there too as the sensor can probably remain streaming.

If you're only after Bayer then I'd suggest looking at the raspiraw code in more detail. It is possible to configure the sensor to output 0.5sec exposures at 1fps, however I don't think anyone has captured or reverse engineered the registers required as yet. Doing anything else will just slow down your captures. There are only about 3 registers involved, but I'm not at liberty to state what they are (my knowledge of the register set is under NDA).
Do note that you then have no AE loop running to set exposure time and analog gain. You need to do that manually.
There is a pull request open on my raspiraw branch where someone has captured the settings for the different modes, and the registers for exposure time and analogue gain (it doesn't convert them into sensible units). It'll give you a load of extra settings over the basic raspiraw that I pushed.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

bhend449
Posts: 7
Joined: Tue Mar 22, 2016 8:08 pm

Re: High fps raw bayer image recording

Tue Mar 22, 2016 8:32 pm

Hello,

I think I'm trying to do something similar to what twVolc is doing. Mainly I'm trying to take several raw bayer images, create matrices out of the pixel responses, and stack those matrices together to study the response of any particular pixel over a long period of time. Mainly, to study RTS noise. Anyway, as a certifiable noob to both the pi and the camera module, I was hoping to get some validation from folks with far more expertise to make sure I'm not fooling myself.

My first step is to collect several images using code similar to twVolc's (many thanks!) and then perform the 10 bit decoding using matlab and something similar to Schwabenchris' code I found here: viewtopic.php?f=43&t=44918&start=200

Here is that code:

Code: Select all

filename='filename.jpg'
sizeRAW = 6404096;
sizeHeader =32768;
imagewidth=2592;
imageheight=1944;
stepsize=4;
rowsize =3264;                                                          %number of bytes per row of pixels, including 24 'other' bytes at end

fin=fopen(filename,'r');                                                
off1 = dir(filename);                                                   %get fileinfos
offset = off1.bytes - sizeRAW + sizeHeader;                             %calc the offset for the reading process
fseek(fin, offset,'bof');                                               %
pixel = uint16(ones(imagewidth,imageheight));
   for row=1:imageheight 
      I=fread(fin,rowsize,'ubit8','ieee-le');
      x = 0;
      for col=1:stepsize:imagewidth
          x = x+1;  
          pixel(col+0,row) = I(x)*2^8;
           x = x+1;
            pixel(col+1,row) = I(x)*2^8;
             x = x+1;
            pixel(col+2,row) = I(x)*2^8;
             x = x+1;
            pixel(col+3,row) = I(x)*2^8;
             x = x+1;
            split = I(x);                                                 %grab the LSB byte
            pixel(col+0,row) = pixel(col+0,row) + bitand(split,192);      %split up the LSB byte with 0b11000000 aka 192 and add to pixel 1
            pixel(col+1,row) = pixel(col+1,row) + bitand(split,48)*2^2;   %split up the LSB byte with 0b00110000 and add to pixel 2
            pixel(col+2,row) = pixel(col+2,row) + bitand(split,12)*2^4;   %split up the LSB byte with 0b00001100 and add to pixel 3
            pixel(col+3,row) = pixel(col+3,row) + bitand(split,3)*2^6;    %split up the LSB byte with 0b00000011 and add to pixel 4
      end
   end
Anyway, again, I'm just looking to make sure that the data I'm getting is real raw data from the sensor. I attempted to use something like the recipe found near the bottom of the page here,
http://picamera.readthedocs.org/en/rele ... ipes2.html
but the script would crash after 20 or so frames. So, thanks again to txVolc, and Schwabenchris.

Appreciate any thoughts or guidance anyone has to offer.

Ben

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23654
Joined: Sat Jul 30, 2011 7:41 pm

Re: High fps raw bayer image recording

Wed Mar 23, 2016 9:28 am

Biggest problem with high frame rate bayer is the size of the imge and the speed with which they can be transferred to the SD card. Bayer images use a lot more memory than JPEG, and at high frame rates the bandwidth the SD card is exceeded (there are also other bottle necks in the system). This could cause rout of memory errors or similar.

Does moving to a smaller image size (which I suspect would be OK for you task) make the script run for longer? e.g. VGA rather than 5MP?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

bhend449
Posts: 7
Joined: Tue Mar 22, 2016 8:08 pm

Re: High fps raw bayer image recording

Wed Mar 23, 2016 6:58 pm

The frame rate as it stands now is a little more than 0.5 using the program similar to twVolc's. That is probably going to be good enough. It was a much bigger issue when I was running the raw bayer recipe where a frame was taking around 20 seconds. That program included building a 3D numpy array, populating two of the dimensions with rows and columns (a 32x32 roi) and appending each additional frame section as the third dimension in the array. That way I could track the output from a paticular pixel over many frames and characterize its performance. But, like I said it would typically crash after about 20 or so frames.

The new program I'm running to collect frames works very well and will give me around 1000 frames in under an hour, likely good enough to detect pixels prone to RTS noise and derive the time constants. But, the catch is that I'm now stuck pulling out the raw pixel data from .jpg files using MATLAB which officially takes me out of my comfort zone. (Hopefully by now it's painfully obvious that I'm a lowly physics student, not EE)

So, the short version of this story, which I probably should have started with, is that everything seems to be working fine, but I remain skeptical. My research involves the performance of small pitch CMOS sensors before and after gamma radiation dosages. To do it though, I need to be absolutely certain that the numbers I ultimately look at have not been altered in any way by processing. If you have a suggestion for a better way to acquire the data, I'm all ears. (Or eyes)

Thanks again!

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23654
Joined: Sat Jul 30, 2011 7:41 pm

Re: High fps raw bayer image recording

Thu Mar 24, 2016 8:57 am

The Bayer data attached to the JPEGS produced by the Foundation camera code is the Bayer Data from the sensor, before any processing. The only thing that may have been done to it is the analog gain may be varied depending on lighting (Analog gain is applied by the sensor itself). But, in decent lighting conditions, it should be 1.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

twVolc
Posts: 21
Joined: Wed Mar 16, 2016 11:41 am

Re: High fps raw bayer image recording

Tue Apr 12, 2016 10:42 am

Thanks for the quick reply 6by9 - sorry, I've only just seen it!

I've just tried setting camera.sensor_mode=2 in python, but it doesn't seem to have made a difference. The crucial thing is I still get this drastic gap in frame captures at about 10-15 images in, for one image, where I may have a lag of >3 seconds between the images. Do you know what might be causing this? If I can prevent this then I will comfortably get 0.5 Hz consistently. Perhaps my code isn't perfect? I did wonder if setting the camera framerate was necessary with still, but it does seem to have an effect, and it seems it can be detrimental to exposure_speed if the framerate is set too high.

I will also have a look into raspiraw, although I fear my lack of experience might prevent me from getting too far with this - your second/third paragraphs of answer kind of lost me. Although I do have time and want to learn, so I can see if I can make any headway with this. One thing I think I didn't mention, but you may have picked up on from my original code is that I want analog gain to be set throughout the acquisition period, to provide consistent images. You mentioned the gain in your reply, but again I'm slightly out of my depth in understanding it - you say I would need to set the gain manually - is that within the raspiraw script itself? If that's the case that would be perfect, as I had thought there wasn't a way of setting the gain manually, rather just fixing it by turning exposure mode off.

Thanks again.

twVolc
Posts: 21
Joined: Wed Mar 16, 2016 11:41 am

Re: High fps raw bayer image recording

Tue Apr 12, 2016 10:51 am

jamesh wrote:The Bayer data attached to the JPEGS produced by the Foundation camera code is the Bayer Data from the sensor, before any processing. The only thing that may have been done to it is the analog gain may be varied depending on lighting (Analog gain is applied by the sensor itself). But, in decent lighting conditions, it should be 1.
Just a note, it may be a little late. If bhend449 is using a script similar to mine to capture the raw data then exposure_mode is turned off to fix the analog gain. So if I understand what I've tried to do correctly, analog gain shouldn't be affecting their results.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23654
Joined: Sat Jul 30, 2011 7:41 pm

Re: High fps raw bayer image recording

Tue Apr 12, 2016 11:16 am

twVolc wrote:Thanks for the quick reply 6by9 - sorry, I've only just seen it!

I've just tried setting camera.sensor_mode=2 in python, but it doesn't seem to have made a difference. The crucial thing is I still get this drastic gap in frame captures at about 10-15 images in, for one image, where I may have a lag of >3 seconds between the images. Do you know what might be causing this? If I can prevent this then I will comfortably get 0.5 Hz consistently. Perhaps my code isn't perfect? I did wonder if setting the camera framerate was necessary with still, but it does seem to have an effect, and it seems it can be detrimental to exposure_speed if the framerate is set too high.

I will also have a look into raspiraw, although I fear my lack of experience might prevent me from getting too far with this - your second/third paragraphs of answer kind of lost me. Although I do have time and want to learn, so I can see if I can make any headway with this. One thing I think I didn't mention, but you may have picked up on from my original code is that I want analog gain to be set throughout the acquisition period, to provide consistent images. You mentioned the gain in your reply, but again I'm slightly out of my depth in understanding it - you say I would need to set the gain manually - is that within the raspiraw script itself? If that's the case that would be perfect, as I had thought there wasn't a way of setting the gain manually, rather just fixing it by turning exposure mode off.

Thanks again.
Could that be the disk cache system suddenly finding it needs to write a load of stuff to the card? Can you sync after each frame to ensure the cache is flushed as you go along?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

twVolc
Posts: 21
Joined: Wed Mar 16, 2016 11:41 am

Re: High fps raw bayer image recording

Tue Apr 12, 2016 11:20 am

Could that be the disk cache system suddenly finding it needs to write a load of stuff to the card? Can you sync after each frame to ensure the cache is flushed as you go along?
Thanks for the quick reply, this sounds like it could be the problem. Unfortunately, as a novice, I don't know exactly how to do this. If it's not too complicated could you provide me with some advice?

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23654
Joined: Sat Jul 30, 2011 7:41 pm

Re: High fps raw bayer image recording

Tue Apr 12, 2016 11:33 am

Don't know much Python, but this might be it...

http://www.tutorialspoint.com/python/os_fsync.htm
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

twVolc
Posts: 21
Joined: Wed Mar 16, 2016 11:41 am

Re: High fps raw bayer image recording

Tue Apr 12, 2016 1:36 pm

jamesh wrote:Don't know much Python, but this might be it...

http://www.tutorialspoint.com/python/os_fsync.htm
Thanks jamesh, I'm trying to get this to work, unsuccessfully thus far.
If there's any python/picamera geniuses out there I'd really appreciate the help (if this is in fact what is causing the frame lag on about my 15th frame)
Using my code from above, I can't obtain a file descriptor for the captured image to then use fsync to write to disk, rather than storing in the buffer. I'm still laying around with it, but if anyone knows what needs to be done that would greatly help me!

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7290
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: High fps raw bayer image recording

Tue Apr 12, 2016 1:46 pm

As a test, write to /dev/null instead of to file. If you still get a significant delay then it's not the file system that is introducing the lag.
Of course you also don't get any output files, so you'll need to log when the files are produced to the console or similar.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Camera board”