kkjkearney
Posts: 14
Joined: Wed Dec 23, 2015 3:16 pm

PiCamera rolling shutter problem

Mon Jan 25, 2016 4:49 pm

I've built a microscope system based upon the PiCamera; it works very well. Problem is, when in preview mode, the rolling shutter reacts very badly with certain light sources (dimmable halogen and non-dimmable LED). Even though the image is stationary, I get a horrible swimming "jello" effect. I understand why this may happen with a moving object, but my object is stationary.

Does anyone have an understanding of why this happens, whether there's a camera setting that will bail me out, or whether there's a type of lighting that will eliminate this effect? It behaves well with ambient fluorescent light.

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

Re: PiCamera rolling shutter problem

Mon Jan 25, 2016 5:19 pm

It'd be helpful if you'd post an example, but at a guess it will be 50Hz flicker from your lights, not the rolling shutter. If your exposure time is not a multiple of 10ms (assuming 50Hz mains) then you'll get banding due to uneven lighting. If the exposure time is <10ms, then there's nothing you can do about it.

There is an option on the GPU to force the exposure time to only use multiples of 10ms (50Hz) or 8.33ms (60Hz). MMAL_PARAMETER_FLICKER_AVOID is the MMAL parameter to look for, but I don't think Picamera has exposed it. Raspistill exposes it IIRC, and you can then also use the -set option to look at the exposure time requested.
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.

kkjkearney
Posts: 14
Joined: Wed Dec 23, 2015 3:16 pm

Re: PiCamera rolling shutter problem

Mon Jan 25, 2016 8:43 pm

Thanks for the quick response. I should have said, I'm in the US (60 Hz)

Here are YouTube links to a few 5 second videos showing the effect:

LED Back light plus dimmable Halogen top light: http://www.youtube.com/watch?v=abvGcqWmxPQ
[Halogen toplight only, non-dimmable: http://www.youtube.com/watch?v=xl-hPqv_dWg

With the proper lighting, the image is fast, responsive and crisp. With LED and dimmable Halogen, the image is wobbly. I'm not sure what to do but avoid LED backlighting and dimmable sources.

kkjkearney
Posts: 14
Joined: Wed Dec 23, 2015 3:16 pm

Re: PiCamera rolling shutter problem

Mon Jan 25, 2016 10:13 pm

Here's a YouTube video that better shows the effect.
http://www.youtube.com/watch?v=hzrZuNwBYCo

Thanks for your help.

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

Re: PiCamera rolling shutter problem

Mon Jan 25, 2016 10:33 pm

Bizarre, but it doesn't look like either the normal light flicker interference or rolling shutter issues to me.
Heat haze? Or RF interference? Dimmers in particular can throw off nasty RF emissions.
It'd be useful to know what sort of exposure times and gains you are using (-set option, or can be read in Picamera) as it may just be that with decent lighting the exposure time is shorter so effects aren't as visible.
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.

kkjkearney
Posts: 14
Joined: Wed Dec 23, 2015 3:16 pm

Re: PiCamera rolling shutter problem

Tue Jan 26, 2016 4:01 pm

I've eliminated RF interference as the cause. With the offending light source turned on, I can block (and unblock) the offending light from hitting the camera while leaving the source running. The effect occurs only when the light hits the camera. If I block the light (but leave the source running), the effect goes away.

There's no heat being generated anywhere near the scope or camera.

I replaced the LED backlight with a simple incandescent 25W bulb, and am seeing the same effect. Surprised...

I will investigate the camera settings. Certainly, when the camera is behaving and misbehaving (with different light sources), the amount of light and quality of that light is different. The auto settings on the camera may be allowing a variable to be adjusted to a value that is causing the misbehavior? Any ideas which settings could be suspect?

fruit-uk
Posts: 609
Joined: Wed Aug 06, 2014 4:19 pm
Location: Suffolk, UK

Re: PiCamera rolling shutter problem

Tue Jan 26, 2016 4:09 pm

Any chance it's related to the camera flash 'flash of death' effect?

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

Re: PiCamera rolling shutter problem

Tue Jan 26, 2016 5:05 pm

fruit-uk wrote:Any chance it's related to the camera flash 'flash of death' effect?
No, that was an issue with the SMPS and caused a reboot!
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.

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

Re: PiCamera rolling shutter problem

Tue Jan 26, 2016 5:13 pm

kkjkearney wrote:I've eliminated RF interference as the cause. With the offending light source turned on, I can block (and unblock) the offending light from hitting the camera while leaving the source running. The effect occurs only when the light hits the camera. If I block the light (but leave the source running), the effect goes away.

There's no heat being generated anywhere near the scope or camera.

I replaced the LED backlight with a simple incandescent 25W bulb, and am seeing the same effect. Surprised...

I will investigate the camera settings. Certainly, when the camera is behaving and misbehaving (with different light sources), the amount of light and quality of that light is different. The auto settings on the camera may be allowing a variable to be adjusted to a value that is causing the misbehavior? Any ideas which settings could be suspect?
My memory is getting a little hazy, but I spent a fair chunk of time on one project determining what tolerance around mains frequency you could go to on exposure time that didn't suffer flicker, however I can't remember the exact effects at short exposure times. Normally it exhibits itself as a dark band that moves up or down the screen depending on beat frequencies.
It's more normally off fluorescent lighting that you see effects due to the tube striking, not incandescent, so I'm confused there too.

Almost certainly it will be exposure time that is the critical thing. See what numbers it is getting set to, but you could try fixing it to some nice multiple of 8.33ms (60Hz).
The other thought is it might be related to the binning used on the sensor for preview modes. You could try adding -md 2 to a raspivid/still command line to force the full 5MP mode, though you'll only get 15fps updates.
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.

kkjkearney
Posts: 14
Joined: Wed Dec 23, 2015 3:16 pm

Re: PiCamera rolling shutter problem

Tue Jan 26, 2016 5:36 pm

OK, making progress! I queried the camera settings with a "good" and "bad" light source.

With the offending LED source:
shutter_speed = 0
exposure_speed = 2895
Result: preview image looks like jelly

With another (badly) offending halogen source:
shutter_speed = 0
exposure_speed = 1470
Result: preview image looks like jelly (bad)

With non-offending source:
shutter_speed = 0
exposure_speed = 33116
Result: preview image looks good

I then programmed a shutter_speed of 33,333 and used the badly offending halogen source:
shutter_speed = 33116
exposure_speed = 33116
Result: The jello effect was GONE!!! However.... as you'd expect, the camera no longer adjusts nicely to lighting conditions, and my image is blinded out unless I fuss with the lighting intensity.

Now, how do I get the best of both worlds? Can I prevent the exposure speed from dipping so low, or is there something else I need to understand/adjust?

This application is all about previewing and capturing. There's no video involved, so I thought I could ignore frame_rate. I've tried a mode of 0 and 1, no difference in the jello effect. I'm using a resolution of 1920x1080.

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

Re: PiCamera rolling shutter problem

Tue Jan 26, 2016 6:15 pm

Try setting exposure time to 8.333ms as the lowest multiple of the mains frequency.
You haven't read out the analogue gain. If that is >x1.0 at the moment then there may be sufficient adjustment there to compensate for the extra exposure time.

I can't explain the effect. There is no reason I can think of why short exposure times under bright conditions should cause this, so I'm a little stumped.
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.

kkjkearney
Posts: 14
Joined: Wed Dec 23, 2015 3:16 pm

Re: PiCamera rolling shutter problem

Wed Feb 03, 2016 3:09 pm

Through trial and error, I arrived at an acceptable exposure_speed of about 15,000. Multiples of any value made no difference.

As I mentioned, fixing the exposure_speed takes away much of the camera's ability to adjust to changes in lighting. Is there a way to define a minimum value, and allow the camera to automatically adjust exposure_speed above that value?

rotwang
Posts: 243
Joined: Sat Dec 07, 2013 1:12 pm

Re: PiCamera rolling shutter problem

Thu Feb 04, 2016 12:29 pm

Have you considered using a DC driven LED, with current controlled by choice of series resistor, no possibility of flicker, and illumination level easily set. That would be the first thing I would try.
Roger
kkjkearney wrote:Through trial and error, I arrived at an acceptable exposure_speed of about 15,000. Multiples of any value made no difference.

As I mentioned, fixing the exposure_speed takes away much of the camera's ability to adjust to changes in lighting. Is there a way to define a minimum value, and allow the camera to automatically adjust exposure_speed above that value?

jolosan
Posts: 20
Joined: Mon Feb 11, 2013 9:10 pm

Re: PiCamera rolling shutter problem

Mon May 28, 2018 10:10 am

Hello, we are doing a School project with a raspberry pi camera mounted on a drone.
The problem we are facing now is the jello effect because of the rolling shutter sensor of the picamera. Exactly the same problem of this topic.
https://www.dropbox.com/s/vgo7p1thvboui ... 1.jpg?dl=0

Here is the code:

Code: Select all

from picamera import PiCamera
from time import sleep
from datetime import datetime

camera = PiCamera()
camera.shutter_speed = 33116
camera.exposure_speed = 33116

camera.resolution= (1640, 1232)
fecha=datetime.now().strftime("%m_%d_%Y_%H_%M_%S")
When programming your code in python it gives compiling problems:

Code: Select all

$python3 timeLapse_shutter_exposure2.py 
Traceback (most recent call last):
  File "timeLapse_shutter_exposure2.py", line 7, in <module>
    camera.exposure_speed = 33116
AttributeError: can't set attribute
Any help would be appreciated.
Regards,

Return to “Camera board”