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 #973

Merged
merged 1 commit into from
Mar 6, 2024
Merged
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: 12 additions & 10 deletions apps/app_full.py
Original file line number Diff line number Diff line change
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"]
_, full_img, _ = picam2.camera_controls['ScalerCrop']
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,8 @@ class panZoomDisplay(QWidget):
def __init__(self):
super().__init__()
self.setMinimumSize(201, 151)
self.scale = 200 / picam2.camera_properties["ScalerCropMaximum"][2]
_, full_img, _ = picam2.camera_controls['ScalerCrop']
self.scale = 200 / full_img[2]
self.zoom_level_ = 1.0
self.max_zoom = 7.0
self.zoom_step = 0.1
Expand All @@ -537,7 +538,7 @@ def setZoomLevel(self, val):
def paintEvent(self, event):
painter = QPainter()
painter.begin(self)
full_img = picam2.camera_properties["ScalerCropMaximum"]
_, full_img, _ = picam2.camera_controls['ScalerCrop']
self.scale = 200 / full_img[2]
# Whole frame
scaled_full_img = [int(i * self.scale) for i in full_img]
Expand All @@ -555,11 +556,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, _ = picam2.camera_controls['ScalerCrop']
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 +584,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, _ = picam2.camera_controls['ScalerCrop']
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 +1129,10 @@ 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, _ = picam2.camera_controls['ScalerCrop']
switch_config("preview")
if current_crop != picam2.camera_properties["ScalerCropMaximum"]:
_, preview_crop, _ = picam2.camera_controls['ScalerCrop']
if current_crop != preview_crop:
print("Preview and Still configs have different aspect ratios")
self.preview_warning.show()
else:
Expand Down Expand Up @@ -1208,7 +1210,7 @@ def toggle_hidden_controls():
# Final setup
window.setWindowTitle("Qt Picamera2 App")
recording = False
scaler_crop = picam2.camera_properties["ScalerCropMaximum"]
_, scaler_crop, _ = picam2.camera_controls['ScalerCrop']
hdr_imgs = {"exposures": None}
pic_tab.apply_settings()

Expand Down
3 changes: 2 additions & 1 deletion picamera2/picamera2.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ 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"]
_, scaler_crop_max, _ = self.camera_controls['ScalerCrop']
cam_mode["crop_limits"] = scaler_crop_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
2 changes: 1 addition & 1 deletion tests/autofocus_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@
time.sleep(0.1)

print("Test AfWindows")
max_window = picam2.camera_properties['ScalerCropMaximum']
_, max_window, _ = picam2.camera_controls['ScalerCrop']
picam2.set_controls({'AfWindows': [max_window]})
time.sleep(0.1)
Loading