Cannot import opencv after succesfull install on Raspberry Pi - opencv

I try to install opencv on my Raspberry Pi with 4GB RAM (Raspberry OS version Linux 5.15.84-v8+ aarch64). Instructions I found on q-engineering. After a 2hr lasting build process the make announced that opencv was succesfully installed. When I try to import it I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
But opencv appears to be succesfully installed. When I run opencv_version I got:
$ opencv_version
4.7.0-dev
and:
/usr/local/bin/opencv_visualisation
/usr/local/bin/opencv_annotation
/usr/local/bin/opencv_version
/usr/local/bin/opencv_model_diagnostics
/usr/local/bin/opencv_waldboost_detector
/usr/local/bin/opencv_interactive-calibration
/usr/local/share/licenses/opencv4
/usr/local/share/opencv4
/usr/local/lib/aarch64-linux-gnu/cmake/opencv4
/usr/local/lib/aarch64-linux-gnu/pkgconfig/opencv4.pc
/usr/local/include/opencv4
/usr/local/include/opencv4/opencv2
/usr/local/include/opencv4/opencv2/opencv.hpp
/usr/local/include/opencv4/opencv2/gapi/opencv_includes.hpp
/usr/local/include/opencv4/opencv2/opencv_modules.hpp
Looking for cv2 or *cv2* yielded nothing except what was already listed above. The date/time of the files conform to the time I ran the install script.
Next I tried opencv-lite according to instructions from the same source. Same result: succesful installation, traces of newly put opencv files but import cv2 still fails.
To complicate matters I use anaconda environments. I got two: base and rpi. I installed with rpi activated. In both no trace of opencv or cv2 and in both cases import fails. Some information where the system fetches python:
$ which python
/home/arnold/bin/anaconda/envs/rpi/bin/python
(rpi) arnold#bottie:~/bin/opencv/opencv/build
There is python in /bin/python and /usr/bin/python I found out with vscode. I tried both and both failed.
My questions:
did installation of opencv really succeed?
if so, is it possible to 'connect' the installation to a running version of python, preferably a conda environment?
if not, what is the best way to proceed?

I try this links. install OpenCV 4 for RPI 4 It worked for me using RPi 4B/8GB 64-bit.
Do update first
Install OpenCV
Check getBuildInformation()
After that if not getting . Then install sudo apt
pyhton3-opencv-contrib
No needed to do cmake. And you ready to go.

Related

Anaconda Jupyter Notebook Opencv not working

Ok so to preface this, I am very new to jupyter notebook and anaconda. Anyways I need to download opencv to use in my notebook but every time I download I keep getting a NameError saying that ‘cv2’ is not defined.
I have uninstalled and installed opencv many times and in many different ways and I keep getting the same error. I saw on another post that open cv is not in my python path or something like that…
How do I fix this issue and put open cv in the path? (I use Mac btw) Please help :( Thank you!
Try the following:
Install OpenCV using Anaconda Navigator or via terminal by running:
conda install -c conda-forge opencv
Now you should check if its installed by running this in terminal: conda list
Import OpenCV in Jupyter Notebook: In your Jupyter Notebook, run import cv2 and see if it works.
If the above steps are not working, you should add OpenCV to your Python PATH by writing the following code to your Jupyter NB:
import sys
sys.path.append('/anaconda3/lib/python3.7/site-packages')
This should work.

How to install opencv on raspberrypi 4 with python3.7

everyone,
The default version of python on the Raspberry Pi 4 is 3.9. I need python 3.7. I successfully install python 3.7.4 and set it as default by adding the line alias python3='python3.7' to the bashcr file. Then I install opencv using pip3. I got: from .cv2 import *
ImportError: libImath-2_2.so.23: cannot open a shared object file: No such file or directory
I also installed it from the source and got the same result.
I investigated and found out that I need to install libilmbase12, but I got the following error message.
E: The package libilmbase12 could not be found
I appreciate any help.
I found a way. I change raspbian from bullseye to buster. Everything works fine. The problem was the compatibility of python and opencv version
You install OpenCV from bash :
sudo apt install python3-opencv

conda install opencv ImportError: the specified module could not be found

I installed opencv using the conda command:
conda install -c conda-forge opencv
The installation was successful without errors. Typing conda list also indicates opencv installed. But import cv2 gives the error: DLL load failed: The specified module could not be found.
I note the opencv does not show up in the Lib/site-packages folder, but occurs in the pkgs folder, that is, C:\\Anaconda\\Anaconda3.7\\pkgs\\opencv-4.1.1-py37h6afde12_1. The site-packages folder has a file cv2.cp37-win_amd64.pyd;
What is problem with the import cv2 error? Was the conda-based opencv installation really successful? My python version is python3.7.1.
A similar problem has been reported here DLL load failed error when importing cv2
Try to install with pip. 'pip install opencv-python'
Did you install the contribution packages of opencv?

cuda torch integration - CudaTensor class not found

Probably, I'm not sufficiently familiar with the dependencies stack here, but I've installed a Deep Learning project that uses Torch and CUDA: https://github.com/donglixp/lang2logic.
Running the project (e.g. by issuing: ./pretrain.sh seq2seq jobqueries lstm), I get this error:
THCudaCheck FAIL file=/tmp/luarocks_cutorch-scm-1-1028/cutorch/lib/THC/THCGeneral.c line=66 error=30 : unknown error
package cunn not found!
package cutorch not found!
If cutorch and cunn are installed, your CUDA toolkit may be improperly configured.
Check your CUDA toolkit installation, rebuild cutorch and cunn, and try again.
Falling back on CPU mode
~/torch/install/share/lua/5.1/torch/File.lua:343: unknown Torch class <torch.CudaTensor>
The last error by the way, is issued from this self-explanatory piece of lua code, which checks for the availability of the CudaTensor class:
if not torch.factory(className) then
error(string.format('unknown Torch class <%s>', tostring(className)))
end
After getting this error, I also installed Lua's cutorch and cunn through the following commands, which seemed to have finished well.
luarocks install cutorch
luarocks install cunn
But I still get the very same error.
The only installation quirk I've noticed had been that luarocks install class seemed to do nothing, and I'm not running on Scientific Linux as the original author, but rather on Ubuntu 16.04.
I had installed CUDA itself through: sudo apt-get install nvidia-cuda-toolkit
How would you address this integration error?
Thanks!
I would have preferred leaving only a comment, but I do not have enough reputation for that yet so here goes.
It seems like you have installation issues. The most obvious thing to try would be to uninstall torch entirely via rm -rf ~/torch and reinstall it following your link's instructions (replacing ClassNLLCriterion.cu file with theirs). Usually, following the instruction here should install cutorch and cunn for you but you can always install them via luarocks as you mentioned. This is also why luarocks install class didn't do anything because it was already installed.
In answer to your comment, torch.CudaTensor as the name suggests is a torch class defined in cutorch. It acts just like any other Tensor class from the torch library but it lives on GPU.
More information on how you installed torch could help.
You also of course need a CUDA compatible device in order to use cutorch.

Kivy Garden fails with error

I have downloaded the prepackaged Kivy zip file onto a Windows 8.1 machine and installed Kivy-Garden using pip (after running kivy.bat). However, I have been unable to successfully use Kivy-Garden. I have attempted the following commands:
garden install graph
garden list
However, neither of them work. They both result in the following error:
Traceback (most recent call last):
File "c:\kivy\Python27\Scripts\garden", line 5, in <module>
pkg_resources.run_script('Kivy-Garden==0.1.1', 'garden')
File "C:\Python27\lib\site-packages\pkg_resources.py", line 483, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "C:\Python27\lib\site-packages\pkg_resources.py", line 1335, in run_script
raise ResolutionError("No script named %r" % script_name)
pkg_resources.ResolutionError: No script named 'garden'
Does this indicate a bad installation? How might I fix it?
Kivy for windows comes in a bundle with all the prerequisites to run, since some are hard to install in windows, so it's not using you installed python.
You should go to your kivy installation folder, inside you'll find the python folder, inside is the python descriptor used for kivy, you can run that python exe, or use pip or easy install (i don't remember if both), like an extra advice i could saw to use PyCharm to program, it's easy to install the python modules and code, i have it myself with SqlAlchemy instaled from the PyCharm Gui (previous config here Configure PyCharm and Kivy).
In the other hand you can configure kivy to run with your installed python (instructions here Kivy with an installed Python in Windows) i haven't tried myself since i use the same python included in kivy with no problems
I never figured out why pip wouldn't work, but I found a workaround.
Just download the package from pypi and run setup.py:
https://pypi.python.org/pypi/kivy-garden/0.1.1
The only workaround I've found that works is to manually install flowers into the kivy garden folder. Ceremcem has a great explanation of it here: filebrowser error in windows for kivy
Also I found I had to explicitly use pip2 for pip to work.

Resources