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

ScalerCrops handling #1087

Closed
wants to merge 3 commits into from
Closed

ScalerCrops handling #1087

wants to merge 3 commits into from

Conversation

naushir
Copy link
Collaborator

@naushir naushir commented Aug 8, 2024

No description provided.

Note that this change and new functionality is only applicable on Pi 5.

The stream configuration dictionary now has a "preserve_ar" key that
when set to True, will preserve the aspect ratio of the output by
cropping the sensor image appropriately. If set to False, the full
field of view of the sensor image is used to scale to the output
resolution. This happens separately for the main and lores streams.

The default behaviour of this flag is as follows:

- For the main stream, it is set to True. This preserves existing
  behaviour.

- For the lowres stream, it is set to False, which then makes the lowres
  stream crop follows the crop of the main stream. Again, this
  preservies existing behaviour, also matching VC4.

Signed-off-by: Naushir Patuck <[email protected]>
Add this control to the ignore list.

Signed-off-by: Naushir Patuck <[email protected]>
@@ -1116,6 +1116,15 @@ def configure_(self, camera_config="preview") -> None:
self.controls = Controls(self, controls=self.camera_config['controls'])
self.configure_count += 1

if "ScalerCrops" in self.camera_controls:
par_crop = self.camera_controls["ScalerCrops"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I'm guessing par_crop means preserve_ar_crop? Actually, for my curiosity, how does this work? Presumably libcamera is calculating the AR-preserving crop for each of the cameras - except I thought asking for camera controls was supposed to give us min/max/default triple. So I think I'm a bit confused!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably libcamera is calculating the AR-preserving crop for each of the cameras - except I thought asking for camera controls was supposed to give us min/max/default triple. So I think I'm a bit confused!

This is a bit of a hack where the controlinfo for rpi::ScalerCrops actually gives us the default (i.e. preserved ar) crop for output 0 and output 1 in the min/max fields. Unfortunately there is no other mechanism that can be used to get this out for span controls.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, yes, that's a bit sneaky! Maybe worth a comment as it was a bit head-scratchy?


for m, l in [(False, False), (False, True), (True, False), (True, True)]:
cfg = picam2.create_video_configuration(main={"size": (1920, 1080), "format": 'XRGB8888', "preserve_ar": m},
lores={"size": (640, 640), "format": 'XRGB8888', "preserve_ar": l},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering what this does on a Pi 4 where you can't have RGB on the lores?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question - I assumed the validate() would change this to YUV and everything would be good. But I've not explicitly tried it...

Actually, there's no reason lores needs to be RGB, perhaps I should just change it to YUV.

@davidplowman davidplowman reopened this Oct 17, 2024
@davidplowman davidplowman mentioned this pull request Oct 17, 2024
@davidplowman
Copy link
Collaborator

Not to worry about this one, I'll deal with the conflict and push a new version!

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