I have been trying to use the cv2 library in python (in IDLE on raspberry pi 3) but I can't manage to import it successfully.
when I type import cv2, I get this:
Traceback (most recent call last):
File "/home/pi/Desktop/python/test.py", line 2, in <module>
from .cv2 import *
ImportError: libjasper .so.1: cannot open shared object file: No such file or directory
I have used the terminal to update, upgrade, and install opencv along with pretty much every other thing I could find relating to opencv or lib. I currently can import cv2 in the terminal but not in IDLE. What do I need to do to be able to import the cv2 library? Thanks in advance.
Recommended way of installing opencv on linux as given by opencv docs "https://docs.opencv.org/4.2.0/d2/de6/tutorial_py_setup_in_ubuntu.html" for python3 is:
sudo apt install python3-opencv
for python2:
sudo apt install python-opencv
On Raspberry pi you may occasionally need to run:
sudo apt update --fix-missing
It will auto-install all the dependencies.
As discussed here, below installations seemed to resolve the issue. It worked for me.
pip3 install opencv-python
sudo apt-get install libatlas-base-dev
sudo apt-get install libjasper-dev
sudo apt-get install libqtgui4
sudo apt-get install python3-pyqt5
sudo apt-get install libqt4-test
Or
the newer OpenCV version handles other installations themselves.
pip install opencv-python==4.1.2.30
Follow the commands for opencv and face recognition : (it worked for me)
-> sudo apt update
-> sudo apt upgrade
-> sudo apt-get install python3-pip
pi#raspberrypi:~ $ python3 -V
Python 3.5.3
pi#raspberrypi:~ $ python2 -V
Python 2.7.13
-> pip3 install numpy
-> pip3 install pillow
-> pip3 install dlib
-> sudo apt-get install cmake
-> pip3 install face_recognition
-> sudo apt-get install python-opencv
-> sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev
-> sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
-> sudo apt-get install libatlas-base-dev
-> sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev -y
-> sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev -y
-> sudo apt-get install libgtk2.0-dev libgtk-3-dev -y
-> sudo pip3 install opencv-python
-> sudo apt-get install libavformat-dev libswscale-dev openexr libopenexr-dev
-> sudo apt-get install libqt4-dev
-> sudo apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
pi#raspberrypi:~ $ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> import dlib
>>> import face_recognition
>>>
Depends on the system.
for PI will take : 2 to 3 hr. (total time)
thanks :)
Related
I'm trying to build a docker image from the docker file:
FROM ubuntu:18.04
# Install tzdata
RUN apt-get update &&\
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install tzdata
# Install Python, Bowtie2 and Java
RUN apt-get install -y python3.10 python3-pip \
openjdk-8-jdk \
bowtie2 \
wget
RUN apt-get install --yes --no-install-recommends \
zlib1g-dev \
libbz2-dev \
liblzma-dev
# Install RSeQC
RUN apt-get install -y python-pip &&\
pip install RSeQC
# Install biopython=1.80
RUN pip install biopython
# Install Atria
RUN wget https://github.com/cihga39871/Atria/releases/download/v3.1.2/atria-3.1.2-linux.tar.gz && \
tar -zxf atria-3.1.2-linux.tar.gz && \
mv atria-3.1.2/bin/atria /usr/local/bin/atria && \
chmod +x /usr/local/bin/atria
#Atria dependencies
RUN apt-get install pigz pbzip2
# Install findtail
RUN wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/findtail/findtail_v1.01 && \
mv findtail_v1.01 /usr/local/bin/findtail_v1.01 && \
chmod +x /usr/local/bin/findtail_v1.01
# Cleanup
RUN apt clean
But while on Step 6/10 : RUN pip install biopython it gives the error :
---> Running in 062f9c27cc15
Collecting biopython
Downloading https://files.pythonhosted.org/packages/3d/2f/d9df24de05d651c5e686ee8fea3afe3985c03ef9ca02f4cc1e7ea10aa31e/biopython-1.77.tar.gz (16.8MB)
Complete output from command python setup.py egg_info:
Biopython requires Python 3.6 or later. Python 2.7 detected.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-mgUybW/biopython/
The command '/bin/sh -c pip install biopython' returned a non-zero code: 1
I've check the python version on my pc. I'm running python version 3.10.6 on my OS and in the dockerfile I'm trying to incorporate python 3.10 version. Where is this error coming from?
The default Python version in Ubuntu 18.04 is 3.6. However, on line 19, you are installing the python-pip package, i.e. the Python 2 version of the pip package manager, which in turn depends on the Python 2.7 package and thus will install Python 2.7.
Which means from this point on, you have two Python versions installed on the system, with two Python VM executables, python and python3, and two pip executables, pip and pip3.
It is not clear why you install Python 2.7 and python-pip on line 19 when you have already installed Python 3.10 and python3-pip on line 8. Nor is it clear why you install BioPython using pip, i.e. the Python 2 version instead of pip3, i.e. the Python 3 version.
I would not install Python 2 at all, since it has not been maintained or supported for several years. I would also not use Ubuntu 18.04, which will be out of standard support in 4 months, unless you are paying for the Extended Security Maintenance. The latest Long-Term Support version of Ubuntu is 22.04.1 which has standard support until April 2027 and extended support until April 2032.
I was trying many ways in order to install Erlang 17.3 on Ubuntu 18. So far I came up with this solution you can read below:
For installation Erlang 17.3 on Ubuntu 18 you should do the following things:
Enter in the console next command:
Download the tar file:
wget http://erlang.org/download/otp_src_17.3.tar.gz
Extract the tar file in directory where you download the otp_src_17.3.tar.gz:
cd '/home/yaroslav/otp_src_17.3'
tar -zxf otp_src_17.3.tar.gz
set export ERL_TOP your 'pwd' path:
export ERL_TOP=pwd
Basic dependencies:
sudo apt-get install autoconf libncurses-dev build-essential
Other applications dependencies
sudo apt-get install m4
sudo apt-get install unixodbc-dev
sudo apt-get install libssl-dev
sudo apt-get -y install libssh-dev
sudo apt-get install libwxgtk3.0-dev libglu-dev
sudo apt-get install fop xsltproc
sudo apt-get install g++
sudo apt-get install default-jdk
sudo apt-get install xsltproc fop
Or all dependencies in one line:
apt-get -y install build-essential autoconf m4 libncurses5-dev libwxgtk3.0-dev libgl1-mesa-
dev libglu1-mesa-dev libpng-dev libssh-dev unixodbc-dev xsltproc fop g++ default-jdk
install openssl version 1.0.2 for Ubuntu 18 (different version SSL is not compatible):
curl https://www.openssl.org/source/openssl-1.0.2l.tar.gz | tar xz && cd openssl-1.0.2l &&
sudo ./config && sudo make && sudo make install
Configure and build:
./configure --with-ssl='/home/yaroslav/otp_src_17.3/openssl-1.0.2l'
sudo make
sudo make install
For installing older versions of Erlang and working with several at the same time I would recommend using kerl
If you need more fancy features you could also head for asdf which has a Erlang plugin (which runs kerl under the hood)
I am trying to enter sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev to install OpenCV on ubuntu but I keep getting the errors:
Unable to locate package libswcale-dev
and
Unable to locate package libv4l-dev
Try sudo apt-get update
If no result show your /etc/apt/sources.list, please.
I am trying to compile and build OpenCV 2.4.13.6 in a local folder on Raspbian.
I did
cmake -D CMAKE_INSTALL_PREFIX=./ - DCMAKE_BUILD_TYPE=Debug ../
make -j4
make install
However the modules folders in the build directory were not present (for example the file core_c.h of the core module could not be found). So I tried to rerun make install but it was failing. I went back another step and rerun cmake ... I noticed it gives me warnings about many packages that cannot be found such as gtk+-2.0 gthread g-streamer and much more.
Should I install those packages to build opencv manually?
Yes, you need to install dependencies manually before compiling OpenCV, although you asked for OpenCV 2, an example list of dependencies for Raspbian can be found here. Directly quoting from given link:
Step 1:
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo rpi-update (can be skipped, but recommended) (don't do it if you will use the RPI cam as recommended by official RPI Website)
$ sudo reboot now
Step 2:
$ sudo apt-get install build-essential cmake pkg-config
Step 3:
$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
Step 4:
$ sudo apt-get install libgtk2.0-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libv4l-0 libv4l-dev
Step 5:
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev
Step 6:
$ sudo apt-get install libatlas-base-dev gfortran
$ sudo apt-get install python-numpy python-scipy python-matplotlib
$ sudo apt-get install default-jdk ant
$ sudo apt-get install libgtkglext1-dev
$ sudo apt-get install v4l-utils
Step 7:
install pip
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py
Step 8:
$ sudo apt-get install python2.7-dev
Step 9:
$ sudo pip install numpy
I have downloaded 20170817-tinker-board-linaro-stretch-alip-v2.0.1.img for Tinker Board. I am trying to install OpenCV 3.0.0. I have followed the instructions given here : http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/.
I was not able to install libjasper-dev. Hence, instead of libpng12-dev, I have installed libpng.
I am trying to compile OpenCV on Tinker Board since yesterday morning. But have been getting following errors during building process:
/usr/include/c++/6/cmath:106:11: error: ::acos has not been declared
Followed by all the math formula triggers similar errors.
Which Debian version is stable for OpenCV? Should I install a lower version of OpenCV? Can someone help?
I successfully managed to install OpenCV on a TinkerBoard. The following were the steps:
Format a 16 GB memory card to FAT32
Download debian image 20170817-tinker-board-linaro-stretch-alip-v2.0.1.img for tinker board from here.
Copy the img file on to the memory card
sudo dd if=/path/to/your/imgfile of=/path/to/your/memorycard bs=4M
a lot of help on this is already available in SO.
Before powering on ensure that you connect your tinker board to the internet through a lan cable.
Once powered on reset the system time with sudo dpkg-reconfigure tzdata. Debian image for tinker board already has ntp installed. Wait a couple of minutes for the tinker board to adjust the board time from the network.
To install opencv and its dependant library, I have taken the instructions given here ....though I had to make some custom library installations but it was very helpful. Please note, my purpose of using Opencv on Tinker Board is to process live video's and hence my focus was more towards installing appropriate video codecs.
The following were the steps:
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y dist-upgrade
sudo apt-get -y autoremove
You may face the following warning messages during installation of perl applications:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.utf8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Though this doesn't impact your installation of OpenCV, after spending 3 days in trying to compile Opencv on tinker board I do not want to leave anything for a chance.
Use the following to suppress these warning messages:
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
dpkg-reconfigure locales
Thanks to this post.
# INSTALL THE DEPENDENCIES
# Build tools:
sudo apt-get install -y build-essential cmake
# GUI (if you want to use GTK instead of Qt, replace 'qt5-default' with 'libgtkglext1-dev' and remove '-DWITH_QT=ON' option in CMake): I just went with qt5 itself.
sudo apt-get install -y qt5-default libvtk6-dev
# Media I/O:
sudo apt-get install -y zlib1g-dev libjpeg-dev libwebp-dev libpng-dev libtiff5-dev libopenexr-dev libgdal-dev
Pls note libjasper-dev is unavailable for this version of Debian and hence I have removed from the above Media I/O list.
# Video I/O:
sudo apt-get install -y libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev yasm libopencore-amrnb-dev libopencore-amrwb-dev libv4l-dev libxine2-dev
sudo apt-get install -y gstreamer1.0-plugins-*
sudo apt-get install libxine-dev
# Parallelism and linear algebra libraries:
sudo apt-get install -y libtbb-dev libeigen3-dev
# Python:
sudo apt-get install -y python-dev python-tk python-numpy python3-dev python3-tk python3-numpy
sudo apt-get install python-pip
# Java:
sudo apt-get install -y ant default-jdk
# Documentation:
sudo apt-get install -y doxygen
Get OpenCV. I decided to go with version 3.0.0 as my development was in this version. You may choose a different version.
sudo apt-get install -y unzip wget
wget https://github.com/opencv/opencv/archive/3.0.0.zip
unzip 3.0.0.zip
rm 3.0.0.zip
Build OpenCV.
mv opencv-3.0.0 OpenCV
cd OpenCV
mkdir build
cd build
cmake -DWITH_QT=ON -DWITH_OPENGL=ON -DFORCE_VTK=ON -DWITH_TBB=ON -DWITH_GDAL=ON -DWITH_FFMPEG=0 -DWITH_XINE=ON -DBUILD_EXAMPLES=ON -DENABLE_PRECOMPILED_HEADERS=OFF ..
A change here from the original script - is the addition of -DWITH_FFMPEG=0, as FFMPEG library was missing and I was not in a frame of mind to install the same. You may want to do so.
make
Though TinkerBoard supports make -j4 i chose to go slow with make. The compile with make took almost 2.5 hours with lot of seemingly indentation errors in c++ codes but finally the compile gets over.
sudo make install
sudo ldconfig
$ python
>>> import cv2
>>> cv2.__version__
'3.0.0'
After few days finally I got good setup. My post improves the previous answer.
Steps is similar like it was before me, but I changed few strings, because I had different errors.
In my case for new Asus Tinker Board I installed:
20170928-tinker-board-linaro-stretch-alip-v2.0.3
opencv-3.3.0 with opencv_contrib-3.3.0.
First start of tinker board.
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y dist-upgrade
It necessary to remove default (old) OpenCV:
sudo apt-get remove libopencv*
sudo apt-get -y autoremove
# INSTALL THE DEPENDENCIES
# Build tools:
sudo apt-get install -y build-essential cmake
# GUI (I had errors with Qt, so I did next)
sudo apt-get install -y libgtkglext1-dev libvtk6-dev
# Media I/O:
sudo apt-get install -y zlib1g-dev libjpeg-dev libwebp-dev libpng-dev libtiff5-dev libopenexr-dev libgdal-dev
# Video I/O:
sudo apt-get install -y libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev yasm libopencore-amrnb-dev libopencore-amrwb-dev libv4l-dev libxine2-dev libxine-dev
sudo apt-get install -y gstreamer1.0-plugins-*
# Parallelism and linear algebra libraries:
sudo apt-get install -y libtbb-dev libeigen3-dev
# Python:
sudo apt-get install -y python-dev python-tk python-numpy python3-dev python3-tk python3-numpy
sudo apt-get install python-pip
# Java:
sudo apt-get install -y ant default-jdk
# Documentation:
sudo apt-get install -y doxygen
Get OpenCV.
cd ~
wget -O opencv.zip https://github.com/opencv/opencv/archive/3.3.0.zip
unzip opencv.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/3.3.0.zip
unzip opencv_contrib.zip
Compile and Install OpenCV
cd ~/opencv-3.3.0/
mkdir build
cd build
cmake -DWITH_OPENGL=ON -DFORCE_VTK=ON -DWITH_TBB=ON -DWITH_GDAL=ON -DWITH_FFMPEG=0 -DWITH_XINE=ON -DBUILD_EXAMPLES=ON -DOPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.3.0/modules -DENABLE_PRECOMPILED_HEADERS=OFF ..
CMake should start to build your configuration, after a couple of minutes you should see:
-- Configuring done
-- Generating done
-- Build files have been written to: ./opencv-3.3.0/build
If you can't see Generating done then some issues have been occurred. Read error messages and the error log file to investigate.
I did without examples, but you can try. Qt I deleted.
make
Better without -j4.
sudo make install
sudo ldconfig
Test the installation
linaro#tinkerboard:~$ python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.3.0'
installing ffmpeg ( the previous answers skiped this )
sudo apt update && sudo apt install ffmpeg libav-tools x264 x265
I also recommend installing the additional packages and enabling neon and vfpv3 when compiling the opncv files. This should give significant improvement in performance:
https://www.pyimagesearch.com/2017/10/09/optimizing-opencv-on-the-raspberry-pi/
I came to this question late. I am adding this answer for the future reference of the people. Here is the official documentation of Tinkerboard.
https://tinkerboarding.co.uk/wiki/index.php/CSI-camera
I just changed the version to the latest version at this time (3.4.1):
#!/bin/bash
#Install
sudo apt-get update
sudo apt-get upgrade
#Install a few developer tools
sudo apt-get install -y build-essential git cmake pkg-config
#Install image I/O packages which allow us to load image file formats such as JPEG, PNG, TIFF, etc.
sudo apt-get install -y libjpeg-dev libtiff5-dev libpng-dev
#Install video I/O packages
sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
#Install the GTK development library
sudo apt-get install -y libgtk2.0-dev
#Various operations inside of OpenCV (such as matrix operations) can be optimized using added dependencies
sudo apt-get install -y libatlas-base-dev gfortran
#Install the Python 2.7 and Python 3 header files
sudo apt-get install -y python2.7-dev python3-dev python-opencv
wget https://github.com/opencv/opencv/archive/3.4.1.zip
unzip 3.4.1.zip
cd opencv-3.4.1
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D WITH_LIBV4L=ON -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make install
It took around 90 minutes to compile.