IntelRealSense / librealsense

Intel® RealSense™ SDK
https://www.intelrealsense.com/
Apache License 2.0
7.55k stars 4.81k forks source link

How do i install Pyrealsense2-aarch64 into my Raspberry pi 4 8Gb version #12886

Open Sharath-MRNoBoDy opened 5 months ago

Sharath-MRNoBoDy commented 5 months ago

Products that iam using are as follows

Camera | Intel Realsense camera d457 OS | Ubuntu raspberry pi bookworm Platform | Raspberry pi 4b 8gm version kernel | 5.15.0-1053-raspi ..... aarch64 GNU/Linux

I was able to follow the IntelRealsense SDK tutorial that is available here . I am able to view the camera from the realsense Veiwer and SDK.

Now comes the error i get by installing pyrealsense2-aarch64 it throws a error saying

pip install pyrealsense2-aarch64
Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement pyrealsense2-aarch64 (from versions: none)
ERROR: No matching distribution found for pyrealsense2-aarch64

I have install python 3.10.12 PIP 22.0.2

MartyG-RealSense commented 5 months ago

Hi @Sharath-MRNoBoDy Until recently the aarch64 Arm version of the pyrealsense2 pip packages only worked for Python 3.7 to 3.9 and you are using Python 3.10. Using an unsupported Python 3 version with pip install would likely cause the message ERROR: No matching distribution found for pyrealsense2-aarch64

Since version 2.55.1 of the SDK was released a week ago (April 21 2024), Python 3.10 has been supported.

image

Have you attempted installation of the SDK and pyrealsense2 wrapper since 2.55.1 and the new aarch64 file were released, please?

Sharath-MRNoBoDy commented 5 months ago

yes i had tried to install this pyrealsense2 package but it still not able to resolve this issue on the RPI 4B when i run a program using the import of this library i get this error Traceback (most recent call last): File "/home/program.py", line 13, in <module> pipe.start(cfg) RuntimeError: Couldn't resolve requests iam using the usb type c 3.1 cable but the same cable is able to fetch the camera feed from the SDK but not able to view the feed when running a program

MartyG-RealSense commented 5 months ago

RuntimeError: Couldn't resolve requests is not related to the SDK or Python version. It occurs when a stream resolution / FPS combination has been requested that the camera cannot currently provide. If a valid resolution / FPS has been defined in a script then a common reason for it is if the camera's USB connection type is being mis-detected as USB 2.1 instead of 3.1 or 3.2, as the supported configurations are more limited on a 2.1 connection.

A way to test for this possibility would be to set your streams to 640x480 and 30 FPS in your config instructions, as this configuration will work with both USB 2.1 and 3.1 / 3.2. If 640x480 works then it is likely that your camera connection is being detected as USB 2.1 when running the script.

Sharath-MRNoBoDy commented 5 months ago

@MartyG-RealSense I have specified to the same frame specs as you have mentioned but iam not able to fetch the live feed

cfg.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30); cfg.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) ; cfg.enable_stream(rs.stream.infrared, 640, 480, rs.format.y8, 30) ;

I am trying to fetch 3 feed from the camera of RBG , Dept and Infrared i am running the same program in the my PC but the programs runs with out any for infrared feed but the frame gets stuck in the RGB and Dept feed

MartyG-RealSense commented 5 months ago

Do you have any other programs running that are using the depth and RGB streams when you run your script?

Sharath-MRNoBoDy commented 5 months ago

@MartyG-RealSense no , just the program getting the RGB, Dept, and Infrared stream other than this the RealSense Viewer is closed before running the program

MartyG-RealSense commented 5 months ago

What happens if you comment out the infrared stream and just access depth and color on your Pi?

Sharath-MRNoBoDy commented 5 months ago

Even though I comment the NIR(Infrared) feed and other related snips The code is still giving me the Runtime error

line 13, in <module> pipe.start(cfg) RuntimeError: Couldn't resolve requests

But the same Code Snippet is able to show the RGB and Dept Feed when I connect the camera into the PC and run the code. This tells the code is error free

MartyG-RealSense commented 5 months ago

Does the script run if you remove the word cfg from the brackets of the pipe start line so that the script ignores the cfg lines and applies the camera's default configuration for each stream instead?

If the script does run with cfg removed, does the script work if you put cfg back in the brackets and remove the spaces before the ; semi-colon line end symbol that you have on the depth and infrared instructions?

cfg.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30); 
cfg.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) ; 
cfg.enable_stream(rs.stream.infrared, 640, 480, rs.format.y8, 30) ;
Sharath-MRNoBoDy commented 5 months ago

If I do that change then it shows this error AttributeError: module 'pyrealsense2' has no attribute 'pipeline' since there is not attribute of Pipeline in pyrealsense2 package it is showing me the above error And if i add the (cfg) in the pipeline then it wont run and shows Runtime error for the same line

MartyG-RealSense commented 5 months ago

When removing cfg from the brackets, does the AttributeError still occur if you change the import pyrealsense2 as rs line to the one below?

import pyrealsense2.pyrealsense2 as rs

Sharath-MRNoBoDy commented 5 months ago

When doing all this iam back to ground zero with a fresh boot to raspberry pi os i tried to build the wrapper from the here but getting all types of error from proxy server(connecting with the network team) to

sudo apt-get install librealsense2-utils
sudo apt-get install librealsense2-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package librealsense2-utils
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package librealsense2-dev

I followed the guide from here

echo "deb [signed-by=/etc/apt/keyrings/librealsense.pgp] https://librealsense.intel.com/Debian/apt-repo `lsb_release -cs` main" | \
sudo tee /etc/apt/sources.list.d/librealsense.list
sudo apt-get update
deb [signed-by=/etc/apt/keyrings/librealsense.pgp] https://librealsense.intel.com/Debian/apt-repo bookworm main
Ign:1 https://librealsense.intel.com/Debian/apt-repo bookworm InRelease
Hit:2 http://deb.debian.org/debian bookworm InRelease               
Hit:3 http://deb.debian.org/debian-security bookworm-security InRelease
Hit:4 http://deb.debian.org/debian bookworm-updates InRelease
Hit:5 http://archive.raspberrypi.com/debian bookworm InRelease
Get:6 http://archive.ubuntu.com/ubuntu jammy InRelease [270 kB]
Ign:1 https://librealsense.intel.com/Debian/apt-repo bookworm InRelease
Err:6 http://archive.ubuntu.com/ubuntu jammy InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C
Ign:1 https://librealsense.intel.com/Debian/apt-repo bookworm InRelease
Err:1 https://librealsense.intel.com/Debian/apt-repo bookworm InRelease
  Could not handshake: An unexpected TLS packet was received. [IP: 14.139.134.20 3128]
Reading package lists... Done
W: GPG error: http://archive.ubuntu.com/ubuntu jammy InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C
E: The repository 'http://archive.ubuntu.com/ubuntu jammy InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: Target Packages (main/binary-arm64/Packages) is configured multiple times in /etc/apt/sources.list.d/archive_uri-https_librealsense_intel_com_debian_apt-repo-bookworm.list:1 and /etc/apt/sources.list.d/librealsense.list:1
W: Target Packages (main/binary-armhf/Packages) is configured multiple times in /etc/apt/sources.list.d/archive_uri-https_librealsense_intel_com_debian_apt-repo-bookworm.list:1 and /etc/apt/sources.list.d/librealsense.list:1
W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list.d/archive_uri-https_librealsense_intel_com_debian_apt-repo-bookworm.list:1 and /etc/apt/sources.list.d/librealsense.list:1
W: Target Translations (main/i18n/Translation-en_GB) is configured multiple times in /etc/apt/sources.list.d/archive_uri-https_librealsense_intel_com_debian_apt-repo-bookworm.list:1 and /etc/apt/sources.list.d/librealsense.list:1
W: Target Translations (main/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list.d/archive_uri-https_librealsense_intel_com_debian_apt-repo-bookworm.list:1 and /etc/apt/sources.list.d/librealsense.list:1

Why am I seeing the warnings for GPG error and E: The repository 'http://archive.ubuntu.com/ubuntu jammy InRelease' is not signed. I checked for the other warnings but the files are empty I feel like my proxy is blocking Upgrades from happening

MartyG-RealSense commented 5 months ago

The distribution_linux.md package installation instructions should not be used with computers with an Arm architecture such as Raspberry Pi as they are designed for use with x86 / x64 architecture computers such as desktop and laptop PCs.

A method of installing librealsense on Raspberry Pi that historically works well for Pi is libuvc backend. This method can be performed with a simple build script at the link below.

https://github.com/IntelRealSense/librealsense/blob/master/doc/libuvc_installation.md

Sharath-MRNoBoDy commented 4 months ago

Hi @MartyG-RealSense I iam not able to install pyrealsense2 in the same RPI 4B I am able to install numpy and other packages in to the same device but the pyrealsense2 package is not able to be found iam getting this error is i try to install the same

root@ubuntu:/home/ubuntu/Desktop# source testpip/bin/activate
(testpip) root@ubuntu:/home/ubuntu/Desktop# pip3 install numpy
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting numpy
  Downloading numpy-1.26.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (14.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.2/14.2 MB 11.0 MB/s eta 0:00:00
Installing collected packages: numpy
Successfully installed numpy-1.26.4
(testpip) root@ubuntu:/home/ubuntu/Desktop# pip3 install pyrealsense2
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
ERROR: Could not find a version that satisfies the requirement pyrealsense2 (from versions: none)
ERROR: No matching distribution found for pyrealsense2
(testpip) root@ubuntu:/home/ubuntu/Desktop# pip3 install pyrealsense2-aarch64
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
ERROR: Could not find a version that satisfies the requirement pyrealsense2-aarch64 (from versions: none)
ERROR: No matching distribution found for pyrealsense2-aarch64
MartyG-RealSense commented 4 months ago

Hi @Sharath-MRNoBoDy The pip install pyrealsense2 command does not work on Raspberry Pi, unfortunately. The wrapper must be built from source code instead.

The easiest way to do this on Pi may be to edit the libuvc backend procedure's build script to add commands to build the pyrealsense2 wrapper at the same time that librealsense is built.

Change line 46 from this:

cmake ../ -DFORCE_LIBUVC=true -DCMAKE_BUILD_TYPE=release

to this:

cmake ../ -DFORCE_LIBUVC=true -DCMAKE_BUILD_TYPE=release -DBUILD_PYTHON_BINDINGS:bool=true

Sharath-MRNoBoDy commented 4 months ago

I tried the command u have mentioned and its still not able to install the same

MartyG-RealSense commented 4 months ago

A RealSense user at https://github.com/IntelRealSense/librealsense/issues/11506#issuecomment-1599168850 provided a detailed guide about how they set up librealsense and pyrealsense2 on a Pi 4 with Ubuntu.

Sharath-MRNoBoDy commented 4 months ago

By following your advice to work with ubuntu I started to work on the Ubuntu in Raspberry pi4b I was able to install and build the required libraries and packages in the RPI4B

now I am back to same error stating while using the terminal SSH to RPI4B with UBUNTU


Traceback (most recent call last):
  File "/home/ubuntu/Desktop/realsense/realsense/temp.py", line 15, in <module>
    frame = pipe.wait_for_frames(10000)
RuntimeError: Frame didn't arrive within 10000

and while using the same RPI Physically, Iam getting a different error message 
MartyG-RealSense commented 4 months ago

What happens if you take the 10000 out of the brackets?

frame = pipe.wait_for_frames()

Sharath-MRNoBoDy commented 4 months ago

If i remove the 10000 out form the brackets then I get the

RuntimeError : Frame didn't arrive within 5000 that's the reason I increased to 10000

MartyG-RealSense commented 4 months ago

'5000' means that new frames did not arrive from the camera during a 5 second period of time. 10000 means new frames did not arrive for 10 seconds.

Does the behaviour of the camera improve if you unplug the micro-sized end of the USB cable from the base of the D457 camera, reverse the connector's orientation and plug it back into the camera (USB-C cables are two-way insertion at the micro-sized end).

Sharath-MRNoBoDy commented 4 months ago

As you suggest to flip the cable and try iam still getting the same error. I also tried to execute a test program from here

I am still getting the same error following with while using ssh

  File "/home/ubuntu/Desktop/sharath /realsense/realsense/test.py", line 11, in <module>
    frames = pipeline.wait_for_frames()
RuntimeError: Frame didn't arrive within 5000

and while using it physically

Line 6 , in <module>
pipeline.start()
RuntimeError: no device Connected

with the test program from here also tried to execute a test program from here while running the same code in the PC it is running but when the same code is executed in the RPI 4B them iam getting both errors

MartyG-RealSense commented 4 months ago

As you are using RSUSB = true (which should take care of any potential conflicts between librealsense and the kernel) and the scripts that you have tested work correctly on a PC, it is possible that the problem is with the Bookworm version of the Ubuntu OS on your Pi.

Some RealSense users with a Pi use Ubuntu 22.04, like the user mentioned earlier in this discussion at https://github.com/IntelRealSense/librealsense/issues/11506#issuecomment-1599168850 who successfully used wait_for_frames(10000)

Sharath-MRNoBoDy commented 3 months ago

Hi Marty-G I tried the method u had mentioned but still not able to retrieve the data from the camera but instead it shows the no device is connected

Traceback (most recent call last):
  File "/home/ubuntu/temp.py", line 12, in <module>
    pipe.start(cfg)
RuntimeError: No device connected

But iam still running the same code even changing to wait_for_frames(5000) to wait_for_frames(10000) like mention the last comment But sometimes with increase wait for frames I get line 15, in frame = pipe.wait_for_frames(10000) RuntimeError: Frame didn't arrive within 10000 or any other frame wait is mentioned

MartyG-RealSense commented 3 months ago

What happens if you use try_wait_for_frames() so that the Frame didn't arrive type of RuntimeError does not cause the program to exit running?

frame = pipe.try_wait_for_frames(10000)

Sharath-MRNoBoDy commented 3 months ago

Nope even if i use the the snippet u suggested but iam still not able to retrieve feed form the camera in the raspberry pi.
But in the normal desktop iam having no issues.

MartyG-RealSense commented 3 months ago

As your code works on a desktop PC but not Pi, this indicates that the script is okay.

As the Viewer and SDK works but pyrealsense2 does not, this indicates that the Bookworm OS is not the cause of the problem.

Although the pip install pyrealsense2 installation method supports Arm devices such as Pi, other RealSense users with a Pi have consistently reported that the pip install method's Arm package does not work with Pi boards. This suggests that a source code installation of pyrealsense2 on Pi might be required instead.

https://github.com/IntelRealSense/librealsense/issues/12886#issuecomment-2124257588 suggests to me that you have already tried building pyrealsense2 from source code though. Is this correct, please?

Sharath-MRNoBoDy commented 3 months ago

Yes @MartyG-RealSense I did completely build the packages for the Pyrealsense2 form the source code but still the problem arises in both the Ubuntu and even on the Raspbian OS. Even if do this

Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyrealsense2
>>> import pyrealsense2 as rs 
>>> import numpy 

though the Pyrealsense is getting imported in the pyhton3 command but when ever i try to run the programs it show device not connected and even in the SDK application it shows Intel RealSense device Detected and even preview the fedd form the sdk

MartyG-RealSense commented 3 months ago

When the camera works with SDK applications such as the Viewer but it is not detected by the pyrealsense2 wrapper, it can unfortunately be very difficult to solve.

A Python 3.11 user at https://github.com/IntelRealSense/librealsense/issues/3062#issuecomment-1814386407 shared what worked in their particular case.