question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[OTHER] Exposure Bracket Function

See original GitHub issue

hey guys. thank you for your dedication towards developing picamera2 further

SKYCAM stx0 stx2 stx4

[Exposure Bracketing]

from picamera2 import *
from time import sleep
from fractions import Fraction

# This script captures exposures with varying shutter time. 
# The frame rate needs to be longer than the exposure or it won't work. 
# The capture takes as long as the frame rate, so reducing the frame rate saves time for quick exposures.

with picamera2.Picamera2() as camera:
   
        camera.resolution = (4056,3040)
        #camera.framerate = Fraction(1, 2)
        camera.iso = 100
        camera.exposure_mode = 'off'
        camera.awb_mode = 'off'
        camera.awb_gains = (1.8,1.8)
        
        config = camera.create_still_configuration()
        camera.configure(config)
		
        camera.set_controls({"ExposureTime": 114, "AnalogueGain": 1})
        camera.start()
        camera.capture_file('0.jpg')
        print(camera.capture_metadata())
		
        camera.stop()
        
		
        camera.set_controls({"ExposureTime": 300, "AnalogueGain": 0.5})
        camera.start()
        camera.capture_file('1.jpg')
        print(camera.capture_metadata())
		
        camera.stop()
        
        camera.set_controls({"ExposureTime": 500, "AnalogueGain": 0.5})
        camera.start()
        camera.capture_file('2.jpg')
        print(camera.capture_metadata())
		
        camera.stop()
        
        camera.close()

Any suggestions for improving my python code in terms of smartness. All setting should remain constant expect for exposure time/shutter speed. For example FocusFoM, ColourGains, Colourcorrectionsmatrix, Lux seems to change in my series.

The idea is to generate a HDR Image via multi exposure fusion algorthmn. Use case for solar power prediction.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:16

github_iconTop GitHub Comments

1reaction
davidplowmancommented, Aug 30, 2022

Hi, just a few things to comment on:

  1. Setting properties with camera.iso = 100 is an idiom from PiCamera, not Picamera2. You need to set these values using (for example) camera.set_controls(...). In fact there is no ISO control in libcamera, you just set the (analogue) gain directly.
  2. Same goes for those awb_gains, that’s a PiCamera thing, in Picamera2 it’s camera.set_controls({"ColourGains": (1.8, 1.8)}).
  3. In a couple of places you set the analogue gain to 0.5. Actually values under 1.0 aren’t valid, I expect it reports "AnalogueGain": 1.0 instead?
  4. The ColourGains and ColourCorrectionMatrix should stop changing, I’m guessing that you’re not setting the colour gains correctly (point 2 above.)
  5. The FocusFoM and Lux values are merely outputs of the system measured from the image (the former is a local contrast measure but it depends on the pixel levels, the latter is an estimate of how bright a scene is). They shouldn’t affect processing if you’ve fixed the AEC/AGC and AWB.
0reactions
davidplowmancommented, Sep 26, 2022

I’m not quite sure what’s going wrong for you. I took your script, deleted all the stuff after the captures (which I can’t run anyway), and rolled them up into a loop, just so that I was editing less code. Here’s what I ended up with:

import time
from picamera2 import *

tuning = Picamera2.load_tuning_file("imx477.json")

t1 = time.perf_counter()

exposures = [50, 100, 150, 250, 400, 650, 1050, 1700, 2750]

def exposure_bracket():
    with Picamera2(tuning=tuning) as camera: 
        config = camera.create_still_configuration(main={"size": (1014, 760),"format": "RGB888"}, raw={"format": "SRGGB12", "size" : (2032, 1520)})
        camera.configure(config)

        for exp in exposures:
            camera.set_controls({"ExposureTime": exp, "AnalogueGain": 1, "ColourGains": (1.0,1.0)})
            camera.start()
            metadata = camera.capture_file(f"{exp}.tga")
            lux = metadata["Lux"]
            sens_temp = metadata["SensorTemperature"]
            camera.stop()
            print("Exposure:", exp, "lux:", lux, " sensor temp:", sens_temp)

exposure_bracket()

t2 = time.perf_counter()
print(f"Finished in {t2-t1} seconds")

For me this code works perfectly. It completes in just over 7s with no errors. I also tried running the exposure_bracket function using the multiprocessing module, and that too seems to work fine.

Are you able to try this?

I’ll also lock this thread so that the discussion can continue on the issue that’s still open, if that’s OK. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exposure Bracketing Photography [COMPLETE GUIDE]
HDR stands for high dynamic range. The goal of an HDR photography is to increase the normal dynamic range of your camera, giving...
Read more >
What Is Bracketing? Definition, Examples & How To Use ...
Photographers bracket their shots by taking a series of photographs at different exposures. This is done to capture more detail in the shadows...
Read more >
How to Use Bracketing to Create Perfect Photos - MasterClass
5. Exposure bracketing: Bracket exposures offer variation in either aperture, shutter speed, or ISO, thus granting a photographer more post- ...
Read more >
Bracketing - Wikipedia
For other uses, see Bracketing (disambiguation). ... In photography, bracketing is the general technique of taking several shots of the same subject using ......
Read more >
Bracketing in Photography: The Ultimate Guide
The great thing about bracketing is it allows you to experiment with different exposure settings the the press of one button instead of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found