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

Deprecate use of the ScalerCropMaximum property #968

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions apps/app_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
QLineEdit, QPushButton, QSlider, QSpinBox,
QTabWidget, QVBoxLayout, QWidget)

from picamera2 import Picamera2
from picamera2 import Picamera2, utils
from picamera2.encoders import H264Encoder, Quality
from picamera2.outputs import FfmpegOutput, FileOutput
from picamera2.previews.qt import QGlPicamera2
Expand Down Expand Up @@ -92,7 +92,7 @@ def update_controls():
global scaler_crop

# Fix aspect ratio of the pan/zoom
full_img = picam2.camera_properties["ScalerCropMaximum"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually (and sorry to be a pain...) could we do

_, full_img, _ = picam2.camera_controls['ScalerCrop']

I feel camera_ctrl_info should probably be made private at some point, and it would avoid people diving into the libcamera structures and having to do type conversions.

full_img = utils.convert_from_libcamera_type(picam2.camera_ctrl_info['ScalerCrop'][1].max)
ar = full_img[2] / full_img[3]
new_scaler_crop = list(scaler_crop)
new_scaler_crop[3] = int(new_scaler_crop[2] / ar)
Expand Down Expand Up @@ -516,7 +516,7 @@ class panZoomDisplay(QWidget):
def __init__(self):
super().__init__()
self.setMinimumSize(201, 151)
self.scale = 200 / picam2.camera_properties["ScalerCropMaximum"][2]
self.scale = 200 / utils.convert_from_libcamera_type(picam2.camera_ctrl_info['ScalerCrop'][1].max)[2]
self.zoom_level_ = 1.0
self.max_zoom = 7.0
self.zoom_step = 0.1
Expand All @@ -537,7 +537,7 @@ def setZoomLevel(self, val):
def paintEvent(self, event):
painter = QPainter()
painter.begin(self)
full_img = picam2.camera_properties["ScalerCropMaximum"]
full_img = utils.convert_from_libcamera_type(picam2.camera_ctrl_info['ScalerCrop'][1].max)
self.scale = 200 / full_img[2]
# Whole frame
scaled_full_img = [int(i * self.scale) for i in full_img]
Expand All @@ -555,11 +555,11 @@ def paintEvent(self, event):
def draw_centered(self, pos):
global scaler_crop
center = [int(i / self.scale) for i in pos]
full_img = picam2.camera_properties["ScalerCropMaximum"]
full_img = utils.convert_from_libcamera_type(picam2.camera_ctrl_info['ScalerCrop'][1].max)
w = scaler_crop[2]
h = scaler_crop[3]
x = center[0] - w // 2 + picam2.camera_properties["ScalerCropMaximum"][0]
y = center[1] - h // 2 + picam2.camera_properties["ScalerCropMaximum"][1]
x = center[0] - w // 2 + full_img[0]
y = center[1] - h // 2 + full_img[1]
new_scaler_crop = [x, y, w, h]

# Check still within bounds
Expand All @@ -583,7 +583,7 @@ def setZoom(self):
if self.zoom_level > self.max_zoom:
self.zoom_level = self.max_zoom
factor = 1.0 / self.zoom_level
full_img = picam2.camera_properties["ScalerCropMaximum"]
full_img = utils.convert_from_libcamera_type(picam2.camera_ctrl_info['ScalerCrop'][1].max)
current_center = (scaler_crop[0] + scaler_crop[2] // 2, scaler_crop[1] + scaler_crop[3] // 2)
w = int(factor * full_img[2])
h = int(factor * full_img[3])
Expand Down Expand Up @@ -1128,9 +1128,9 @@ def apply_settings(self):
# Finally set the modes and check sensor crop
if self.preview_check.isChecked():
switch_config("still")
current_crop = picam2.camera_properties["ScalerCropMaximum"]
current_crop = utils.convert_from_libcamera_type(picam2.camera_ctrl_info['ScalerCrop'][1].max)
switch_config("preview")
if current_crop != picam2.camera_properties["ScalerCropMaximum"]:
if current_crop != utils.convert_from_libcamera_type(picam2.camera_ctrl_info['ScalerCrop'][1].max):
print("Preview and Still configs have different aspect ratios")
self.preview_warning.show()
else:
Expand Down Expand Up @@ -1208,7 +1208,7 @@ def toggle_hidden_controls():
# Final setup
window.setWindowTitle("Qt Picamera2 App")
recording = False
scaler_crop = picam2.camera_properties["ScalerCropMaximum"]
scaler_crop = utils.convert_from_libcamera_type(picam2.camera_ctrl_info['ScalerCrop'][1].max)
hdr_imgs = {"exposures": None}
pic_tab.apply_settings()

Expand Down
2 changes: 1 addition & 1 deletion picamera2/picamera2.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def sensor_modes(self) -> list:
self.configure(temp_config)
frameDurationMin = self.camera_controls["FrameDurationLimits"][0]
cam_mode["fps"] = round(1e6 / frameDurationMin, 2)
cam_mode["crop_limits"] = self.camera_properties["ScalerCropMaximum"]
cam_mode["crop_limits"] = utils.convert_from_libcamera_type(self.camera_ctrl_info['ScalerCrop'][1].max)
cam_mode["exposure_limits"] = tuple([i for i in self.camera_controls["ExposureTime"] if i != 0])
self.sensor_modes_.append(cam_mode)
return self.sensor_modes_
Expand Down
4 changes: 2 additions & 2 deletions tests/autofocus_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from libcamera import controls

from picamera2 import Picamera2
from picamera2 import Picamera2, utils

picam2 = Picamera2()
if 'AfMode' not in picam2.camera_controls:
Expand Down Expand Up @@ -94,6 +94,6 @@
time.sleep(0.1)

print("Test AfWindows")
max_window = picam2.camera_properties['ScalerCropMaximum']
max_window = utils.convert_from_libcamera_type(picam2.camera_ctrl_info['ScalerCrop'][1].max)
picam2.set_controls({'AfWindows': [max_window]})
time.sleep(0.1)
Loading