Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jetson Nano pyrelasense has not attribute pipeline #13453

Closed
harshal-14 opened this issue Oct 22, 2024 · 14 comments
Closed

Jetson Nano pyrelasense has not attribute pipeline #13453

harshal-14 opened this issue Oct 22, 2024 · 14 comments

Comments

@harshal-14
Copy link

harshal-14 commented Oct 22, 2024

librealsense 2.55.1 RELEASE
OS Linux
Name Intel RealSense D435I
Serial Number 213622072204
Firmware Version 5.15.1.55
Advanced Mode YES
Camera Locked YES
Usb Type Descriptor 3.2
Product Line D400
Asic Serial Number 218523067486
Firmware Update Id 218523067486
Dfu Device Path

Hi,
I built everything based on this method

#13445

, however I cannot find the pyrealsense to work with even a basic python script.

import pyrealsense2 as rs
import numpy as np
import cv2

# Configure depth and color streams
pipeline = rs.pipeline()
config = rs.config()

# Get device product line for setting a supporting resolution
pipeline_wrapper = rs.pipeline_wrapper(pipeline)
pipeline_profile = config.resolve(pipeline_wrapper)
device = pipeline_profile.get_device()
device_product_line = str(device.get_info(rs.camera_info.product_line))

found_rgb = False
for s in device.sensors:
    if s.get_info(rs.camera_info.name) == 'RGB Camera':
        found_rgb = True
        break
if not found_rgb:
    print("The demo requires Depth camera with Color sensor")
    exit(0)

config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)

# Start streaming
pipeline.start(config)

try:
    while True:
        # Wait for a coherent pair of frames: depth and color
        frames = pipeline.wait_for_frames()
        depth_frame = frames.get_depth_frame()
        color_frame = frames.get_color_frame()
        if not depth_frame or not color_frame:
            continue

        # Convert images to numpy arrays
        depth_image = np.asanyarray(depth_frame.get_data())
        color_image = np.asanyarray(color_frame.get_data())

        # Apply colormap on depth image (image must be converted to 8-bit per pixel first)
        depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)

        # Stack both images horizontally
        images = np.hstack((color_image, depth_colormap))

        # Show images
        cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)
        cv2.imshow('RealSense', images)
        cv2.waitKey(1)

finally:
    # Stop streaming
    pipeline.stop()

I get this error

AttributeError: module 'pyrealsense2' has no attribute 'pipeline'

Upon digging I found this is a common issue on Jetson devices #13080 but I don't find the *.so files for pyrealsense. What am I doing wrong?

@MartyG-RealSense
Copy link
Collaborator

Hi @harshal-14 When pyrealsense2 is built from source code, after building of the wrapper is completed the .so files will usually be found in the librealsense > build > wrappers > python directory of the librealsense source code folder.

I note that you used the libuvc backend instructions, which use the 'libuvc_installation.sh' build script. This script downloads the librealsense source code and places a folder called librealsense-master on the computer.

If you modified line 46 of the libuvc script to include the flag -DBUILD_PYTHON_BINDINGS:bool=true so that pyrealsense2 is built from source code at the same time as librealsense, then I would recommend finding the 'librealsense-master' folder on your computer and then navigating to the sub-folder location 'build > wrappers > python' to see whether the .so files are there.

@harshal-14
Copy link
Author

image
Hey @MartyG-RealSense,
I don't see any .so files in here.

@MartyG-RealSense
Copy link
Collaborator

Thanks for checking the wrappers > python folder.

For some RealSense users in the past, amending their 'import pyrealsense2 as rs' line to the one below has resolved the AttributeError: module 'pyrealsense2' has no attribute 'pipeline' error.

import pyrealsense2.pyrealsense2 as rs

@harshal-14
Copy link
Author

Hi Marty, thanks for your prompt reply, however this doesn't solve the problem.

import pyrealsense2.pyrealsense2 as rs

ModuleNotFoundError: No module named 'pyrealsense2.pyrealsense2'

@MartyG-RealSense
Copy link
Collaborator

Usually, installing the pyrealsense2 wrapper from packages instead of source code with the command pip install pyrealsense2 does not work on Jetson boards even though pip install of the wrapper supports devices with Arm architecture like Jetson. It would be worth trying just to eliminate the possibility of whether it will work or not though.

@harshal-14
Copy link
Author

If I installed through pip then it shows even if device is connected and detected by realsense-viewer, lsusb it gives the following error:

pipeline_profile = config.resolve(pipeline_wrapper)
RuntimeError: No device connected

@MartyG-RealSense
Copy link
Collaborator

Is the camera also not detected if the test script below is used?

# First import the library
import pyrealsense2 as rs

# Create a context object. This object owns the handles to all connected realsense devices
pipeline = rs.pipeline()
pipeline.start()

try:
    while True:
        # Create a pipeline object. This object configures the streaming camera and owns it's handle
        frames = pipeline.wait_for_frames()
        depth = frames.get_depth_frame()
        if not depth: continue

        # Print a simple text-based representation of the image, by breaking it into 10x20 pixel regions and approximating the coverage of pixels within one meter
        coverage = [0]*64
        for y in range(480):
            for x in range(640):
                dist = depth.get_distance(x, y)
                if 0 < dist and dist < 1:
                    coverage[x//10] += 1

            if y%20 is 19:
                line = ""
                for c in coverage:
                    line += " .:nhBXWW"[c//25]
                coverage = [0]*64
                print(line)

finally:
    pipeline.stop()

@harshal-14
Copy link
Author

If I installed doing

pip install pyrealsense2

then it shows camera not detected. But if I uninstall this one, and then try it shows

pyrelasense has not attribute pipeline

@MartyG-RealSense
Copy link
Collaborator

Having no .so files in the wrapper build folder makes it difficult to achieve a solution, unfortunately.

An installation method that has not apparently been tried yet is to use the librealsense + pyrealsense2 source code procedure at #6964 (comment) which was designed specifically for Jeton Nano.

As the instructions were written a while ago, step 7 refers to Python 3.6 instead of a recent Python version such as 3.12. If you only have one Python version installed on your computer though, you should be able to skip step 7 as setting the PYTHONPATH parameter would be unnecessary. The PYTHONPATH is to tell the computer which Python version to use if, for example, you had Python 2 and Python 3 installed on the same computer.

@MartyG-RealSense
Copy link
Collaborator

Hi @harshal-14 Do you require further assistance with this case, please? Thanks!

@harshal-14
Copy link
Author

Yes I tried all above steps, but nothing seems to work. Do you have any other solution in mind?

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Nov 8, 2024

You previously succeded in building the librealsense SDK with the 'libuvc backend' procedure that you described at #13445 (comment)

When editing line 46 of the libuvc_installation.sh scrpt, where you used the following CMake build instruction:

cmake ../ -DFORCE_LIBUVC=true -DCMAKE_BUILD_TYPE=release -DBUILD_EXAMPLES=true -DBUILD_GRAPHICAL_EXAMPLES=true -DBUILD_WITH_CUDA=on -DFORCE_RSUSB_BACKEND=TRUE

Have you tried adding the -DBUILD_PYTHON_BINDINGS:bool=true command for building the Python wrapper at the same time that librealsense is built?

cmake ../ -DFORCE_LIBUVC=true -DCMAKE_BUILD_TYPE=release -DBUILD_EXAMPLES=true -DBUILD_GRAPHICAL_EXAMPLES=true -DBUILD_WITH_CUDA=on -DBUILD_PYTHON_BINDINGS:bool=true

You do not need to use the -DFORCE_RSUSB_BACKEND=TRUE flag if you have already included -DFORCE_LIBUVC=true

@MartyG-RealSense
Copy link
Collaborator

Hi @harshal-14 Do you require further assistance with this case, please? Thanks!

@MartyG-RealSense
Copy link
Collaborator

Case closed due to no further comments received.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants