hey again em i want focus in a whole area in the middle (rather than a spot ) .
1question how big is the area than normal focus used.
do i use this part properly
picam2.set_controls({"AfMode": controls.AfModeEnum.Manual,
"LensPosition": lens_position_spinbox.value(),
"AfMetering" : controls.AfMeteringEnum.Windows,
"AfWindows" : [ (0, 0, 400, 500) ]}) #2 question is that in the middle????
here is what i used
```
1question how big is the area than normal focus used.
do i use this part properly
picam2.set_controls({"AfMode": controls.AfModeEnum.Manual,
"LensPosition": lens_position_spinbox.value(),
"AfMetering" : controls.AfMeteringEnum.Windows,
"AfWindows" : [ (0, 0, 400, 500) ]}) #2 question is that in the middle????
here is what i used
Code:
#!/usr/bin/python3from libcamera import controlsfrom PyQt5 import QtCorefrom PyQt5.QtGui import QPalettefrom PyQt5.QtWidgets import (QApplication, QCheckBox, QHBoxLayout, QLabel, QPushButton, QVBoxLayout, QWidget, QDoubleSpinBox)from picamera2 import Picamera2from picamera2.previews.qt import QGlPicamera2import numpy as npimport timeSTATE_AF = 0STATE_CAPTURE = 1def request_callback(request): lens_position = request.get_metadata().get('LensPosition', 'N/A') # Format the lens position to display up to 3 decimal places lens_position_str = f"{float(lens_position):.3f}" if lens_position != 'N/A' else 'N/A' label.setText(f"Lens Position: {lens_position_str}") picam2 = Picamera2(1)picam2.post_callback = request_callbackpreview_width = 800preview_height = picam2.sensor_resolution[1] * 800 // picam2.sensor_resolution[0]preview_height -= preview_height % 2preview_size = (preview_width, preview_height)raw_size = tuple([v // 2 for v in picam2.camera_properties['PixelArraySize']])preview_config = picam2.create_preview_configuration({"size": preview_size}, raw={"size": raw_size})picam2.configure(preview_config)if 'AfMode' not in picam2.camera_controls: print("Attached camera does not support autofocus") quit()picam2.set_controls({"AfMode": controls.AfModeEnum.Auto,"AfSpeed": controls.AfSpeedEnum.Fast})app = QApplication([])def on_button_clicked(): global state button.setEnabled(False) manual_focus.setEnabled(False) af_checkbox.setEnabled(False) state = STATE_AF if af_checkbox.isChecked() else STATE_CAPTURE if state == STATE_AF: picam2.autofocus_cycle(signal_function=qpicamera2.signal_done) else: do_capture() # Remove focus from QDoubleSpinBox lens_position_spinbox.clearFocus()def on_continuous_af_toggled(checked): if checked: picam2.set_controls({"AfMode": controls.AfModeEnum.Continuous, "AfSpeed": controls.AfSpeedEnum.Fast, "AfMetering" : controls.AfMeteringEnum.Windows, "AfWindows" : [ (0, 0, 400, 500) ]}) else: picam2.set_controls({"AfMode": controls.AfModeEnum.Auto, "AfSpeed": controls.AfSpeedEnum.Fast, "AfMetering" : controls.AfMeteringEnum.Windows, "AfWindows" : [ (0, 0, 400, 500) ]})SAVE_DIRECTORY = "/home/konos93/Desktop/camera/cam1"def do_capture(): timestamp = time.strftime("%Y%m%d%H%M%S") filename = f"{SAVE_DIRECTORY}/bbb{timestamp}.jpg" cfg = picam2.create_still_configuration(buffer_count=3) picam2.switch_mode_and_capture_file(cfg, filename, signal_function=qpicamera2.signal_done) print(f"Image saved: {filename}")def callback(job): global state if state == STATE_AF: state = STATE_CAPTURE success = "succeeded" if picam2.wait(job) else "failed" print(f"AF cycle {success} in {job.calls} frames") do_capture() else: picam2.wait(job) picam2.set_controls({"AfMode": controls.AfModeEnum.Auto, "AfSpeed": controls.AfSpeedEnum.Fast, "AfMetering" : controls.AfMeteringEnum.Windows, "AfWindows" : [ (0, 0, 400, 500) ]}) button.setEnabled(True) manual_focus.setEnabled(True) af_checkbox.setEnabled(True)def on_manual_toggled(checked): mode = controls.AfModeEnum.Continuous if checked else controls.AfModeEnum.Auto picam2.set_controls({"AfMode": controls.AfModeEnum.Manual, "LensPosition": lens_position_spinbox.value(), "AfMetering" : controls.AfMeteringEnum.Windows, "AfWindows" : [ (0, 0, 400, 500) ]}) def on_lens_position_changed(value): picam2.set_controls({"AfMode": controls.AfModeEnum.Manual, "LensPosition": value})# Add an overlay to the camera preview when the checkbox is clickeddef on_overlay_checkbox_toggled(checked): global overlay if checked: qpicamera2.set_overlay(overlay) else: qpicamera2.set_overlay(None)overlay_checkbox = QCheckBox("Show Overlay")overlay_checkbox.setChecked(False)overlay_checkbox.toggled.connect(on_overlay_checkbox_toggled)# Define the overlayoverlay = np.zeros((300, 400, 4), dtype=np.uint8)overlay[:150, 200:] = (255, 0, 0, 64)overlay[150:, :200] = (0, 255, 0, 64)overlay[150:, 200:] = (0, 0, 255, 64) window = QWidget()bg_colour = window.palette().color(QPalette.Background).getRgb()[:3]qpicamera2 = QGlPicamera2(picam2, width=preview_width, height=preview_height, bg_colour=bg_colour, keep_ar=True)qpicamera2.done_signal.connect(callback, type=QtCore.Qt.QueuedConnection)button = QPushButton("Click to capture JPEG")button.clicked.connect(on_button_clicked)continuous_af_checkbox = QCheckBox("Continuous AF")continuous_af_checkbox.setChecked(False)continuous_af_checkbox.toggled.connect(on_continuous_af_toggled)label = QLabel()af_checkbox = QCheckBox("AF before capture", checked=True)manual_focus = QCheckBox("Manual Focus", checked=False)manual_focus.toggled.connect(on_manual_toggled)# Add a QDoubleSpinBox for adjusting lens positionlens_position_spinbox = QDoubleSpinBox()lens_position_spinbox.setSingleStep(0.02) # Adjust step size to 0.05lens_position_spinbox.setMinimum(0) # Set minimum valuelens_position_spinbox.setMaximum(10) # Set maximum valuelens_position_spinbox.setFixedWidth(100) # Set fixed width for smaller sizelens_position_spinbox.setValue(5) # Set initial value to 5lens_position_spinbox.valueChanged.connect(on_lens_position_changed)window.setWindowTitle("cam1 App")label.setFixedWidth(200)label.setFixedHeight(50)label.setAlignment(QtCore.Qt.AlignTop)layout_h = QHBoxLayout()layout_v = QVBoxLayout()layout_v.addWidget(label)layout_v.addWidget(manual_focus)layout_v.addWidget(lens_position_spinbox) # Add the lens position QDoubleSpinBoxlayout_v.addWidget(af_checkbox)layout_v.addWidget(continuous_af_checkbox) # Add the continuous autofocus checkboxlayout_v.addWidget(overlay_checkbox)layout_v.addWidget(button)layout_h.addWidget(qpicamera2, 1)layout_h.addLayout(layout_v, 2)window.resize(1500, 460)button.setFixedHeight(200)button.setFixedWidth(200)window.setLayout(layout_h)picam2.start()window.move(500, 560)window.show()app.exec()picam2.stop()
Code:
[4:15:51.741548826] [7091] INFO Camera camera_manager.cpp:284 libcamera v0.1.0+118-563cd78e[4:15:51.764258589] [7100] INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a258644a 22-11-2023 (21:59:22)[4:15:51.860457356] [7100] INFO RPI pisp.cpp:1112 Registered camera /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a to CFE device /dev/media1 and ISP device /dev/media0 using PiSP variant BCM2712_C0[4:15:51.860527041] [7100] INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a258644a 22-11-2023 (21:59:22)[4:15:51.963835964] [7100] INFO RPI pisp.cpp:1112 Registered camera /base/axi/pcie@120000/rp1/i2c@80000/imx708@1a to CFE device /dev/media3 and ISP device /dev/media2 using PiSP variant BCM2712_C0[4:15:51.966117331] [7091] INFO Camera camera_manager.cpp:284 libcamera v0.1.0+118-563cd78e[4:15:51.988719169] [7105] INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a258644a 22-11-2023 (21:59:22)[4:15:52.092915461] [7105] INFO RPI pisp.cpp:1112 Registered camera /base/axi/pcie@120000/rp1/i2c@88000/imx708@1a to CFE device /dev/media1 and ISP device /dev/media0 using PiSP variant BCM2712_C0[4:15:52.093009702] [7105] INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a258644a 22-11-2023 (21:59:22)[4:15:52.194916979] [7105] INFO RPI pisp.cpp:1112 Registered camera /base/axi/pcie@120000/rp1/i2c@80000/imx708@1a to CFE device /dev/media3 and ISP device /dev/media2 using PiSP variant BCM2712_C0[4:15:52.197631567] [7091] WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format Y16 [4:15:52.197673660] [7091] WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format RGB6[4:15:52.197679178] [7091] WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format BGR6[4:15:52.197685382] [7091] WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format PC1M[4:15:52.198412214] [7091] INFO Camera camera.cpp:1183 configuring streams: (0) 800x450-XBGR8888 (1) 2304x1296-BGGR16_PISP_COMP1[4:15:52.198543807] [7105] INFO RPI pisp.cpp:1396 Sensor: /base/axi/pcie@120000/rp1/i2c@80000/imx708@1a - Selected sensor format: 2304x1296-SBGGR10_1X10 - Selected CFE format: 2304x1296-PC1BQStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'error: XDG_RUNTIME_DIR is invalid or not set in the environment.error: XDG_RUNTIME_DIR is invalid or not set in the environment.AF cycle succeeded in 21 framesImage saved: /home/konos93/Desktop/camera/cam1/bbb20240208165852.jpg[4:16:06.213042902] [7091] WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format Y16 [4:16:06.213084790] [7091] WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format RGB6[4:16:06.213092402] [7091] WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format BGR6[4:16:06.213101568] [7091] WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format PC1M[4:16:06.213780715] [7091] INFO Camera camera.cpp:1183 configuring streams: (0) 4608x2592-BGR888 (1) 4608x2592-BGGR16_PISP_COMP1[4:16:06.220726390] [7105] INFO RPI pisp.cpp:1396 Sensor: /base/axi/pcie@120000/rp1/i2c@80000/imx708@1a - Selected sensor format: 4608x2592-SBGGR10_1X10 - Selected CFE format: 4608x2592-PC1B[4:16:06.749302211] [7091] WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format Y16 [4:16:06.749343803] [7091] WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format RGB6[4:16:06.749349562] [7091] WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format BGR6[4:16:06.749356896] [7091] WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format PC1M[4:16:06.749907765] [7091] INFO Camera camera.cpp:1183 configuring streams: (0) 800x450-XBGR8888 (1) 2304x1296-BGGR16_PISP_COMP1[4:16:06.757067051] [7105] INFO RPI pisp.cpp:1396 Sensor: /base/axi/pcie@120000/rp1/i2c@80000/imx708@1a - Selected sensor format: 2304x1296-SBGGR10_1X10 - Selected CFE format: 2304x1296-PC1B
Statistics: Posted by Konos93a — Thu Feb 08, 2024 3:18 pm