View my account

Help Error: no module named pyrealsense2

Comments

13 comments

  • MartyG

    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.

    0
    Comment actions Permalink
  • Gracex

    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 :(

    0
    Comment actions Permalink
  • MartyG

    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

     

    0
    Comment actions Permalink
  • Gracex

    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!

    0
    Comment actions Permalink
  • MartyG

    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:

    https://github.com/IntelRealSense/librealsense/tree/master/wrappers/python/examples#sample-code-for-intel-realsense-python-wrapper

    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

    0
    Comment actions Permalink
  • Gracex

    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?

    0
    Comment actions Permalink
  • MartyG

    It is no bother at all.  There are references about solving this error at the link below.

    https://support.intelrealsense.com/hc/en-us/community/posts/1500001251202-Can-t-open-MobileNetSSD-deploy-prototxt-

    0
    Comment actions Permalink
  • Gracex

    Hi, in the solution you linked, the said : "You can set the directory using datadir variable." I am a beginner at this, so I have no idea what that means. Could you explain it to me, thank you so much

    0
    Comment actions Permalink
  • MartyG

    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

     

    0
    Comment actions Permalink
  • Gracex

    Hi, I have opencv4 installed. does this mean that I can't use opencv on the intel camera, unless its opencv 3.4?

    0
    Comment actions Permalink
  • MartyG

    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.

    https://github.com/IntelRealSense/librealsense/tree/master/wrappers/opencv#opencv-samples-for-intel-realsense-cameras

     

    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')

    0
    Comment actions Permalink
  • Gracex

    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.

    0
    Comment actions Permalink
  • MartyG

    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).

    0
    Comment actions Permalink

Please sign in to leave a comment.