[HOW-TO] Set exposure measurement area with Raspberry Pi Camera
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- python, raspberry-pi
- Domain
- computer-vision, embedded-iot
Research direction
Start by reproducing the posted Picamera2 script with imx477.json and the custom AeMeteringMode setup, then inspect the rpi.agc metering_modes configuration and the approach from issue #967. Compare the captured exposure when each side of the image is covered; done means confirming whether the custom weights are applied and documenting the required configuration or code change.
Written by the indexing model from the issue text.
Description
Hi there :)
I am trying to take images with a raspberry pi 2018 HQ Camera V1.0 / raspberry Pi 5 combination and I want to manually set the auto exposure metering so that it only meters the right hand side of the camera. As far as I know the tuning file for this camera is the imx477.json.
My question is how can I ensure that my custom metering array is used?
So far I have tried two approaches:
Approach 1:
I did try to directly edit the tuning file like this
"rpi.agc":
{
"channels": [
{
"comment": "Channel 0 is normal AGC",
"metering_modes":
{
"centre-weighted":
{
"weights":
[
*Array*
]
},
"spot":
{
"weights":
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 2, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 2, 3, 2, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 2, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]
},
"matrix":
{
"weights":
[
*Array*
]
}
"custom":
{
"weights":
[
0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 4, 3, 2,
0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 5, 6, 5, 4, 3,
0, 0, 0, 0, 0, 0, 0, 3, 4, 5, 6, 7, 6, 5, 4,
0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 8, 7, 6, 5,
0, 0, 0, 0, 0, 0, 0, 5, 6, 7, 8, 9, 8, 7, 6,
0, 0, 0, 0, 0, 0, 0, 6, 7, 8, 9, 9, 9, 8, 7,
0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 9, 9, 9, 9, 8,
0, 0, 0, 0, 0, 0, 0, 8, 9, 9, 9, 9, 9, 9, 8,
0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 9, 9, 9, 9, 8,
0, 0, 0, 0, 0, 0, 0, 6, 7, 8, 9, 9, 9, 8, 7,
0, 0, 0, 0, 0, 0, 0, 5, 6, 7, 8, 9, 8, 7, 6,
0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 8, 7, 6, 5,
0, 0, 0, 0, 0, 0, 0, 3, 4, 5, 6, 7, 6, 5, 4,
0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 5, 6, 5, 4, 3,
0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 4, 3, 2
]
}
},
And then take an image like this, where I select the AeMeteringMode to Custom
from picamera2 import Picamera2
from libcamera import controls
from PIL import Image
from datetime import datetime
tuning = Picamera2.load_tuning_file("imx477_edited.json")
picam2 = Picamera2(tuning=tuning)
picam2.configure(picam2.create_still_configuration())
picam2.start()
picam2.set_controls({"AeMeteringMode": controls.AeMeteringModeEnum.Custom})
img = picam2.capture_array()
Image.fromarray(img).save(f"capture_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg")
picam2.stop()
and while this resulted in images being taken, the images did not suggest, that it was only metering the right hand side of the image.
Approach 2:
I then tried to set the array in code similar to the solution that I saw in issue https://github.com/raspberrypi/picamera2/issues/967?new_signup=true
[...]
tuning = Picamera2.load_tuning_file("imx477.json")
algo = Picamera2.find_tuning_algo(tuning, "rpi.agc")
algo["channels"][0]["metering_modes"]["custom"] = {
"weights": [0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 4, 3, 2, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 5, 6, 5, 4, 3, 0, 0, 0, 0, 0, 0, 0, 3, 4, 5, 6, 7, 6, 5, 4, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 8, 7, 6, 5, 0, 0, 0, 0, 0, 0, 0, 5, 6, 7, 8, 9, 8, 7, 6, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8, 9, 9, 9, 8, 7, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 9, 9, 9, 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 9, 9, 9, 9, 9, 8, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 9, 9, 9, 9, 8, 0, 0, 0, 0, 0, 0, 0, 6, 7, 8, 9, 9, 9, 8, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 7, 8, 9, 8, 7, 6, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 8, 7, 6, 5, 0, 0, 0, 0, 0, 0, 0, 3, 4, 5, 6, 7, 6, 5, 4, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 5, 6, 5, 4, 3, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 4, 3, 2]
}
picam2 = Picamera2(tuning=tuning)
[...
While here I again got no errors and images where taken these are not what I expect given my custom metering array.
Images
These are examples of the images that I took with these approaches.
For this one the left side was covered and here I expect a relatively normal exposure since the right hand side should anyway only be metered.
For this image, however, where the right hand side is covered I would expect a lot of overexposure on the left side, since the metering should only be done for the right hand side.
To me it seems like it then just defaults to a centre-weighted metering mode. How can I ensure that my custom metering array is used?
Any help is greatly appreciated!
- Dominant language
- Python
- Stars
- 1.2k
- Forks
- 258
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from raspberrypi/picamera2
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
raspberrypi/picamera2#1405 · 3 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
raspberrypi/picamera2#1404 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 57/100
raspberrypi/picamera2#1403 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
raspberrypi/picamera2#1392 · 13 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
raspberrypi/picamera2#1389 · 4 comments ·
All issues in raspberrypi/picamera2
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100