RemyC
Posts: 11
Joined: Thu Nov 17, 2016 10:05 am

Using Flash_mode with Camera V2

Thu Nov 17, 2016 10:24 am

Hi,

As the title says, I am trying to use the flash mode with the picamera V2 using a RPI3.
What I want to do is to illumate with a LED just one frame and capture it.
I tried a trick like

Code: Select all

GPIO.output(12, GPIO.HIGH)
camera.capture('FlashTest.jpg')
GPIO.output(12, GPIO.LOW
But the LED is on for too long, 1,1 second.
Since I am at 30 FPS, I would like to flash just one frame, for less than 33 ms.

I then tried to use the Flash_mode following the tuto :http://picamera.readthedocs.io/en/relea ... figuration Using a flash with the camera, but it doesnt work.

Looks like the tuto is made for RPI2.
I found the correct dt-blob.dts for RPI3 https://github.com/raspberrypi/firmware ... t-blob.dts and modified it, but when I compile it, there is a ton of warning : "has a unit name but no reg property".

When I reboot the RPI3, the GPIO12 is correctly set as an output, but nothing happens when I use

Code: Select all

camera.flash_mode = 'on'
camera.capture('FlashTest.jpg')
Is there something I am doing wrong ?
I am not really a good user of RPI and linux OS, so if anyone could give me a hint, would be nice.

Thanks.

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

Re: Using Flash_mode with Camera V2

Thu Nov 17, 2016 4:42 pm

The PiCamera docs have been updated in latest, but hadn't made 1.12 let alone 1.10 that you were looking at.

Doing

Code: Select all

wget https://raw.githubusercontent.com/raspberrypi/firmware/master/extra/dt-blob.dts
dtc -I dts -O dtb -o dt-blob.bin dt-blob.dts
gives me no errors, so if you're seeing errors off dtc then you've probably made a typo. I'd suggest trying again, and quote the full errors (preferably using the code tags to make things easier to read and avoid losing formatting).

The flash will be on for ~99ms assuming a 33ms exposure. It is a rolling shutter camera so not all lines of the image are exposed at the same time. You therefore have to factor in the frame readout time as well as exposure time. Doing a still capture will use the full 8MPix mode which requires approx 66ms to readout (15fps max).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

RemyC
Posts: 11
Joined: Thu Nov 17, 2016 10:05 am

Re: Using Flash_mode with Camera V2

Fri Nov 18, 2016 12:28 pm

Thank you for your answer.
I don't know why google put me on such an old version of the doc. Spent hours finding the right DTC file...

Anyway, it now works and I can flash the LED. However, the led flash seems to only work with Exposure mode auto ?
I would like to use it with my own settings (exposure mode off, gain and shutter speed). Is that possible ?

I understand that with exposure mode auto, the LED flash twice so the auto settings can be set.
I tried with exposure mode off, but the LED flash only once, and apparently not during the captured frame. I can't see the LED on on the image captured.

I tried another way : setting my camera (with python), setting GPIO for the LED HIGH, calling raspitill, setting GPIO for the LED LOW, but it doesnt work either since the camera is already in use before caling raspitill.

I just want to flash my LED for about 100-200ms (the shorter, the better), for one frame, with my settings, exposure mode OFF.
Is there a way to do so ?

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

Re: Using Flash_mode with Camera V2

Fri Nov 18, 2016 2:26 pm

With exposure mode off then flash control is pretty redundant beyond the timing as there is not adaptation of exposure or gain allowed.
I wouldn't like to try and predict what the flash control does in exposure mode off.

The best approach I can think of requires a moderate level of tinkering at the MMAL level, so it depends on your C skills (or understanding of how PiCamera maps Python onto the MMAL API).

There is a parameter MMAL_PARAMETER_CAPTURE_STATUS for which the MMAL_PARAMETER_CHANGE_EVENT_REQUEST mechanism can be used to be notified of status changes. I'd need to check exactly when the MMAL_PARAM_CAPTURE_STATUS_CAPTURE_STARTED and MMAL_PARAM_CAPTURE_STATUS_CAPTURE_ENDED states get signaled as they changed slightly over time, but the basic theory is that you should get the _STARTED event when the still capture is requested, and _ENDED when it "completes" (whatever that means - exposure complete or full capture processing complete?).
I would expect that duration to be around 200ms if the _ENDED event is at exposure complete, but should be <500ms even if not.

The change is relatively easy to do in RaspiStill to try and prove the theory before doing so in PiCamera. Something like:

Code: Select all

diff --git a/host_applications/linux/apps/raspicam/RaspiStill.c b/host_applications/linux/apps/raspicam/RaspiStill.c
index c7d3f79..a63cd1c 100644
--- a/host_applications/linux/apps/raspicam/RaspiStill.c
+++ b/host_applications/linux/apps/raspicam/RaspiStill.c
@@ -862,6 +862,15 @@ static void camera_control_callback(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buf
                         );
          }
          break;
+         case MMAL_PARAMETER_CAPTURE_STATUS:
+         {
+            MMAL_PARAMETER_CAPTURE_STATUS_T *status = (MMAL_PARAMETER_CAPTURE_STATUS_T*)param;
+            if (status->status == MMAL_PARAM_CAPTURE_STATUS_CAPTURE_STARTED)
+               vcos_log_error("Started capture...");
+            else if (status->status == MMAL_PARAM_CAPTURE_STATUS_CAPTURE_ENDED)
+               vcos_log_error("Ended capture");
+         }
+         break;
       }
    }
    else if (buffer->cmd == MMAL_EVENT_ERROR)
@@ -1019,6 +1028,18 @@ static MMAL_STATUS_T create_camera_component(RASPISTILL_STATE *state)
       }
    }
 
+   {
+      MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T change_event_request =
+         {{MMAL_PARAMETER_CHANGE_EVENT_REQUEST, sizeof(MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T)},
+          MMAL_PARAMETER_CAPTURE_STATUS, 1};
+
+      status = mmal_port_parameter_set(camera->control, &change_event_request.hdr);
+      if ( status != MMAL_SUCCESS )
+      {
+         vcos_log_error("No capture status events");
+      }
+   }
+
    // Enable the camera, and tell it its control callback function
    status = mmal_port_enable(camera->control, camera_control_callback);
 
(totally untested beyond that it builds).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

RemyC
Posts: 11
Joined: Thu Nov 17, 2016 10:05 am

Re: Using Flash_mode with Camera V2

Mon Nov 21, 2016 2:26 pm

Thank you for your answer.

Well, I guess it's starting to be to complicated for my level.
Too bad the Flash isn't sync with the frame captured with exposure mode off, it would have been enough.
It's like there is only the preflash with this mode :(

I think I have no other way but to flash with GPIO High and Low during a capture..

Thank you anyway for your time and help.

RemyC
Posts: 11
Joined: Thu Nov 17, 2016 10:05 am

Re: Using Flash_mode with Camera V2

Mon Jun 19, 2017 7:22 am

Hello,

Back on this topic, trying to get a single flash signal at the start of the acquisition.
However, I am having a black image when I am in Exposure mode off. 1 Flash led but black image.
If I use exposure mode auto, I have 2 flash LED, 1 "colored" image, but auto gain and auto exposure time.

Any idea why I would have a black image on exposure mode off ?

Thank you

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

Re: Using Flash_mode with Camera V2

Mon Jun 19, 2017 8:14 am

Have you set an exposure time? The default is about 500users iirc, so without it anything but the brightest scene will be dark.
Gain should be set to x1 if you set exposure off before any frames have come through
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

RemyC
Posts: 11
Joined: Thu Nov 17, 2016 10:05 am

Re: Using Flash_mode with Camera V2

Mon Jun 19, 2017 1:59 pm

Thanks for your quick answer :)

By exposure time, you mean shutter_speed ? If so, yes I already set a value.
if there is an other way to set the exposure time, I am not aware of it. And after a quick search, I haven't found anything else besides shutter_speed...

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

Re: Using Flash_mode with Camera V2

Mon Jun 19, 2017 2:13 pm

Yes, I mean shutter speed.

What does the EXIF data in the JPEG say the exposure time and ISO are?
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

RemyC
Posts: 11
Joined: Thu Nov 17, 2016 10:05 am

Re: Using Flash_mode with Camera V2

Mon Jun 19, 2017 2:49 pm

the EXIF data says : 1/25 secondes for exposure time and ISO-6 for ISO speed, which is weird because I set "camera.iso" to 100. Unless it s not the same iso.

The things is :
- with Camera exposure mode auto and camera flash mode on, it works (got 2 flashes and 1 images, but auto gain and exposure time)

- with Camera exposure mode off and camera flash mode on, I got 1 flash but black image. And I cannot take 2 images in a row, the second one is "timed out waiting for capture to end"

- with Camera exposure mode off and "camera flash mode on" commented, I have no flashed but "colored" images, and I can take many in a row.

Code: Select all

camera.iso = 100
WBgains = ()
WBgains = (1/1, 1/1)
camera.awb_mode = 'off'
camera.awb_gains = WBgains
camera.resolution = (3200,2400)
camera.color_effects = (128, 128)
sleep(Tl) #Time left to settled all parameters 
camera.exposure_mode = 'off'
camera.framerate = 10
camera.shutter_speed = 40000

camera.flash_mode = 'on'

#Calculation of the gains product
Gana = camera.analog_gain
Gdig = camera.digital_gain
Gana = float(Gana)
Gdig = float(Gdig)
PdGains = Gana*Gdig


N=1
while (N != '10'):

    camera.capture(os.path.join(chemin, "Image%d_PdG=%.2f_JPEG.jpg" % (N,PdGains)), format = 'jpeg', quality = 100)
    print('\tAcquistion JPEG ~~> OK!')

    print('\tShutter Speed : '+str(camera.shutter_speed))
    print('\tISO : '+str(camera.iso))
    print('\tFramerate : '+str(camera.framerate))
    print('\tGain analogue : '+str(camera.analog_gain))
    print('\tGain digital : '+str(camera.digital_gain))
    N = input("Next : ")
I dont get why it won't work...

RemyC
Posts: 11
Joined: Thu Nov 17, 2016 10:05 am

Re: Using Flash_mode with Camera V2

Mon Jun 19, 2017 3:18 pm

Actually, I just need a signal when the capture of the image start (with exposure mode off). I was thinking about using a monostable for 200 or 300ms to flash my LED. Is there an other way to get the start capture signal ?

Thank you for your help.

RemyC
Posts: 11
Joined: Thu Nov 17, 2016 10:05 am

Re: Using Flash_mode with Camera V2

Wed Jun 21, 2017 11:03 am

No idea about that ? :(

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

Re: Using Flash_mode with Camera V2

Wed Jun 21, 2017 3:54 pm

Register for updates to the MMAL_PARAMETER_CAPTURE_STATUS on the control port. You should get a callback as the capture starts, and one shortly after the exposure is complete.

I'm not intending on messing with how the AE/AGC tuner and flash driver interact - it all gets too messy, and having expsoure off with flash makes little sense.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

RemyC
Posts: 11
Joined: Thu Nov 17, 2016 10:05 am

Re: Using Flash_mode with Camera V2

Fri Jun 23, 2017 8:15 am

Ok, I will try this if I can figure out how to :D

I dont get why you say there is no sense in doing a flash with exposure mode off.
Mode off just disable the automatic gain control, fixing the values of digital gain et analog gain right ?
I mean, isnt it like when you use a camera with no automatic control and just a flash ? To have your own settings, and then the brightness you wish.

Thank you for your help anyway :)

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

Re: Using Flash_mode with Camera V2

Fri Jun 23, 2017 8:55 am

RemyC wrote:Ok, I will try this if I can figure out how to :D
Look at Raspistill and how it is using MMAL_PARAMETER_CHANGE_EVENT_REQUEST to request changes on MMAL_PARAMETER_CAMERA_SETTINGS, and then handling them in the control port callback (camera_control_callback)
RemyC wrote:I dont get why you say there is no sense in doing a flash with exposure mode off.
Mode off just disable the automatic gain control, fixing the values of digital gain et analog gain right ?
I mean, isnt it like when you use a camera with no automatic control and just a flash ? To have your own settings, and then the brightness you wish.
I should have said it makes no sense to be telling the tuner about flash with exposure mode off, and that is the only option there is in the camera stack at the moment.

It's locked auto gain and auto exposure, so normally the tuner will be running a preflash to calibrate the settings for the main flash. If the flash had controllable intensity then that could be varied, but otherwise you are adjusting exposure time and gain so that the flash doesn't over expose the image. With no control on flash intensity and everything locked you're really just looking for a trigger - that's not what the flash driver is there to do.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

RemyC
Posts: 11
Joined: Thu Nov 17, 2016 10:05 am

Re: Using Flash_mode with Camera V2

Fri Jun 23, 2017 3:15 pm

Look at Raspistill and how it is using MMAL_PARAMETER_CHANGE_EVENT_REQUEST to request changes on MMAL_PARAMETER_CAMERA_SETTINGS, and then handling them in the control port callback (camera_control_callback)
Well, I m using python, so that might be complicated. And I am not much of a developper :(
But for now, I just set a GPIO High before the acquisition. I just dont know the delay between my command and the actual capture. If it works with a duration max of 500ms for the flash, it is fine by me.
With no control on flash intensity and everything locked you're really just looking for a trigger - that's not what the flash driver is there to do.
I am indeed just looking for a trigger, but with the duration of the exposure time. I ve seen it called "flash trigger" in others cameras, that is why I didn't understand what you were saying about it.

Thank you for your precision.

Return to “Camera board”

Who is online

Users browsing this forum: No registered users and 10 guests