Hello,
I'd like to ask a new question, without opening a new topic, as it's somewhat related to the previous one.
My project is to create an opensource camera, and for the moment I've incorporated quite a few settings that work rather well.
Two of them are :
-a zoom that zooms into the image to facilitate manual focusing at wide apertures.
- A combox that lets you select different aspect ratios (Panavision, cinemascope etc.).
Works pretty well.
My only problem is that when I select an aspect ratio, zoom in and then zoom out, I don't get the same aspect ratio.
When calling the zoom_out function, I'd like to retrieve the variable (role) returned by the format_cine_changed function in order to know the ratio selected by the user, so that when I zoom out I get the corresponding image ratio.
I'm feeling a bit silly because it seems pretty straightforward, but I'm getting a bit stuck on it.
Could you help me?
Here's my code, which I've simplified as much as possible (I've removed all the other settings and functions)
I'd like to ask a new question, without opening a new topic, as it's somewhat related to the previous one.
My project is to create an opensource camera, and for the moment I've incorporated quite a few settings that work rather well.
Two of them are :
-a zoom that zooms into the image to facilitate manual focusing at wide apertures.
- A combox that lets you select different aspect ratios (Panavision, cinemascope etc.).
Works pretty well.
My only problem is that when I select an aspect ratio, zoom in and then zoom out, I don't get the same aspect ratio.
When calling the zoom_out function, I'd like to retrieve the variable (role) returned by the format_cine_changed function in order to know the ratio selected by the user, so that when I zoom out I get the corresponding image ratio.
I'm feeling a bit silly because it seems pretty straightforward, but I'm getting a bit stuck on it.
Could you help me?
Here's my code, which I've simplified as much as possible (I've removed all the other settings and functions)
Code:
import sysimport timeimport libcamerafrom timeit import default_timer as timerimport cv2from PyQt5.QtCore import *from PyQt5.QtGui import *from PyQt5.QtWidgets import *from PyQt5 import QtCorefrom PyQt5 import QtWidgetsfrom PyQt5.QtWidgets import QPushButton, QVBoxLayout, QApplication, QWidgetfrom PyQt5.QtGui import QPalette, QColorfrom picamera2.previews.qt import QGlPicamera2from picamera2.previews.qt import QGlPicamera2from picamera2.encoders import H264Encoderfrom picamera2.outputs import FfmpegOutput from picamera2 import Picamera2, Preview, MappedArrayfrom libcamera import Transform, controlsimport boardimport datetimeimport os, smbusfrom datetime import dateapp= QApplication(sys.argv)picam2 = Picamera2()def zoom_in(request): size = request.get_metadata()['ScalerCrop'][2:] full_res = picam2.camera_properties['PixelArraySize'] factor_zoom=1000 size = [factor_zoom for s in size] offset = [(r - s) // 2 for r, s in zip(full_res, size)] picam2.set_controls({"ScalerCrop": offset + size }) def zoom_out(request): size = request.get_metadata()['ScalerCrop'][2:] size_scaler = request.get_metadata()['ScalerCrop'] if size_scaler[0]>10: full_res = picam2.camera_properties['PixelArraySize'] factor_zoom=20000 size = [factor_zoom for s in size] offset = [(r - s) // 2 for r, s in zip(full_res, size)] picam2.set_controls({"ScalerCrop": offset + size }) class Camerapreview(QMainWindow): def __init__(self, parent=None): super(Camerapreview, self).__init__(parent) raw = {'size': (2028, 1524), 'format': 'SBGGR12'} config = picam2.create_video_configuration({'size': (2028, 1524)}, transform=Transform(hflip=1, vflip=1), raw=raw) self.qpicamera2 = QGlPicamera2(picam2) picam2.configure(config) self.preview = QWidget() self.setCentralWidget(self.preview) self.vLayout = QVBoxLayout(self.centralWidget()) self.sliders4Widget = QWidget() self.sliders4Widget.setFixedHeight(40) self.sliders4WidgetLayout = QHBoxLayout(self.sliders4Widget) self.sliders4Widget.setStyleSheet('* {background: white;}') self.format_cine = QComboBox(self) self.format_cine.setGeometry(200, 150, 120, 40) self.format_cine.setStyleSheet('* {background: white;}') format_list = ["Format 4/3","format_académique 1.37:1", "CinemaScope 2.55:1","standard européen 1.66:1", "standard américain 1.85:1 ","Panavision/Scope standard 2.35:1","Cinérama 2.65:1,"] """self.format_cine.addItem("1.33:1") self.format_cine.addItem("1.37:1") self.format_cine.addItem("CinemaScope 2.39:1")""" self.format_cine.addItems(format_list) format_4T3=0 format_académique=1 format_cinemascope=2 format_standard_europeen=3 format_standard_americain=4 format_panavision=5 format_cinerama=6 self.format_cine.setItemData(0, format_4T3) self.format_cine.setItemData(1, format_académique) self.format_cine.setItemData(2, format_cinemascope) self.format_cine.setItemData(3, format_standard_europeen) self.format_cine.setItemData(4, format_standard_americain) self.format_cine.setItemData(5, format_panavision) self.format_cine.setItemData(6, format_cinerama) self.format_cine.activated[str].connect(self.format_cine_changed) self.button_zoom = QPushButton('ZOOM_IN', self) self.button_zoom.move(100,70) self.button_zoom.clicked.connect(self.on_click) self.sliders4WidgetLayout.addWidget(self.format_cine) self.sliders4WidgetLayout.addWidget(self.button_zoom) self.vLayout.addWidget(self.qpicamera2) self.vLayout.addWidget(self.sliders4Widget) self.sliders4Widget.show() def format_cine_changed(self, text): role = self.format_cine.itemData(self.format_cine.currentIndex()) if role==0:#format 4/3 1.33 picam2.stop() config = picam2.create_video_configuration({'size': (2028, 1524)}, transform=Transform(hflip=1, vflip=1)) picam2.configure(config) picam2.start() if role==1:#format academique 1.37 picam2.stop() config = picam2.create_video_configuration({'size': (2028, 1480)}, transform=Transform(hflip=1, vflip=1)) picam2.configure(config) picam2.start() if role==2:#format cinemscope 2.55 picam2.stop() config = picam2.create_video_configuration({'size': (2028, 795)}, transform=Transform(hflip=1, vflip=1)) picam2.configure(config) picam2.start() if role==3:#format standard européen 1.66 picam2.stop() config = picam2.create_video_configuration({'size': (2028, 1221)}, transform=Transform(hflip=1, vflip=1)) picam2.configure(config) picam2.set_controls({"ScalerCrop":(0,440,4056,2444)}) picam2.start() if role==4:#format standard americain 1.85 picam2.stop() config = picam2.create_video_configuration({'size': (2028, 1096)}, transform=Transform(hflip=1, vflip=1)) picam2.set_controls({"ScalerCrop":(0,440,4056,2192)}) picam2.configure(config) picam2.start() if role==5:#format panavision 2.35 picam2.stop() config = picam2.create_video_configuration({'size': (2028, 863)}, transform=Transform(hflip=1, vflip=1)) picam2.configure(config) picam2.start() if role==6:#format cinerama 2.65 picam2.stop() config = picam2.create_video_configuration({'size': (2028, 765)}, transform=Transform(hflip=1, vflip=1)) picam2.configure(config) picam2.start() return role @pyqtSlot() def on_click(self): picam2.post_callback = zoom_in def mousePressEvent(self, event): picam2.post_callback = zoom_outapp.setStyleSheet(CSS) window = Camerapreview()window.setStyleSheet("background-color: black;")window.setWindowTitle("My App")window.setWindowFlag(Qt.FramelessWindowHint) window.showFullScreen()app.exec()
Statistics: Posted by davebixby — Thu Feb 29, 2024 5:01 pm