Python Forum
Some help with picamera ROI setting?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Some help with picamera ROI setting?
#1
Hello,
I'm trying to take a picture and zoom it ,using camera.zoom
zoom
Retrieves or sets the zoom applied to the camera’s input.

When queried, the zoom property returns a (x, y, w, h) tuple of floating point values ranging from 0.0 to 1.0, indicating the proportion of the image to include in the output (this is also known as the “Region of Interest” or ROI). The default value is (0.0, 0.0, 1.0, 1.0) which indicates that everything should be included. The property can be set while recordings or previews are in progress.
but I can't seem to understand the values I can enter
can I only use normalize values 0-1 ?

is there any way to print the image and with the mouse see the places I want to zoom in?
then enter them to the function ?

I read here
https://docs.baslerweb.com/image-roi
but unable to make it using python

can someone help ? show example with picture and numbers?

Thanks,
Reply
#2
What have you attempted so far?
Please show code, working or not.
Reply
#3
(Feb-27-2023, 12:54 PM)korenron Wrote: Hello,
I'm trying to take a picture and zoom it ,using camera.zoom
zoom
Retrieves or sets the zoom applied to the camera’s input.

When queried, the zoom property returns a (x, y, w, h) tuple of floating point values ranging from 0.0 to 1.0, indicating the proportion of the image to include in the output (this is also known as the “Region of Interest” or ROI). The default value is (0.0, 0.0, 1.0, 1.0) which indicates that everything should be included. The property can be set while recordings or previews are in progress.
but I can't seem to understand the values I can enter
can I only use normalize values 0-1 ?

is there any way to print the image and with the mouse see the places I want to zoom in?
then enter them to the function ?

I read here
https://docs.baslerweb.com/image-roi
but unable to make it using python

can someone help ? show example with picture and numbers?

Thanks,

HI,

Yes, the values you can enter for camera.zoom are normalized values between 0 and 1. The values represent the proportion of the image that should be included in the output.

Regarding your second question, there are ways to preview an image and select the ROI using the mouse. One way to do this is to use a library like OpenCV in Python. Here's an example of how to select an ROI using the mouse and then zoom in on that region using camera.zoom:

import cv2
import numpy as np
import picamera

# Create a camera object
camera = picamera.PiCamera()

# Capture an image from the camera
camera.capture('image.jpg')

# Load the image using OpenCV
img = cv2.imread('image.jpg')

# Show the image and allow the user to select an ROI
roi = cv2.selectROI(img)

# Crop the image to the selected ROI
x, y, w, h = roi
img_roi = img[y:y+h, x:x+w]

# Calculate the normalized values for the ROI
x_norm = x / img.shape[1]
y_norm = y / img.shape[0]
w_norm = w / img.shape[1]
h_norm = h / img.shape[0]

# Set the zoom to the selected ROI
camera.zoom = (x_norm, y_norm, w_norm, h_norm)



In this example, we're first capturing an image from the camera and loading it into OpenCV. We then use the cv2.selectROI function to allow the user to select an ROI using the mouse. Once the user has made their selection, we crop the image to the selected ROI and calculate the normalized values for the ROI. Finally, we set the camera.zoom attribute to the selected ROI.

I hope this helps! Let me know if you have any further questions.
Reply
#4
Thank you for the code
I didn't know there is a ROI function in cv2
make everything so easy now :-)

Thank you! ,
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020