Picamera2 and libcamera Issue

Hi all,

Working with quad-camera imx477 HAT, It works well for taking pictures. But when I want to use Picamera2 for multiple capturing I got this error:

python test.py
[0:02:46.040444550] [1797] INFO Camera camera_manager.cpp:299 libcamera v0.0.0+4186-d1dc0373
[0:02:46.063683715] [1798] WARN RPI raspberrypi.cpp:1308 Mismatch between Unicam and CamHelper for embedded data usage!
[0:02:46.064559799] [1798] INFO RPI raspberrypi.cpp:1425 Registered camera /base/soc/i2c0mux/[email protected]/[email protected] to Unicam device /dev/media3 and ISP device /dev/media0
Traceback (most recent call last):
File “/home/pi/test.py”, line 8, in
“AwbMode”: libcamera.controls.AwbModeEnum.Daylight})
NameError: name ‘libcamera’ is not defined

I tried to install libcamera from HERE, then I got this error:

./install_pivariety_pkgs.sh -p libcamera_dev
=================================================
Hardware Revision: b03111
Kernel Version: 5.10.92-v7l+
OS Codename: bullseye
ARCH: armv7l
kernel:5.10.92-v7l+
–2023-02-23 11:10:18-- https://github.com/ArduCAM/Arducam-Pivariety-V4L2-Driver/releases/download/install_script/libcamera_dev_links.txt
Resolving github.com (github.com)… 140.82.113.3
Connecting to github.com (github.com)|140.82.113.3|:443… connected.
HTTP request sent, awaiting response… 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/353945933/26dffcaf-16dc-499f-9891-18a8b34bcb79?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230223%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230223T161018Z&X-Amz-Expires=300&X-Amz-Signature=0d99bd5aebb576e4a626344e75ddea26a4383c63c61d8a73d57168a6a2e1ee28&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=353945933&response-content-disposition=attachment%3B%20filename%3Dlibcamera_dev_links.txt&response-content-type=application%2Foctet-stream [following]
–2023-02-23 11:10:18-- https://objects.githubusercontent.com/github-production-release-asset-2e65be/353945933/26dffcaf-16dc-499f-9891-18a8b34bcb79?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230223%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230223T161018Z&X-Amz-Expires=300&X-Amz-Signature=0d99bd5aebb576e4a626344e75ddea26a4383c63c61d8a73d57168a6a2e1ee28&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=353945933&response-content-disposition=attachment%3B%20filename%3Dlibcamera_dev_links.txt&response-content-type=application%2Foctet-stream
Resolving objects.githubusercontent.com (objects.githubusercontent.com)… 185.199.109.133, 185.199.110.133, 185.199.108.133, …
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.109.133|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 4095 (4.0K) [application/octet-stream]
Saving to: ‘libcamera_dev_links.txt’

libcamera_dev_links 100%[===================>] 4.00K --.-KB/s in 0.003s

2023-02-23 11:10:18 (1.16 MB/s) - ‘libcamera_dev_links.txt’ saved [4095/4095]

–2023-02-23 11:10:18-- https://github.com/ArduCAM/Arducam-Pivariety-V4L2-Driver/releases/download/libcamera-v0.0.5/libcamera-dev-0.0.12-bullseye-armhf.deb
Resolving github.com (github.com)… 140.82.113.3
Connecting to github.com (github.com)|140.82.113.3|:443… connected.
HTTP request sent, awaiting response… 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/353945933/1496d493-b770-4703-9db7-bbfd8655f59a?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230223%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230223T161018Z&X-Amz-Expires=300&X-Amz-Signature=e31c9452f46e8b69c40b3f45ab5d733395a357ad4987f640138fac81860749bf&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=353945933&response-content-disposition=attachment%3B%20filename%3Dlibcamera-dev-0.0.12-bullseye-armhf.deb&response-content-type=application%2Foctet-stream [following]
–2023-02-23 11:10:18-- https://objects.githubusercontent.com/github-production-release-asset-2e65be/353945933/1496d493-b770-4703-9db7-bbfd8655f59a?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230223%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230223T161018Z&X-Amz-Expires=300&X-Amz-Signature=e31c9452f46e8b69c40b3f45ab5d733395a357ad4987f640138fac81860749bf&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=353945933&response-content-disposition=attachment%3B%20filename%3Dlibcamera-dev-0.0.12-bullseye-armhf.deb&response-content-type=application%2Foctet-stream
Resolving objects.githubusercontent.com (objects.githubusercontent.com)… 185.199.111.133, 185.199.109.133, 185.199.110.133, …
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.111.133|:443… connected.
HTTP request sent, awaiting response… 200 OK
Length: 964530 (942K)

Unknown error, please send the error message to [email protected]

Do you have any idea what is the issue? what process should I follow to make sure no issues will happen?
Thanks

@mahagh

May be a conflict

dpkg -l | grep libcamera
pip3 list | grep libcamera

@Edward

dpkg -l | grep libcamera
ii libcamera-apps 0.0.12 armhf libcamera-apps
ii libcamera-dev 0.0.12 armhf libcamera
iU libcamera0:armhf 0~git20230124+9b860a66-1 armhf complex camera support library

Nothing poped up for the second command

I think there should be the issue with libcamera which is installed in two locations! as this error appears when I wanted to install the updates:

Also this error:

sudo apt upgrade
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
You might want to run ‘apt --fix-broken install’ to correct these.
The following packages have unmet dependencies:
python3-picamera2 : Depends: python3-libcamera (>= 0~git20230105+5df5b72c-1) but it is not installed
E: Unmet dependencies. Try ‘apt --fix-broken install’ with no packages (or specify a solution).
[email protected]:~ $ sudo apt --fix-broken install
Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is heWaiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is heWaiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is heWaiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is heWaiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is heWaiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is heWaiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is heWaiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is heWaiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is heWaiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is heWaiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is heWaiting for cache lock: Could not get lock /var/lib/dpkg/lock-fronteWaiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1308 (packagekitd) kitd)… 12s
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
Correcting dependencies… Done
The following packages were automatically installed and are no longer required:
libfuse2 raspinfo
Use ‘sudo apt autoremove’ to remove them.
The following additional packages will be installed:
python3-libcamera
The following NEW packages will be installed:
python3-libcamera
0 upgraded, 1 newly installed, 0 to remove and 226 not upgraded.
50 not fully installed or removed.
Need to get 0 B/208 kB of archives.
After this operation, 1,102 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up gzip (1.10-4+deb11u1) …
(Reading database … 104292 files and directories currently installed.)
Preparing to unpack …/python3-libcamera_0~git20230124+9b860a66-1_armhf.deb …
Unpacking python3-libcamera (0~git20230124+9b860a66-1) …
dpkg: error processing archive /var/cache/apt/archives/python3-libcamera_0~git20230124+9b860a66-1_armhf.deb (–unpack):
trying to overwrite ‘/usr/lib/python3/dist-packages/libcamera/init.py’, which is also in package libcamera-dev 0.0.12
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
/var/cache/apt/archives/python3-libcamera_0~git20230124+9b860a66-1_armhf.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

Any idea?
Thanks

@mahagh

There seems to be a conflict between python3-picamera2 and libcamera

sudo apt-get remove --purge python3-picamera2
sudo apt remove libcamera0

@Edward
The commands did not help. I reinstalled the RPI and updated it.

Here the error:

python test.py
Traceback (most recent call last):
File “/home/pi/.local/lib/python3.9/site-packages/numpy/core/init.py”, line 23, in
from . import multiarray
File “/home/pi/.local/lib/python3.9/site-packages/numpy/core/multiarray.py”, line 10, in
from . import overrides
File “/home/pi/.local/lib/python3.9/site-packages/numpy/core/overrides.py”, line 6, in
from numpy.core._multiarray_umath import (
ImportError: libcblas.so.3: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/pi/test.py”, line 4, in
from picamera2 import MappedArray, Picamera2, Preview
File “/usr/lib/python3/dist-packages/picamera2/init.py”, line 5, in
from .converters import YUV420_to_RGB
File “/usr/lib/python3/dist-packages/picamera2/converters.py”, line 1, in
import numpy as np
File “/home/pi/.local/lib/python3.9/site-packages/numpy/init.py”, line 141, in
from . import core
File “/home/pi/.local/lib/python3.9/site-packages/numpy/core/init.py”, line 49, in
raise ImportError(msg)
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  • The Python version is: Python3.9 from “/usr/bin/python”
  • The NumPy version is: “1.24.2”

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: libcblas.so.3: cannot open shared object file: No such file or directory

@mahagh

The environment seems a bit chaotic.

I wonder if you follow my link below:
https://docs.arducam.com/Raspberry-Pi-Camera/Native-camera/PiCamera2-User-Guide/

My suggestion is to get a brand new system and use the link I provided to operate. If there are still problems, I think we can communicate remotely.

Tomorrow is the weekend, I wish you a happy weekend in advance.

@Edward
I reinstalled RPI and followed your link instructions, and I get the first error that I got.

python test.py
[0:04:36.186470342] [1542] INFO Camera camera_manager.cpp:299 libcamera v0.0.0+4186-d1dc0373
[0:04:36.208992068] [1543] WARN RPI raspberrypi.cpp:1308 Mismatch between Unicam and CamHelper for embedded data usage!
[0:04:36.210603717] [1543] INFO RPI raspberrypi.cpp:1425 Registered camera /base/soc/i2c0mux/[email protected]/[email protected] to Unicam device /dev/media4 and ISP device /dev/media3
Traceback (most recent call last):
File “/home/pi/test.py”, line 8, in
“AwbMode”: libcamera.controls.AwbModeEnum.Daylight})
NameError: name ‘libcamera’ is not defined

@Edward
Another issue is about Exposure time. With Picamera2, I could not capture images with more than exposure time = 40000. All the above ones give me a solid black shot. Meanwhile, with the same camera in Picamera, I could capture pictures with even exposure time = 2000000.

Any idea why this happens?

Thanks,

@mahagh

AWBMODE, how do you set it, you can refer to my test

from picamera2 import Picamera2, Preview
import time

picam2 = Picamera2()
controls = picam2.camera_controls
print(controls)

# picam2 = Picamera2()
picam2.start_preview(Preview.QTGL)

preview_config = picam2.create_preview_configuration()
picam2.configure(preview_config)

picam2.start()
time.sleep(1)

picam2.set_controls({"AwbMode": 1})
time.sleep(5)

I also tested the exposure at the same time

from picamera2 import Picamera2, Preview
import time

picam2 = Picamera2()
controls = picam2.camera_controls
print(controls)

# picam2 = Picamera2()
picam2.start_preview(Preview.QTGL)

preview_config = picam2.create_preview_configuration()
picam2.configure(preview_config)

picam2.start()
time.sleep(1)

picam2.set_controls({"ExposureTime": 60000})
time.sleep(5)

I used the same camera as you, and I didn’t seem to find your problem. Can you show me your code?

Hi @Edward,
I wanted the daylight white balance mode, that is why I used this code for it:

config = picam2.create_still_configuration(controls={“AwbEnabled”: 1,
“AwbMode”: libcamera.controls.AwbModeEnum.Daylight})

And this is the reason I get “libcamera not defined Error”.

Could you help me how to assign daylight as white ballance mode?

Thanks,

import time
from picamera2 import MappedArray, Picamera2, Preview
picam2 = Picamera2()
config = picam2.create_still_configuration(controls={“AwbEnabled”: 1,
“AwbMode”: libcamera.controls.AwbModeEnum.Daylight})
picam2.configure(config)
exposure_time = [1000000, 50000, 25000]
i = 1
for exp in exposure_time:
picam2.set_controls({“ExposureTime”: exp,“AnalogueGain”: 1.0})
picam2.start_and_capture_file(“ldr_{:02d}.jpg”.format(i), show_preview = 0)
i += 1

This is the whole code that I use.
Is there anything wrong there?

@mahagh

You can put the code that sets awd in set_controls as well.

Daylight:

picam2.set_controls({"AwbMode": 5})
1 Like

@Edward

Got you. Thanks