raspberrypi / userland

Source code for ARM side libraries for interfacing to Raspberry Pi GPU.
BSD 3-Clause "New" or "Revised" License
2.04k stars 1.09k forks source link

Any solution to the full manual mode for RasberryPi camera ? #151

Closed rapitz closed 7 years ago

rapitz commented 10 years ago

I am a real starter on this, but I need that mode for photometry. So far it seems that is quite difficult. Is there any hope ?

JamesH65 commented 10 years ago

What specifically are your requirements? You can already set the shutter for example, but what else do you want to do?

rapitz commented 10 years ago

Dear James, I am a real starter on this, but I have experience in building photometric devices for analytical instruments. I am building a mobile device for photometry and for that, is very important to fix both shutter speed and aperture. I have done that using an ImageSource astronomy camera that is full manual and the prtotype works fine. However, if I can use the Raspi-cam, the device will be not only smaller but also quite cheap. So far I have not found any information on the full manual mode for the Rp camera. Thanks for your kind attention to this matter. Rafael

On Fri, Mar 14, 2014 at 1:07 PM, JamesH65 notifications@github.com wrote:

What specifically are your requirements? You can already set the shutter for example, but what else do you want to do?

Reply to this email directly or view it on GitHubhttps://github.com/raspberrypi/userland/issues/151#issuecomment-37675011 .

6by9 commented 10 years ago

Aperture on the Pi sensor is fixed anyway. Shutter speed can be set in raspistill with the -ss parameter. ISO should be selectable with -iso. AWB can now be fixed with "-awb off" and "-awbg ," (just being released at the moment.

Which other parameters are you wanting to change.

rapitz commented 10 years ago

Dear James, thanks again for your kind attention. I will try the ISO and AWB settings and fix the shutter speed accordingly. Best personal regards, Rafael

On Wed, Mar 26, 2014 at 6:58 AM, 6by9 notifications@github.com wrote:

Aperture on the Pi sensor is fixed anyway. Shutter speed can be set in raspistill with the -ss parameter. ISO should be selectable with -iso. AWB can now be fixed with "-awb off" and "-awbg ," (just being released at the moment.

Which other parameters are you wanting to change.

Reply to this email directly or view it on GitHubhttps://github.com/raspberrypi/userland/issues/151#issuecomment-38672982 .

rapitz commented 10 years ago

Dear James, after answering your last instructions, I was looking into my Raspi-Cam documentation (July 2013) and do not find any reference to the -ss parameter. Where can I get a more recent documentation on the RP-cam ? Thanks R

On Wed, Mar 26, 2014 at 11:50 AM, Rafael Apitz-Castro rapitz@gmail.comwrote:

Dear James, thanks again for your kind attention. I will try the ISO and AWB settings and fix the shutter speed accordingly. Best personal regards, Rafael

On Wed, Mar 26, 2014 at 6:58 AM, 6by9 notifications@github.com wrote:

Aperture on the Pi sensor is fixed anyway. Shutter speed can be set in raspistill with the -ss parameter. ISO should be selectable with -iso. AWB can now be fixed with "-awb off" and "-awbg ," (just being released at the moment.

Which other parameters are you wanting to change.

Reply to this email directly or view it on GitHubhttps://github.com/raspberrypi/userland/issues/151#issuecomment-38672982 .

shrx commented 10 years ago

That documentation is clearly outdated. I'm not sure if there's an up-to-date version available.

rapitz commented 10 years ago

Thanks, I'll look around if there is an updated one. R

On Fri, Mar 28, 2014 at 6:24 PM, shrx notifications@github.com wrote:

That documentation is clearly outdated. I'm not sure if there's an up-to-date version available.

Reply to this email directly or view it on GitHubhttps://github.com/raspberrypi/userland/issues/151#issuecomment-38976457 .

6by9 commented 10 years ago

Execute "raspistill" with no arguments and you get the help text. That is kept up to date as new features are added.

raspistill Camera App v1.3.6

Runs camera for specific time, and take JPG capture at end if requested

usage: raspistill [options]

Image parameter commands

-?, --help      : This help information
-w, --width     : Set image width <size>
-h, --height    : Set image height <size>
-q, --quality   : Set jpeg quality <0 to 100>
-r, --raw       : Add raw bayer data to jpeg metadata
-o, --output    : Output filename <filename> (to write to stdout, use '-o -'). If not specified, no file is saved
-l, --latest    : Link latest complete image to filename <filename>
-v, --verbose   : Output verbose information during run
-t, --timeout   : Time (in ms) before takes picture and shuts down (if not specified, set to 5s)
-th, --thumb    : Set thumbnail parameters (x:y:quality) or none
-d, --demo      : Run a demo mode (cycle through range of camera options, no capture)
-e, --encoding  : Encoding to use for output file (jpg, bmp, gif, png)
-x, --exif      : EXIF tag to apply to captures (format as 'key=value') or none
-tl, --timelapse        : Timelapse mode. Takes a picture every <t>ms
-fp, --fullpreview      : Run the preview using the still capture resolution (may reduce preview fps)
-k, --keypress  : Wait between captures for a ENTER, X then ENTER to exit
-s, --signal    : Wait between captures for a SIGUSR1 from another process
-g, --gl        : Draw preview to texture instead of using video render component
-gc, --glcapture        : Capture the GL frame-buffer instead of the camera image

Preview parameter commands

-p, --preview   : Preview window settings <'x,y,w,h'>
-f, --fullscreen        : Fullscreen preview mode
-op, --opacity  : Preview window opacity (0-255)
-n, --nopreview : Do not display a preview window

Image parameter commands

-sh, --sharpness        : Set image sharpness (-100 to 100)
-co, --contrast : Set image contrast (-100 to 100)
-br, --brightness       : Set image brightness (0 to 100)
-sa, --saturation       : Set image saturation (-100 to 100)
-ISO, --ISO     : Set capture ISO
-vs, --vstab    : Turn on video stabilisation
-ev, --ev       : Set EV compensation
-ex, --exposure : Set exposure mode (see Notes)
-awb, --awb     : Set AWB mode (see Notes)
-ifx, --imxfx   : Set image effect (see Notes)
-cfx, --colfx   : Set colour effect (U:V)
-mm, --metering : Set metering mode (see Notes)
-rot, --rotation        : Set image rotation (0-359)
-hf, --hflip    : Set horizontal flip
-vf, --vflip    : Set vertical flip
-roi, --roi     : Set region of interest (x,y,w,d as normalised coordinates [0.0-1.0])
-ss, --shutter  : Set shutter speed in microseconds

Notes

Exposure mode options :
auto,night,nightpreview,backlight,spotlight,sports,snow,beach,verylong,fixedfps,antishake,fireworks

AWB mode options :
off,auto,sun,cloud,shade,tungsten,fluorescent,incandescent,flash,horizon

Image Effect mode options :
none,negative,solarise,sketch,denoise,emboss,oilpaint,hatch,gpen,pastel,watercolour,film,blur,saturation,colourswap,washedout,posterise,colourpoint,colourbalance,cartoon

Metering Mode options :
average,spot,backlit,matrix

Preview parameter commands

-gs, --glscene  : GL scene square,teapot,mirror,yuv,sobel
-gw, --glwin    : GL window settings <'x,y,w,h'>

The same goes for raspivid or raspiyuv.

rapitz commented 10 years ago

Fine, I appreciate all the help I've got from you. Now I may start the real experiments. Rafael

On Mon, Mar 31, 2014 at 6:17 AM, 6by9 notifications@github.com wrote:

Execute "raspistill" with no arguments and you get the help text. That is kept up to date as new features are added.

raspistill Camera App v1.3.6

Runs camera for specific time, and take JPG capture at end if requested

usage: raspistill [options]

Image parameter commands

-?, --help : This help information -w, --width : Set image width -h, --height : Set image height -q, --quality : Set jpeg quality <0 to 100> -r, --raw : Add raw bayer data to jpeg metadata -o, --output : Output filename (to write to stdout, use '-o -'). If not specified, no file is saved -l, --latest : Link latest complete image to filename -v, --verbose : Output verbose information during run -t, --timeout : Time (in ms) before takes picture and shuts down (if not specified, set to 5s) -th, --thumb : Set thumbnail parameters (x:y:quality) or none -d, --demo : Run a demo mode (cycle through range of camera options, no capture) -e, --encoding : Encoding to use for output file (jpg, bmp, gif, png) -x, --exif : EXIF tag to apply to captures (format as 'key=value') or none -tl, --timelapse : Timelapse mode. Takes a picture every ms -fp, --fullpreview : Run the preview using the still capture resolution (may reduce preview fps) -k, --keypress : Wait between captures for a ENTER, X then ENTER to exit -s, --signal : Wait between captures for a SIGUSR1 from another process -g, --gl : Draw preview to texture instead of using video render component -gc, --glcapture : Capture the GL frame-buffer instead of the camera image

Preview parameter commands

-p, --preview : Preview window settings <'x,y,w,h'> -f, --fullscreen : Fullscreen preview mode -op, --opacity : Preview window opacity (0-255) -n, --nopreview : Do not display a preview window

Image parameter commands

-sh, --sharpness : Set image sharpness (-100 to 100) -co, --contrast : Set image contrast (-100 to 100) -br, --brightness : Set image brightness (0 to 100) -sa, --saturation : Set image saturation (-100 to 100) -ISO, --ISO : Set capture ISO -vs, --vstab : Turn on video stabilisation -ev, --ev : Set EV compensation -ex, --exposure : Set exposure mode (see Notes) -awb, --awb : Set AWB mode (see Notes) -ifx, --imxfx : Set image effect (see Notes) -cfx, --colfx : Set colour effect (U:V) -mm, --metering : Set metering mode (see Notes) -rot, --rotation : Set image rotation (0-359) -hf, --hflip : Set horizontal flip -vf, --vflip : Set vertical flip -roi, --roi : Set region of interest (x,y,w,d as normalised coordinates [0.0-1.0]) -ss, --shutter : Set shutter speed in microseconds

Notes

Exposure mode options : auto,night,nightpreview,backlight,spotlight,sports,snow,beach,verylong,fixedfps,antishake,fireworks

AWB mode options : off,auto,sun,cloud,shade,tungsten,fluorescent,incandescent,flash,horizon

Image Effect mode options : none,negative,solarise,sketch,denoise,emboss,oilpaint,hatch,gpen,pastel,watercolour,film,blur,saturation,colourswap,washedout,posterise,colourpoint,colourbalance,cartoon

Metering Mode options : average,spot,backlit,matrix

Preview parameter commands

-gs, --glscene : GL scene square,teapot,mirror,yuv,sobel -gw, --glwin : GL window settings <'x,y,w,h'>

The same goes for raspivid or raspiyuv.

Reply to this email directly or view it on GitHubhttps://github.com/raspberrypi/userland/issues/151#issuecomment-39075240 .

ivannaz commented 9 years ago

I think I still have an issue regarding full manual exposure.

I can't keep "analog gain" and "digital gain" frozen at some specific - or minimum - values.

While I can specify exposure time and ISO, the camera still sets its analog and digital gain by itself. And it is bad at it! When the center and most of the area is dark, and only a corner have light, the analog and digital gains increase to the point of saturating this corner area. Perhaps, in some "automatic exposure" criteria, this is OK. But we are talking about manual exposure here, and there is nothing manual in this camera attempt of outsmarting me and destroying the scene details in the corner.

This is an example:

raspistill -t 0 -set --shutter 10000 -awb off -awbg 1.0,1.0 -ISO 100

mmal: Exposure now 9977, analog gain 256/256, digital gain 640/256 mmal: AWB R=256/256, B=256/256 mmal: Exposure now 9977, analog gain 256/256, digital gain 832/256 mmal: AWB R=256/256, B=256/256 mmal: Exposure now 9977, analog gain 1024/256, digital gain 256/256 mmal: AWB R=256/256, B=256/256 mmal: Exposure now 9977, analog gain 1024/256, digital gain 512/256 mmal: AWB R=256/256, B=256/256 mmal: Exposure now 9977, analog gain 1024/256, digital gain 640/256 mmal: AWB R=256/256, B=256/256 mmal: Exposure now 9977, analog gain 1024/256, digital gain 704/256 mmal: AWB R=256/256, B=256/256 mmal: Exposure now 9977, analog gain 1792/256, digital gain 419/256 mmal: AWB R=256/256, B=256/256 mmal: Exposure now 9977, analog gain 1792/256, digital gain 428/256 mmal: AWB R=256/256, B=256/256 mmal: Exposure now 9977, analog gain 1968/256, digital gain 394/256 mmal: AWB R=256/256, B=256/256 mmal: Exposure now 9977, analog gain 1968/256, digital gain 396/256 mmal: AWB R=256/256, B=256/256 mmal: Exposure now 9977, analog gain 2016/256, digital gain 387/256 mmal: AWB R=256/256, B=256/256 mmal: Exposure now 9977, analog gain 2016/256, digital gain 388/256 mmal: AWB R=256/256, B=256/256 mmal: Exposure now 9977, analog gain 2016/256, digital gain 389/256 mmal: AWB R=256/256, B=256/256

And the corner scene is now saturated.

Is there a way to get the raw bayer data from the sensor? Or at least shut down any attempt to correct anything, and let me specify the manual exposure I need? It would be great if we had "-ex manual", for instance. Can this be done through mmal?

Regards,

Ivan

ethanol100 commented 9 years ago

Try adding -ev -24 to your command. This will try to reduce the gains to a minimum and should give you analog gain 256/256, digital gain 256/256.

Getting the raw sensor data will not be of much help for you. The analog gain is applied to the sensor and will change the raw bayer data too. There is the new possibility to get the raw bayer data, but it is fixed to a single value of shutter speed see https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=109137.

ivannaz commented 9 years ago

Thank you! It is a shame I have not tried the ev settings before - perhaps because I did not, and still does not, understand exactly what this -24 means, and why -25 is not so good. I glanced at the sources, but it seems that is setting is dealt only in gpu arena.

Now gains are, if not fixed, at least less variable, and corner saturation is less frequent.

raspistill -t 0 -set --shutter 100 -awb off -awbg 1.0,1.0 -ISO 100 -ev -24 mmal: Exposure now 83, analog gain 256/256, digital gain 256/256 mmal: AWB R=256/256, B=256/256 mmal: Exposure now 83, analog gain 1024/256, digital gain 256/256 mmal: AWB R=256/256, B=256/256 mmal: Exposure now 83, analog gain 1792/256, digital gain 256/256 mmal: AWB R=256/256, B=256/256 mmal: Exposure now 83, analog gain 1968/256, digital gain 256/256 mmal: AWB R=256/256, B=256/256 mmal: Exposure now 83, analog gain 2016/256, digital gain 256/256 mmal: AWB R=256/256, B=256/256 mmal: Exposure now 83, analog gain 2032/256, digital gain 256/256 mmal: AWB R=256/256, B=256/256

The digital gain seems locked, and while the analog gain is still uncontrolled, it needs really dark scenes to ramp up (notice the short exposure time). I still can induce corner saturation, but only in more extreme cases. In dimly lit scenes, with just a small bright object (say, a CCFT lamp), the analog gain goes up only when the object not at center - and adding "-mm matrix" improved that.

It is still not an strict manual exposure, but is close enough to be useful.

Thank you.

Regards,

Ivan

6by9 commented 9 years ago

EV is in 1/6ths of a stop, so -24 is -4 stops. If shutter speed hadn't been fixed, then it would also try adjusting that. It can also be set as a MMAL_RATIONAL_T to explicitly set the number of stops in the range -4 to +4 (although the exposure mode will clip the max gain combination and shutter speed), but it is still in 1/6ths under the bonnet, so don't expect finer grained control. ISO setting seems to be slightly odd that it does not obey it during preview, but should on a still capture. Not something I'm going to fiddle with as it is fiendishly complicated.

As @ethanol100 has said, yes you can now get to the raw data and do the lot yourself, but you need to understand the register settings. Shutter time is covered in the unofficial datasheet that can be obtained from the internet, as is analogue gain. rawcam as checked in gives an exposure time of 2.275ms, and analogue gain of (I think) x2.18 - they were the values I happened to have to hand, and must confess to not having copied that bit from jbeale's I2C dumps. Line lengths for the various modes have been quoted on the forums before. As mentioned on the thread there has been some work done on the Freescale i.MX6 platform to write a driver for OV5647, so www.viionsystems.com/UbuntuImages/ov5647_mipi.c might give some useful information for setting exposure time and gain to values of your choosing. I don't know where they got their information from, but it looks correct.

edit: Corrected the exposure time from 36.ms.

ivannaz commented 9 years ago

I hope the -ev -24 would be enough, and further measures unnecessary. Thank you.

I removed the default lens and installed an M12. Noticed something odd: While expecting an featureless and smooth image of a clean, uniformly lit paper sheet, the image shows all four corners brighter than the center image level. As if the sensor - or the GPU - were doing some sort of vignetting compensation of the original lens. Do you happen to know if the GPU does that? If it does, would the raw access bypass this correction?

JamesH65 commented 9 years ago

Yes, the GPU has a lens shading correction table tuned to the original lens. Using raw will indeed bypass this - the data in raw is direct from the sensor, so the only setting of relevance will be the analog gain.

spikedrba commented 9 years ago

is there any solution/recommendation (other than using raw), to compensate/remove the shading correction if one uses a different lens?

JamesH65 commented 9 years ago

No, afraid not. Best bet is to write your own lens shading code that compensates. Take the picture of the flat field, then work out what adjustments you need to make to get a resulting flat image, then apply as necessary.

shrx commented 9 years ago

Unfortunately I can't find the source, but if I remember correctly there were plans to have the camera use dynamic (i.e., lens-specific) color and brightness corrections, but I guess it was put on hold or deemed unfeasible.

6by9 commented 9 years ago

The dynamic lens shading algo is active, but only if you enable a statistics pass on stills capture - "-st" option in raspistill. Doing so also forces recomputing all AWB gains, so don't complain when "-awbg" then fails, and potentially AE digital gain. Trying to integrate the fixes to run dynamic lens shading without needing a stats pass is still on my "to do" list, but the branch it was fixed on had significantly diverged from the Pi branch so the changes need significant rework. No longer working for Broadcom rather puts a damper on the time available to play with Pi firmware.

spikedrba commented 9 years ago

@JamesH65 bear with a noob if you can, any pointer of what I'd need to read up and understand in order to do that? or is this yet another case of completely missing the point and this being something requiring a ton of understanding and many months man hours to accomplish?

shrx commented 9 years ago

I wouldn't say months, but it's not straightforward: http://en.wikipedia.org/wiki/Flat-field_correction http://www.astronomie-und-internet.de/docs/Creating%20a%20Flatfield%20Calibrating%20Image.pdf

6by9 commented 9 years ago

There's no way to set your own lens shading tables into the ISP, so if you were to try calibrating it yourself, then you've got to implement the entire pipeline yourself. That is lots of work, or you've got to make use of someone else's pipe which is unlikely to be trivial, or realtime. IIRC Lens shading correction is done in the Bayer domain as you end up with tables for each of the 4 colour channels (the 2 greens are generally treated independently). I don't know what results you'll get trying to correct for that at the back end of the pipe.

namork commented 8 years ago

has there been an update to disable lens compensation or load an individual compensation in the meantime?

JamesH65 commented 8 years ago

Not that I am aware off. Any thoughts 6x9?

On 22 February 2016 at 11:21, namorrellek notifications@github.com wrote:

has there been an update to disable lens compensation or load an individual compensation in the meantime?

— Reply to this email directly or view it on GitHub https://github.com/raspberrypi/userland/issues/151#issuecomment-187129034 .

6by9 commented 8 years ago

As stated on the forums (https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=126220), no, there have been no changes to the lens shading arrangements.

Disabling lens shading isn't supported and is unlikely to produce a flat colour representation, and producing your own tables isn't supported either.

rwb27 commented 8 years ago

Hello, I was wondering if there might have been any change on this since the camera module v2 came out - presumably there's a different lens shading correction for v1 and v2 of the camera module; is there now a way to switch between them?
I've been using the camera board in a microscope, where the optics really are pretty much uniform; the ability to turn off lens shading correction would be really nice (and much more elegant than the current hack of getting raw images and debayering them ourselves). It would be great to keep the GPU-powered preview, video encoding, etc. etc. but just avoid the lens shading step.

Thanks in advance for any help,

Richard

6by9 commented 8 years ago

No, no change - it's a question of resourcing the change when very few people will make use of it. The V2 camera uses an automatic lens shading algorithm, but then again so did the V1 to a lesser degree.

rwb27 commented 8 years ago

Fair enough - thanks for the answer. Perhaps with some experimentation I might be able to get the automatic lens shading to do the right thing - and if I do I'll certainly post it somewhere.

6by9 commented 7 years ago

Closing due to inactivity and al lfeatures requested are implemented.

You can now disable or provide an alternate lens shading grid - https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=190586

Commit https://github.com/raspberrypi/userland/commit/212184f0f1fdf76eff31e3875fdeb2b7980cd5cb adds -ag <float> and -dg <float> options to the raspicam apps to fix the analogue and digital gains respectively. It is using part of the AE/AGC algorithm, so do NOT set -ex off with these options.

If there is something specific that you find doesn't work with it, then please raise a new issue.