Insurmountable
Posts: 33
Joined: Fri Oct 20, 2017 11:50 am

Syncing a high power LED array to camera start frame.

Mon Apr 02, 2018 1:49 pm

NO OPTION TO DELETE MY ACCOUNT
Last edited by Insurmountable on Thu Dec 27, 2018 2:42 pm, edited 1 time in total.

drgeoff
Posts: 9253
Joined: Wed Jan 25, 2012 6:39 pm

Re: Syncing a high power LED array to camera start frame.

Mon Apr 02, 2018 3:56 pm

Raspbian is not a real time OS, the OS is doing other things in addition to running your code and python is an interpreted language.

All those latencies mean that things are not happening as soon as you expect.

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

Re: Syncing a high power LED array to camera start frame.

Mon Apr 02, 2018 7:44 pm

Two words - rolling shutter.
The sensor has no on board "storage", and the readout to the SoC is bandwidth limited. The way most sensors work around that is that the exposure of each line is delayed by the time the line takes to read out, hence the frame start event is when the SoC receives the first line of the frame/the first line finishes exposing. If taking a still image (full 5 or 8MPix frame readout), then the frame readout time is ~60ms. The other sensor modes have varying readout times, which also dictates the maximum frame rate of each mode.
Setting your exposure time to 1ms means that each line will be exposed for 1ms, but there will still be a temporal difference between the first and last line.
Have a read of waveform80's description at http://picamera.readthedocs.io/en/lates ... -operation

drgeoff is also correct that Linux is not a real-time operating system, so there are no guarantees as to the processing latency (even more so in an interpreted language such as Python). That is one of the main reasons I didn't plumb it through as a callback from the GPU as you could gain an indeterminate latency in processing that event. At least with a GPIO being controlled by the GPU the latency should be minimal.
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.

Insurmountable
Posts: 33
Joined: Fri Oct 20, 2017 11:50 am

Re: Syncing a high power LED array to camera start frame.

Tue Apr 03, 2018 5:41 pm

NO OPTION TO DELETE MY ACCOUNT
Last edited by Insurmountable on Thu Dec 27, 2018 2:44 pm, edited 1 time in total.

Kozuch
Posts: 63
Joined: Sun Aug 10, 2014 10:35 am

Re: Syncing a high power LED array to camera start frame.

Fri Apr 13, 2018 1:40 pm

Do I understand this correctly that with some sort of setting ("disable_camera_led=3") and a setup described above one can get a GPIO signal when a frame exposure starts? Does this work only with still capture more or also in video (sensor running freely) mode (still/video MMAL ports)?

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

Re: Syncing a high power LED array to camera start frame.

Fri Apr 13, 2018 2:08 pm

Kozuch wrote:
Fri Apr 13, 2018 1:40 pm
Do I understand this correctly that with some sort of setting ("disable_camera_led=3") and a setup described above one can get a GPIO signal when a frame exposure starts? Does this work only with still capture more or also in video (sensor running freely) mode (still/video MMAL ports)?
viewtopic.php?t=190314
NB Start/end of frame reception at the SoC ie end of exposure of the first/last line of the image.
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.

PiGraham
Posts: 3529
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Syncing a high power LED array to camera start frame.

Fri Apr 13, 2018 2:36 pm

Insurmountable wrote:
Tue Apr 03, 2018 5:41 pm
Yes it seems to work better just using the Camera LED signal to switch the FET directly on and off. When you do as I have done you get a small band at the top of the picture which is the delay in switching on the FET using my python code. I will put a scope on it tomorrow and see what the differences are between the two methods.

The reason I did it this way was I wanted to have better control of the lights on time, if you drive directly from the camera LED signal then you always switch the lights off when the last frame is received regardless of the shutter time but it seems that at high shutter speeds this is practically one and the same.
As 6by9 explained (read the linked info) you can't use strobbed illumination with the rolling shutter at shutter times shorter than the full frame time. If you try you will only illuminate some strip of lines. The scan lines expose at different times. This is nothing like a film camera or gloabl shutter sensor
.

You need to turn the light on from the first line to the last line of the frame + exposure time.

If you need to freeze fast motion with exposures shorter than the frame time use a different camera.

Insurmountable
Posts: 33
Joined: Fri Oct 20, 2017 11:50 am

Re: Syncing a high power LED array to camera start frame.

Fri Apr 13, 2018 7:02 pm

NO OPTION TO DELETE MY ACCOUNT
Last edited by Insurmountable on Thu Dec 27, 2018 2:44 pm, edited 2 times in total.

Insurmountable
Posts: 33
Joined: Fri Oct 20, 2017 11:50 am

Re: Syncing a high power LED array to camera start frame.

Fri Apr 13, 2018 7:15 pm

NO OPTION TO DELETE MY ACCOUNT
Last edited by Insurmountable on Thu Dec 27, 2018 2:45 pm, edited 1 time in total.

Insurmountable
Posts: 33
Joined: Fri Oct 20, 2017 11:50 am

Re: Syncing a high power LED array to camera start frame.

Fri Apr 13, 2018 7:19 pm

NO OPTION TO DELETE MY ACCOUNT
Last edited by Insurmountable on Thu Dec 27, 2018 2:45 pm, edited 1 time in total.

PiGraham
Posts: 3529
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Syncing a high power LED array to camera start frame.

Sat Apr 14, 2018 8:48 am

Insurmountable wrote:
Fri Apr 13, 2018 7:15 pm
As 6by9 explained (read the linked info) you can't use strobbed illumination with the rolling shutter at shutter times shorter than the full frame time. If you try you will only illuminate some strip of lines. The scan lines expose at different times. This is nothing like a film camera or gloabl shutter sensor
I am using this for a Computer Vision project, the results I am getting do have banding so you could never use it for film or TV but considering I am capturing images of stuff moving fast in total darkness, the results are great and I have achieved what everyone else said you need a physical shutter to do.

Fair enough, if you can compensate for banding and distortion that results from rolling shutter it can still be useful. You can combine multiple partially-illuminated frames and un-warp and so on.

You shouldn't be surprised that you got the replies explaining rolling shutter since in your OP you didn't seem to understand how it works.
If the exposure time of the camera is 1ms then it should only need the lights to be on for 1ms not 15ms.
And you didn't say anything about how you were using the images or how you were compensating for rolling shutter effects.

Insurmountable
Posts: 33
Joined: Fri Oct 20, 2017 11:50 am

Re: Syncing a high power LED array to camera start frame.

Sat Apr 14, 2018 7:54 pm

NO OPTION TO DELETE MY ACCOUNT
Last edited by Insurmountable on Thu Dec 27, 2018 2:44 pm, edited 1 time in total.

PiGraham
Posts: 3529
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Syncing a high power LED array to camera start frame.

Sun Apr 15, 2018 4:09 pm

Thanks for posting those images. It's great to see what people are doing with Raspberry Pis. It looks very impressive.
Are you trying to freeze motion? It doesn't look like anything is moving in the image from the Pi camera with LED lighting.

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

Re: Syncing a high power LED array to camera start frame.

Sun Apr 15, 2018 8:03 pm

Insurmountable wrote:
Sat Apr 14, 2018 7:54 pm
ooops I nearly forgot with a rolling shutter it's not really exposure time but the amount of gain of the CCD chip, silly me.
??! Neither Pi cameras are CCD, they're both CMOS based. Both have exposure control (time between resetting the line and reading it out) 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.

PiGraham
Posts: 3529
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Syncing a high power LED array to camera start frame.

Sun Apr 15, 2018 8:36 pm

Insurmountable wrote:
Sat Apr 14, 2018 7:54 pm
ooops I nearly forgot with a rolling shutter it's not really exposure time but the amount of gain of the CCD chip, silly me.
It really is exposure time. It's just that each line of the image exposes at a different time,, one after the other, but each line exposes (gathers light) for the specified exposure time. Gain is something else entirely.

Insurmountable
Posts: 33
Joined: Fri Oct 20, 2017 11:50 am

Re: Syncing a high power LED array to camera start frame.

Sun Apr 15, 2018 9:29 pm

NO OPTION TO DELETE MY ACCOUNT
Last edited by Insurmountable on Thu Dec 27, 2018 2:45 pm, edited 2 times in total.

Insurmountable
Posts: 33
Joined: Fri Oct 20, 2017 11:50 am

Re: Syncing a high power LED array to camera start frame.

Sun Apr 15, 2018 10:48 pm

NO OPTION TO DELETE MY ACCOUNT
Last edited by Insurmountable on Thu Dec 27, 2018 2:47 pm, edited 1 time in total.

Insurmountable
Posts: 33
Joined: Fri Oct 20, 2017 11:50 am

Re: Syncing a high power LED array to camera start frame.

Sun Apr 15, 2018 11:19 pm

NO OPTION TO DELETE MY ACCOUNT
Last edited by Insurmountable on Thu Dec 27, 2018 2:46 pm, edited 1 time in total.

PiGraham
Posts: 3529
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Syncing a high power LED array to camera start frame.

Mon Apr 16, 2018 7:40 am

Insurmountable wrote:
Sun Apr 15, 2018 9:29 pm

Also you can get a zillion different hi-quality camera lens on gumtree or craigslist for less than $100 while hi quality CCTV lens are expensive and because of their size don't let in enough light. You want to try and get lens that are NOT full format, if you do use one then your picture will be zoomed in like a 1000 times and you will have a very narrow field of view.
That is a challenge. One limitation in using an SLR lens with a Pi camera is the size of the pixels / the resolution of the projected image. An SLR/DSLR has a large photo sensitive area and doesn't need such high resolution to get nice sharp results. The pixels on the Pi sensors are very small beyond the limit of resolution of most lenses. Any large format lens that is properly matched to those sensors will be relatively expensive.
Not only do you get the magnification problem, you can't get sharp focus.
Fast lenses help with light levels, but also soften the sharpness and reduce depth of field.

You have done a good job there.

PiGraham
Posts: 3529
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Syncing a high power LED array to camera start frame.

Mon Apr 16, 2018 7:44 am

Insurmountable wrote:
Sun Apr 15, 2018 11:19 pm
Are you trying to freeze motion? It doesn't look like anything is moving in the image from the Pi camera with LED lighting.
Here is one of my freeze motion shots, taken from the shore.

Great photos.

I was asking about whether you were using strobbed LEDs to freeze motion, which is where rolling shutter gest particularly problematic.
Any motion will result in some distortion but it's not noticeable in most scenes and slow speeds. As you know it gest obvious with fast moving edges like propellers. You can't use a strobe to get a freeze-frame image of a propeller on a rolling shutter sensor.

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

Re: Syncing a high power LED array to camera start frame.

Mon Apr 16, 2018 9:13 am

Insurmountable wrote:
Sun Apr 15, 2018 10:48 pm
??! Neither Pi cameras are CCD, they're both CMOS based. Both have exposure control (time between resetting the line and reading it out) and gain control.
And I have a Hoover but it is not actually a Hoover. ;)
I'm no expert on CCDs hence surmised from your comment that there could be a limitation where they couldn't control exposure time. I'd be surprised as exposure time gives a significantly greater degree of control over the amount of light sensed than gain does.
Insurmountable wrote:
It really is exposure time. It's just that each line of the image exposes at a different time,, one after the other, but each line exposes (gathers light) for the specified exposure time. Gain is something else entirely.
Yeah I was wondering how it would be possible to implement using gain, I figured it was something akin to switching the power on then off to achieve. The reason why companies like FaceBook and Apple make so much money is the inability of todays computer engineers to make manuals that make sense. When I had my BBC model B in the 80s there was no Internet, no one to ask, I had a few manuals which explained everything in detail and that was that, never needed to ask anyone anything. Look it up in the manual which would say stuff like this command causes the CPU to first set these registers to this then these lines to that, it literally told you how it worked, these days manuals attempt to simplify stuff and fail miserably.
Have a read through https://picamera.readthedocs.io/en/latest/fov.html for a decent description of how the sensors implement rolling shutter with exposure time.
Insurmountable wrote:A good point is how it is seemingly impossible to set the Pi camera into manual mode, any adjustments are made using whatever the last automatic settings produced, you cant say take a picture with this ISO and then add 2 stops of extra exposure, if you tell it to increase the exposure by 2 stops then it takes the last automatically obtained exposure setting and adds 2 stops to that. like WTF? do these guys even do photography?
Er, try -ag and -dg in raspistill/vid to explicitly set analogue and digital gains, and -ss to set the shutter speed. (NB omit any of those and the automatic algorithm will be adjusting those controls to try and achieve what it sees as correctly exposed).
Add in -awbg to set white balance gains, and there aren't many more controls left. If you want manual control then you take full responsibility for it.

Please rememeber that the Pi camera was aimed at mobile phones, not DSLRs. Two very different markets with different expectations (and price points).
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.

Insurmountable
Posts: 33
Joined: Fri Oct 20, 2017 11:50 am

Re: Syncing a high power LED array to camera start frame.

Mon Apr 16, 2018 11:21 am

NO OPTION TO DELETE MY ACCOUNT
Last edited by Insurmountable on Thu Dec 27, 2018 2:46 pm, edited 1 time in total.

Insurmountable
Posts: 33
Joined: Fri Oct 20, 2017 11:50 am

Re: Syncing a high power LED array to camera start frame.

Mon Apr 16, 2018 11:43 am

NO OPTION TO DELETE MY ACCOUNT
Last edited by Insurmountable on Thu Dec 27, 2018 2:47 pm, edited 1 time in total.

Insurmountable
Posts: 33
Joined: Fri Oct 20, 2017 11:50 am

Re: Syncing a high power LED array to camera start frame.

Mon Apr 16, 2018 12:11 pm

NO OPTION TO DELETE MY ACCOUNT
Last edited by Insurmountable on Thu Dec 27, 2018 2:46 pm, edited 1 time in total.

PiGraham
Posts: 3529
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Syncing a high power LED array to camera start frame.

Mon Apr 16, 2018 4:13 pm

Insurmountable wrote:
Mon Apr 16, 2018 11:43 am
The maximum speed of what I want to take images of is 15m/sec with an exposure time of 1.5ms that means the object will only have moved 2cm during the exposure time. And objects are traveling towards the camera so it wont be an issue.
Frame rate is more significant than exposure time. The fastest I've seen the current Pi camera run in 665fps which is 5.5ms but unless you are setting the frame rate you will have the standard 60fps 16.7ms or 30fps 33.4ms. Of course frame rate and exposure time are related

The object will have moved 2cm in the time a single line is exposing, but to get an image you need all the lines so it could be a much bigger distance. Look for comb tooth effects on edges.

You can ee it on hermansw's video here
Image
viewtopic.php?t=201568#p1277323

Check out HermanSW who has been exploring high frame rates.

viewtopic.php?t=201568

How significant motion during the frame time is depends a lot on the field of view / distance to target.

The gif above is 'only' 3.3m/s but it's close to the camera so the effect is very obvious.

If you have sample images that show no sign of these effects it would be interesting to understand what's going on.

Return to “Advanced users”