picamera2 icon indicating copy to clipboard operation
picamera2 copied to clipboard

[BUG] Native Zoom on Camera

Open Rob-Nafous opened this issue 9 months ago • 8 comments

Please only report one bug per issue!

Describe the bug The camera is super zoomed

To Reproduce Hello, I wrote down a code in order to do facial_recognition with my raspberry pi 5. I use a picamera module 3. I followed the tutorial a first time. And everything went well and perfect.

However, after reinitializating my raspberry pi. Setting my conda environment, downloading all my librairies. My code wasn't working anymore. So I went back to my test.py as follow :

from picamera2 import Picamera2, Preview
import time
picam2 = Picamera2()
camera_config = picam2.create_preview_configuration()
picam2.configure(camera_config)
picam2.start_preview(Preview.QTGL)
picam2.start()
time.sleep(2)
picam2.capture_file("test.jpg")

and saw that the camera was SUPER zoomed. Like x30. I don't understand why. Because here's the step :

After reinitializating my pi :

Installing conda with :

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-armv7l.sh
chmod +x Miniconda3-latest-Linux-armv7l.sh
./Miniconda3-latest-Linux-armv7l.sh

checking if the camera is working with :

rpicam-hello

All works well the camera is good

Downloading picamera2 with :

sudo apt install -y python3-picamera2
cd Desktop
python test.py 

and see that the camera is super zoomed.

Expected behaviour To not have a camera x30.

Console Output, Screenshots I can provide screenshot of whatever you want just ask me. I beg you help me please I'm turning crazy haha.

Hardware : Raspberry pi 5. Camera Module 3.

Additional context No additionnal context. But I could give you more if you need it. Thanks a lot for your time and help.

Rob-Nafous avatar Mar 18 '25 14:03 Rob-Nafous

I will let an admin close this issue. But the error is quite 'stupid'

Just, we need to put the preview before the configuration. Which isn't the case in the user manual : https://datasheets.raspberrypi.com/camera/picamera2-manual.pdf

Do as follow :

from picamera2 import Picamera2, Preview
import time

picam2 = Picamera2()
picam2.start_preview(Preview.QTGL)
camera_config = picam2.create_preview_configuration()
picam2.configure(camera_config)

picam2.start()
time.sleep(5)
picam2.close() #Remove the sleep and close if you want to close it manually with ctrl+C.

Don't ask me why or how, I don't know.

Is it possible to update the manual ? That's quite annoying to follow tutorials that aren't up to date haha.

Thanks a lot.

Rob-Nafous avatar Mar 18 '25 15:03 Rob-Nafous

Hi, can you just confirm you Picamera2 version (apt list python3-picamera2)? I know there was a crazy zoom-related bug a little while back.

I also don't know anything much about anaconda, but could that somehow mean you're not using the version of Picamera2 that you expect? I've tried your original script with a vanilla installation (i.e. no conda, no virtual environments), and it seems to work OK for me.

davidplowman avatar Mar 20 '25 10:03 davidplowman

Hello david, python3-picamera2/stable,stable,now 0.3.25-1 all [installed]

I followed the instruction in first place after creating my conda environment. I'm not an expert either so couldn't help more I am sorry.

Rob-Nafous avatar Mar 20 '25 14:03 Rob-Nafous

Do you have a spare SD card lying around where you could install a clean version of Raspberry Pi OS. Don't add anything else to it (except for sudo apt update and sudo apt full-upgrade), so no conda environments, and then just try if the zoom problem is present or not?

davidplowman avatar Mar 20 '25 14:03 davidplowman

I might have one at home, I'll try it tomorrow and let you know how it works :)

Rob-Nafous avatar Mar 20 '25 14:03 Rob-Nafous

Hi David,

So yeah, it works with an empty SD. I don't understand how a conda environment can change the comportment?

Rob-Nafous avatar Mar 21 '25 16:03 Rob-Nafous

Not sure either, I'm afraid! I'm wondering whether there's some kind of issue where the Picamera2 version gets coped/frozen when a conda environment is set up and then doesn't update (even though the system version does). Is that possible? Generally when you import a module you can look at module.__file__ which will give you a clue as to where it's being loaded from. Does that suggest anything?

davidplowman avatar Mar 21 '25 16:03 davidplowman

We had the same issue after upgrading to bookworm 2024-11-19 on https://www.planktoscope.org/

Upgrading python3-libcamera from 0.3.2+rpt20240927-1 to 0.4.0+rpt20250213-1 solves it.

sudo apt install --only-upgrade python3-libcamera

Here is the output

Reading package lists... Done     
Building dependency tree... Done                                                                                                                                                                                    
Reading state information... Done
The following additional packages will be installed:                                                                                                                                                                
  libcamera-ipa libcamera-tools libcamera0.4 libpisp-common libpisp1
The following NEW packages will be installed:                                                             
  libcamera0.4                                                                                            
The following packages will be upgraded:                                                                                                                                                                            
  libcamera-ipa libcamera-tools libpisp-common libpisp1 python3-libcamera                                 
5 upgraded, 1 newly installed, 0 to remove and 170 not upgraded.                                          
Need to get 2,445 kB of archives.                                                                         
After this operation, 1,225 kB of additional disk space will be used. 
Do you want to continue? [Y/n]                                                                            
Get:1 http://archive.raspberrypi.com/debian bookworm/main arm64 libpisp1 arm64 1.1.0-1 [282 kB]                                                                                                                     
Get:2 http://archive.raspberrypi.com/debian bookworm/main arm64 libpisp-common all 1.1.0-1 [4,908 B]
Get:3 http://archive.raspberrypi.com/debian bookworm/main arm64 libcamera0.4 arm64 0.4.0+rpt20250213-1 [656 kB]                                                                                                     
Get:4 http://archive.raspberrypi.com/debian bookworm/main arm64 libcamera-ipa arm64 0.4.0+rpt20250213-1 [836 kB]
Get:5 http://archive.raspberrypi.com/debian bookworm/main arm64 libcamera-tools arm64 0.4.0+rpt20250213-1 [335 kB]
Get:6 http://archive.raspberrypi.com/debian bookworm/main arm64 python3-libcamera arm64 0.4.0+rpt20250213-1 [330 kB]
Fetched 2,445 kB in 0s (5,544 kB/s)         
Reading changelogs... Done
(Reading database ... 123517 files and directories currently installed.)
Preparing to unpack .../0-libpisp1_1.1.0-1_arm64.deb ...
Unpacking libpisp1:arm64 (1.1.0-1) over (1.0.7-1) ... 
Preparing to unpack .../1-libpisp-common_1.1.0-1_all.deb ...
Unpacking libpisp-common (1.1.0-1) over (1.0.7-1) ... 
Selecting previously unselected package libcamera0.4:arm64.
Preparing to unpack .../2-libcamera0.4_0.4.0+rpt20250213-1_arm64.deb ...
Unpacking libcamera0.4:arm64 (0.4.0+rpt20250213-1) ...
Preparing to unpack .../3-libcamera-ipa_0.4.0+rpt20250213-1_arm64.deb ...
Unpacking libcamera-ipa:arm64 (0.4.0+rpt20250213-1) over (0.3.2+rpt20240927-1) ...
Preparing to unpack .../4-libcamera-tools_0.4.0+rpt20250213-1_arm64.deb ...
Unpacking libcamera-tools (0.4.0+rpt20250213-1) over (0.3.2+rpt20240927-1) ...
Preparing to unpack .../5-python3-libcamera_0.4.0+rpt20250213-1_arm64.deb ...
Unpacking python3-libcamera:arm64 (0.4.0+rpt20250213-1) over (0.3.2+rpt20240927-1) ...
Setting up libpisp-common (1.1.0-1) ...
Setting up libpisp1:arm64 (1.1.0-1) ...
Setting up libcamera-ipa:arm64 (0.4.0+rpt20250213-1) ...
Setting up libcamera0.4:arm64 (0.4.0+rpt20250213-1) ...
Setting up libcamera-tools (0.4.0+rpt20250213-1) ...
Setting up python3-libcamera:arm64 (0.4.0+rpt20250213-1) ...
Processing triggers for libc-bin (2.36-9+rpt2+deb12u9) ...

sonnyp avatar Apr 02 '25 13:04 sonnyp