raspberrypi / userland

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

raspivid MJPEG always too dark, how to push the gain? #424

Closed VigibotDev closed 6 years ago

VigibotDev commented 7 years ago

I need >= 25FPS (slower is useless for my home real-time robotics)

I can't set the - ISO parameters, it's always ignored even with - ex off

raspivid -fps 25 -w 720 -h 576 -ex off -ISO 800 -cd MJPEG -o /var/www/temp/video.mjpg

tested many combinations of - ex off/auto/night without success

How to push up this gain? (noise is not a problem!)

VigibotDev commented 7 years ago
(root|~) vcgencmd version
Sep 12 2017 15:25:20
Copyright (c) 2012 Broadcom
version 3fbb171d1950eb3789eb8e37ba11e01079a37239 (clean) (release)
(root|~)

all last available version on raspberry pi 3 (stretch)

JamesH65 commented 7 years ago

Why have you opened three issues for the same problem? It's not going to make things progress any faster.

On 19 Sep 2017 07:40, "Pascal" notifications@github.com wrote:

(root|~) vcgencmd version Sep 12 2017 15:25:20 Copyright (c) 2012 Broadcom version 3fbb171d1950eb3789eb8e37ba11e01079a37239 (clean) (release) (root|~)

all last available version on raspberry pi 3 (stretch)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_raspberrypi_userland_issues_424-23issuecomment-2D330444418&d=DwMFaQ&c=DpyQ_ftY536pf7wCBQXXU58xADDRY77THQzJu1OmzOo&r=w09_2ePv8G3zRjoV19Wm1Q6rI7CDlOns4PuRv2hHkek&m=VLYZPbW1YiFX1SJWwE9KoXTUkA9tQ1mXNmliArFLHXc&s=tU_2-viVbYeWKnZsH33i5UuIHnN72YFmiL5aM2Wb3rw&e=, or mute the thread https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_ADqrHTVTCAjtIavQzg3RCGrNDD4SNFEFks5sj2HYgaJpZM4Pb6iA&d=DwMFaQ&c=DpyQ_ftY536pf7wCBQXXU58xADDRY77THQzJu1OmzOo&r=w09_2ePv8G3zRjoV19Wm1Q6rI7CDlOns4PuRv2hHkek&m=VLYZPbW1YiFX1SJWwE9KoXTUkA9tQ1mXNmliArFLHXc&s=cWUeWiRyha72peYRSB14qbg3X0-zIUfXcXMg61HrcME&e= .

VigibotDev commented 7 years ago

Sorry for this, I opened my own issue because I think my question is simpler : "how to push the gain and get the noise of the sensor visible on MJPEG video ?"

You can close this one or any duplicate, I am at your disposal for tests.

There is a dedicated raspberry pi 3 24/7 online here - the raspberry pi camera port of my home robot project - where I need more video gain : http://www.serveurperso.com:8080

To compare, here is the working camera system (my original project) with very sensitive CMOS and HAD2 camera : https://www.serveurperso.com/?page=robot

(no ads on any URL)

6by9 commented 7 years ago

Remove -ex off. ISO is part of the automatic gain control algorithm, therefore turning that off stops ISO working. Add -set and the app will print out the current exposure time, analog and digital gains, and white balance gains. You should see analog gain at ~2520/256 and digital gain at ~500/256 for ISO 800.

Also remember that increasing the gain whilst auto exposure is still running will just result in the exposure time being shortened. To adjust the target brightness of the scene you need to be increasing the EV to alter the target.

VigibotDev commented 7 years ago

I already tested -ISO 800 with -ev 10 and without -ex without significative improvements. I re do this test with -set. Parameters are displayed on stdout or OSD?

6by9 commented 7 years ago

Parameters are displayed on stdout or OSD?

stdout (which would have been blatantly obvious if you tried it).

Run raspivid -fps 25 -w 720 -h 576 -cd MJPEG -o /var/www/temp/video.mjpg -set If the exposure time has hit 39840 usecs and analog gain is at 2521/256 (x9.84) then you have hit the maximum the sensor will do. Unless you can rewrite the laws of physics then that is a hard limitation. (I'm assuming you're using a V2 IMX219 sensor. The V1 OV5647 has slightly different maximum values).

You can use the -br (brightness) option to crank up the gain later in the processing pipe. Range is 0 to 100.

JamesH65 commented 7 years ago

OV5647 max figures are :

39806us, 2048/256 analog gain.

What specifically are you trying to do, because it all seem to be working as I would expect?

On 19 September 2017 at 11:31, 6by9 notifications@github.com wrote:

Parameters are displayed on stdout or OSD?

stdout (which would have been blatantly obvious if you tried it).

Run raspivid -fps 25 -w 720 -h 576 -cd MJPEG -o /var/www/temp/video.mjpg -set If the exposure time has hit 39840 usecs and analog gain is at 2521/256 (x9.84) then you have hit the maximum the sensor will do. Unless you can rewrite the laws of physics then that is a hard limitation. (I'm assuming you're using a V2 IMX219 sensor. The V1 OV5647 has slightly different maximum values).

You can use the -br (brightness) option to crank up the gain later in the processing pipe. Range is 0 to 100.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/raspberrypi/userland/issues/424#issuecomment-330498505, or mute the thread https://github.com/notifications/unsubscribe-auth/ADqrHciJqofnbX7oraK-Wr1JhvzgocZZks5sj5gPgaJpZM4Pb6iA .

-- James Hughes Principal Software Engineer, Raspberry Pi (Trading) Ltd

VigibotDev commented 7 years ago

I'm away from my raspberry (at work) and there is too light to test for now:D I run your cmdline tonight. I use mjpeg-streamer experimental it give the same parameters as raspivid I configured like this for now.

(root|~/scripts) cat mjpg-streamer.sh
#!/bin/bash

pat=/root/mjpg-streamer/mjpg-streamer-experimental
bin=$pat/mjpg_streamer

i="input_raspicam.so -fps 25 -q 10 -x 720 -y 576 -rot 180 -ex night -ISO 800 -ev 10"
o="output_http.so -p 8080"

LD_LIBRARY_PATH=$pat $bin -i "$i" -o "$o" -b

This is bad if the hardware have gain limitation to hide the sensor noise. On many module I can do it. Add brightness is bad because it's not automatic and white parts of the picture get overexposed on day light sorry for my English

VigibotDev commented 7 years ago

I look on Google to get you information about the sensor board I use.

VigibotDev commented 7 years ago

5 MP Omnivision 5647

JamesH65 commented 7 years ago

The max analogue gain that sensor can do is 8, which is what I am seeing being used.

VigibotDev commented 7 years ago

I just want push up the gain when I'm in near night. clearly the sensor is underexposed and I want to see the little CMOS noise at night.

VigibotDev commented 7 years ago

you say there is a hardware limitation of 8 for the analog gain this is bad:( no way to hack?

JamesH65 commented 7 years ago

As for sensor noise, to see that you would need to turn of the denoise processing - gain is not the only thing that can affect the pixels. There are over 20 stages of processing done to the bayer from the camera before its get displayed/encoded.

AFAIK, 8 is the maximum analogue gain the sensor can support.

VigibotDev commented 7 years ago

do you know another way to get a hardware accelerated MJPEG stream on raspberry (an PAL analog capture is good for me) ?

VigibotDev commented 7 years ago

I close this issue after the last test tonight...

JamesH65 commented 7 years ago

Sorry, not sure what you mean by accelerated MJPEG stream.

VigibotDev commented 7 years ago

raspivid is very fast : do you process by software or get the MJPEG frames from hardware ?

VigibotDev commented 7 years ago

Look the picture (there is clouds lol) : http://www.serveurperso.com:8080/ index For me this sensor is crappy underexposed. Even with maximum tuning:( I must add the dynamic range compensation to high

JamesH65 commented 7 years ago

The entire path from sensor to H264/MJPEG is done in the GPU using HW blocks. The final result is passed to the ARM/Linux userland. The GPU does have software on it to coordinate everything, but that is closed source firmware.

VigibotDev commented 7 years ago

input_raspicam.so -fps 25 -q 10 -x 720 -y 576 -rot 180 -ex night -ISO 800 -ev 10 -drc high I don't get the video when I add the -drc option. I must test with raspivid and if it work I ask the mjpg encoder experimental author.

VigibotDev commented 7 years ago

versus this one (HAD2 sensor -> analog video downlink -> expensive & own design video receiver -> capture board -> mjpg streamer)

ccd

VigibotDev commented 7 years ago

And the same HAD2 sensor on very dark :

sensornoise

sensitivity/gain is "10 or 100 more OK" than the raspicam...

VigibotDev commented 7 years ago

And my better camera same light level (near 1 inch CMOS b&w sensor for astronomy)

astrocam

6by9 commented 7 years ago

B&W gains you photons hitting the sensor because you remove the colour filters.

The OV5647 has 1.4x1.4um pixels (IMX219 is 1.1x1.1um). Looking at https://www.ptgrey.com/exview-had-ccd-ii-sensor-technology the smallest of those has 3.1. So that's at least 4.9 times as many photons.

And I won't ask about the difference in price....

Use the appropriate tool for your job - that may not be the Pi camera module. Despite the smaller pixel size the IMX219 is typically more sensitive, but not orders of magnitude.

I did start on a patch set that allowed manual control of analog and digital gain, but I can't recall what state it was in. It's not automatic though, so you'd be relying on auto exposure to handle changes in brightness. The use case is too limited to add in extra tuner configs.

VigibotDev commented 7 years ago

I know... it is a pity that it is not possible to push the automatic gain on the Raspicam, because with the manual light and contrast settings (80 and 90) I can get a descent sensitivity on dark, bug way over exposed on day... This is an important feature missing. Many cheap webcam can do it and I we clearly see the CMOS working at maximum performance. The pi cam look always very under exploited on night scenes.

But this gain problem is only for video @ fast FPS because slow shutter speed give amazing result on raspicam (I have many PI webcam runing in automatic FPS mode https://www.serveurperso.com/?page=webcam&n=11 doing long exposure )

VigibotDev commented 7 years ago

For all my PI cam, as objective I use the two first, CS and PCB mount to get a maximum of light :

3_types_camera_pi

but problem is not the sensor sensitivity or optics, it's a too limited automatic maximum gain. I do this to make a cheap opensource version of my project.

interesting thread about the gain of raspicam : https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=131558 https://www.raspberrypi.org/forums/viewtopic.php?t=156754

6by9 commented 7 years ago

So actually you haven't purchased a camera module from Raspberry Pi, but you're complaining about it.....

VigibotDev commented 7 years ago

I have one official but give the way badest result (too narrow FOV and very poor sensitivity). pinhole are bulshit.

VigibotDev commented 7 years ago

(and of course there is the same under exposure problem on the official)

VigibotDev commented 7 years ago

-ex night alone give the best result possible... An automatic tuning of light contrast (before MJPEG compression) are needed to get the best picture...

JamesH65 commented 7 years ago

Have you tried the brightness and contrast setting from here?

https://www.raspberrypi.org/documentation/raspbian/applications/camera.md

VigibotDev commented 7 years ago

Yes but it's not automatic... With light @ 80 and contrast @ 90 I get good performance on night but overexposed the day...

VigibotDev commented 7 years ago

I'm at home I tested the 6by9 cmdline :

raspivid -fps 25 -w 720 -h 576 -cd MJPEG -o /var/www/temp/video.mjpg -set

mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=274/256, B=332/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=278/256, B=333/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=281/256, B=334/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=284/256, B=335/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=287/256, B=336/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=290/256, B=337/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=287/256, B=330/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=284/256, B=323/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=281/256, B=316/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=278/256, B=310/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=276/256, B=304/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=274/256, B=298/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=272/256, B=294/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=270/256, B=290/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=268/256, B=287/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=266/256, B=284/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=264/256, B=281/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=263/256, B=278/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=275/256, B=276/256
mmal: Exposure now 39827, analog gain 2048/256, digital gain 383/256
mmal: AWB R=286/256, B=274/256
rodizio1 commented 6 years ago

So actually you haven't purchased a camera module from Raspberry Pi, but you're complaining about it.....

I have one official but give the way badest result (too narrow FOV and very poor sensitivity). pinhole are bulshit.

I also buy 3rd-Party cameras. Not because I want to save money, support copy-cats or harm the Raspberry Foundation. Problem is simply, there is no alternative lens for the Raspberry Cams and the FOV of the lens is way too small for my application.

Is there a special reason the cam was designed with a hole-pattern that is exatly one mm off compared to M12 lens mounting holes?

Maybe the Raspberry foundation could consider:

VigibotDev commented 6 years ago

For a robot the wide angle / fisheye is 100% mandatory, you can test to move my 3rd-camera here : http://www.serveurperso.com:8080/ robot

JamesH65 commented 6 years ago

This issue will be closed within 30 days unless further interactions are posted. If you wish this issue to remain open, please add a comment. A closed issue may be reopened if requested.

JamesH65 commented 6 years ago

Closing due to lack of activity. Please request to be reopened if you feel this issue is still relevant.