Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the initial camera controls not used when starting camera #39

Merged

Conversation

christian-nils
Copy link
Contributor

@christian-nils christian-nils commented Apr 25, 2024

Fixes issues including the one described in #37 where the sink camera is not aware of the targeted framerate causing problems with the autoexposure algorithm.

fixes issues such as christianrauch#37 where the sink camera does is not aware of the targeted framerate causing problems with the autoexposure algorithm.
@christianrauch
Copy link
Owner

Thanks a lot for this PR. Is the issue related to #30?

Can you give an example of what did not work for you before this PR and how that changed with this PR?

@christian-nils
Copy link
Contributor Author

christian-nils commented Apr 26, 2024

I don't think this will solve #30 (the bug report is also a bit confusing). I guess some of the listed stream formats are just not supported by the camera causing the issue reported.

For this PR, I can explain a bit more why it is relevant. In my case, I have two IMX477 sensors, one configured as a source and the other one as a sink using the following dtoverlay configuration:

dtoverlay=imx477,cam0,rotation=0,always-on,sync-sink
dtoverlay=imx477,rotation=0,always-on,sync-source

This means that the sink sensor will only capture frames when it receives a trigger on its XVS line.

If you don't add the expected framerate for the sink before starting the camera, you'll have issue with the AEC/AGC algorithm. After the 3rd frame of the startup phase (to initialize the algorithms I guess? those frames are dropped after https://github.com/raspberrypi/libcamera/blob/eb00c13d7c9f937732305d47af5b8ccf895e700f/src/libcamera/pipeline/rpi/pisp/data/example.yaml#L22), you will get an updated metadata with Exposure=0.

From the report:

[2:08:07.563255269] [673] DEBUG IPARPI ipa_base.cpp:1274 Metadata - Exposure: 985.83us Frame length: 2197 Line length: 15.17us Gain: 1
[2:08:07.563389046] [673] DEBUG IPARPI cam_helper.cpp:251 Metadata updated - Exposure: 0.00us Frame length: 0 Line length: 0.00us Gain: 1 Temperature: 0

This will happen for every following frames.

When using the fix, you set the controls before the camera as explained here (https://libcamera.org/api-html/classlibcamera_1_1Camera.html#a5c033a72ac66fbdd2c2bb9f934389dcf). Which leads to fixing the error reported above:

[2:19:04.777075042] [862] DEBUG IPARPI ipa_base.cpp:1274 Metadata - Exposure: 985.83us Frame length: 2175 Line length: 15.17us Gain: 1
[2:19:04.777131041] [862] DEBUG IPARPI cam_helper.cpp:251 Metadata updated - Exposure: 985.83us Frame length: 2175 Line length: 15.17us Gain: 1 Temperature: 27

So, in short, we get the following before the fix (obstructing the first frames to get a high exposure which bugs the successive capture):
bad.webm

we get the following after applying the patch
good.webm

Please let me know if that addresses your questions.

@christianrauch christianrauch merged commit 0b5cfe9 into christianrauch:main Apr 27, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants