Opentrons / buildroot

The Opentrons fork of buildroot for building the OT2 system. Our default branch is opentrons-develop.
http://buildroot.org
Other
10 stars 7 forks source link

Need Support for OpenCV #199

Open vmalhotra99 opened 1 year ago

vmalhotra99 commented 1 year ago

I am unable to install OpenCV on my OT2. I need it to control a thermal camera. I am getting this error:

Command "/usr/bin/python -m pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-avsg5iox --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools==59.2.0 wheel==0.37.0 cmake>=3.1 pip scikit-build>=0.13.2 "numpy==1.13.3; python_version=='3.6' and platform_machine != 'aarch64' and platform_machine != 'arm64'" "numpy==1.17.0; python_version=='3.7' and platform_machine != 'aarch64' and platform_machine != 'arm64'" "numpy==1.17.3; python_version=='3.8' and platform_machine != 'aarch64' and platform_machine != 'arm64'" "numpy==1.19.3; python_version<='3.9' and sys_platform == 'linux' and platform_machine == 'aarch64'" "numpy==1.21.0; python_version<='3.9' and sys_platform == 'darwin' and platform_machine == 'arm64'" "numpy==1.19.3; python_version=='3.9' and platform_machine != 'aarch64' and platform_machine != 'arm64'" "numpy==1.21.2; python_version=='3.10' and platform_system!='Darwin'" "numpy==1.21.4; python_version=='3.10' and platform_system=='Darwin'" "numpy==1.22.0; python_version>='3.11'"" failed with error code 2 in None

sfoster1 commented 1 year ago

Yeah unfortunately I think that will be a problem since the OT-2 doesn't have a C compiler on it, and it doesn't look like there's an arm7 prebuild on pypi. If you can get opencv set up on a separate raspberry pi 3, you can probably copy the required libraries over to your OT-2.

vmalhotra99 commented 1 year ago

Oh okay. Thanks a lot!

Can you guide me as to what I need to copy and from where? I've never tired this method.

sfoster1 commented 1 year ago

Me either but I think it should be possible.

The overview of what we want to do is - and forgive me if you already know this, hopefully it will be useful to others in the future: Opencv is a compiled C and C++ shared object library (solib in unix parlance). It has python "bindings" that make it usable from python, but these bindings don't stand alone: they need to find the solib to use. In addition, the opencv solib has dynamic linker requirements for other solibs on the system - things that provide jpeg support, for instance. We'll need to get all those to the OT-2 as well.

While those libraries are in their standard places on a raspbian install, the OT-2's root filesystem is read-only. So we'll have to put these files somewhere non-standard, and point a python program to them with the use of the [url=https://man7.org/linux/man-pages/man8/ld.so.8.html]`LD_LIBRARY_PATH`[/url] environment variable. So, let's:

Get a raspberry pi 3 running raspbian. Install opencv: apt-get install opencv and python 3.7 (from deadsnakes I suppose?). Then pip install your python opencv package.

Next, you'll want to copy /usr/lib/python3.7/site-packages/opencv*(this is your python path; if I'm wrong about what it is, you can check it by running python -c 'import sys; print(sys.path)') to the OT-2 in /var/user-packages/python3.7/site-packages/ (you may have to make the last two directories). This should move the python stuff to the OT-2.

At that point, probably the best thing to do is to open a python shell on the OT-2 with LD_LIBRARY_PATH=/var/user-packages/usr/lib: LD_LIBRARY_PATH=/var/usr-packages/usr/lib python. Now, try and import your opencv package. To make sure it can find the opencv solibs when they're present, we want to run This will definitely fail, but it will fail with a message about not finding the .so files we talked about above. When it does, copy the so file at that path on the other raspberry pi to the equivalent path in /var/user-packages on the OT-2. So for instance, if python can't find /usr/lib/opencv.so.1, get it from the raspberry pi and put it in /var/user-packages/usr/lib/opencv.so.1. Then run python again, and copy over whatever new thing is missing.

This is kind of a pain! But I think it will work.

vmalhotra99 commented 1 year ago

Thanks! Can you also tell me what you mean by open a python shell? I'm working on the Jupyter notebook.

When I run this command in Jupyter, it still says No module named 'cv2'

!LD_LIBRARY_PATH=/var/user-packages/usr/lib: LD_LIBRARY_PATH=/var/usr-packages/usr/lib python -c "import cv2"