Help Error: no module named pyrealsense2
Hi, I am trying to setup an intel depth camera with a RPI4. The OS is Raspbian buster. However, I keep on getting the error: no module named pyrealsense2. Has anyone encountered this error or does anyone know how to fix this?
-
Hi Gracex. When this error occurs on Raspberry Pi, a solution that can resolve it is to locate files with the extension .so that are created after the Python wrapper has been built from source code and place the Python script that you have created in the same folder location as those files. The files are named 'librealsense2.so' and 'pyrealsense2.so'.
If Python 3 is being used then the pyrealsense2.so file will likely have a more complex filename based on your Python 3 version number, such as 'pyrealsense2.cpython-35m-arm-linux-gnueabihf.so'. For example, Python 3.5 may generate a filename with '35m' in it, whilst Python 3.7 may have '37m', and so on.
Once these two .so files are located then they can be copy and pasted to the folder location where your Python script is stored. Alternatively, one RealSense user copied their script file to the original location of the .so files instead.
On Raspberry Pi I would suggest looking for the .so files in the librealsense/build folder.
-
Hi, I did that and it still did not work. I am completely new on the raspbery pi. I think I might of copied the .so files into the wrong python script folder. Could you clarify what folder it is in. Also, I cannot find the pyrealsense.so file. I followed countless tutorials on YouTube and it still isn't working :(
-
Could you check for the .so files on your Raspberry Pi under the folder location librealsense > build > wrappers >python please.
https://github.com/IntelRealSense/librealsense/issues/3062#issuecomment-454383972
Also, remember that if you are using Python 3.7 then pyrealsense2.so will have an extended filename like pyrealsense2.cpython-37m-arm-linux-gnueabihf.so - the best way to identify it is to look for a file whose name starts with pyrealsense2 and ends in .so
-
Hi this works thank you so much. Does this mean every time I try to use a python program with the intel camera, i have to copy those files into the same folder as the python program. Also, do you know any python files that let the intel depth camera measure the distance of objects on the raspberry pi, thank you so much!
-
That's great to hear that you were successful :)
The two .so files should be in the same folder as each new pyrealsense2 script that you create, yes. So if you only had a single folder for your scripts then you would only have to copy the .so files into the folder once, though it would make it difficult to neatly organize your pyrealsense2 scripts if they were all in the same folder.
Alternatively, you could set a PYTHONPATH for the Python wrapper to define a path to pyrealsense2, as described in Step 4 of the official Python installation instructions.
https://github.com/IntelRealSense/librealsense/tree/master/wrappers/python#building-from-source
The pyrealsense2 PyPi page has a very simple example script at the link below.
https://pypi.org/project/pyrealsense2/
You can find further example scripts here:
Intel's distance_to_object Jupyter Notebook example also demonstrates aligning depth to color and printing a distance value.
https://github.com/IntelRealSense/librealsense/blob/jupyter/notebooks/distance_to_object.ipynb
-
Hi, sorry to bother you again. I tried running the distance to object code on my raspberry pi but i keep on getting this error:
net = cv2.dnn.readNetFromCaffe("../MobileNetSSD_deploy.prototxt", "../MobileNetSSD_deploy.caffemodel")
cv2.error: OpenCV(4.5.1) /tmp/pip-wheel-qd18ncao/opencv-python/opencv/modules/dnn/src/caffe/caffe_io.cpp:1121: error: (-2:Unspecified error) FAILED: fs.is_open(). Can't open "../MobileNetSSD_deploy.prototxt" in function 'ReadProtoFromTextFile'do you have any advice on how to fix it?
-
It is no bother at all. There are references about solving this error at the link below.
-
I researched the question deeply but could not find an answer unfortunately. Let's look at the problem from the perspective of the comment in the link below, that suggested that the OpenCV version might be a problem.
https://github.com/IntelRealSense/librealsense/issues/3173#issuecomment-458976012
Do you have OpenCV 3.4 or OpenCV 4 installed, please? RealSense examples that use OpenCV were designed for OpenCV 3.4, as described in the link below.
https://dev.intelrealsense.com/docs/opencv-wrapper
-
The SDK's OpenCV example page states that samples can be converted to OpenCV 4 with minor code changes. If your problem with prototxt is related to the OpenCV version then I don't know how to alter the code to correct that though.
The original goal when researching the distance calculation aspect of your case was to find a Python version of the SDK's Ready to Hack C++ example that prints the distance to whatever is in the center of the camera's view as simple text.
https://github.com/IntelRealSense/librealsense#ready-to-hack
I researched such examples again and found a Python conversion of Ready To Hack that a RealSense user had shared. You may be able to use this instead of the distance_to_object example.
https://community.intel.com/t5/Items-with-no-label/D435-Distance/td-p/719293
#Camera set up
while True:
frames = pipeline.wait_for_frames()
depth_frame = frames.get_depth_frame()
if not depth_frame: continue
width = depth_frame.get_width()
height = depth_frame.get_height()
#print(width,height)
#Calculate distance
dist_to_center = depth_frame.get_distance(int(width/2), int(height/2))
print('The camera is facing an object:',dist_to_center,'meters away') -
Hi, I want the intel camera to be able to detect objects and measure the distance of those objects from the intel camera. Do you know any code for distance measurement and image detection using tensor flow and the intel camera? It can only be with tensorflow and not any other machine learning platform. Sorry for being so annoying, I am really new at this.
-
The RealSense SDK has a TensorFlow wrapper that can be used with Python. It provide a range of samples to try, starting with object detection and classification and progressing through to use of live data.
https://github.com/IntelRealSense/librealsense/tree/master/wrappers/tensorflow
In its second example, the wrapper demonstrates use of depth data to calculate a human's height based on the Y axis. This is achieved by querying XYZ coordinates of a detected object, so conceivably you could adapt it to obtain Z (distance).
Please sign in to leave a comment.
Comments
13 comments