In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to talk to you about how to install opencv3.1 in raspberry pie 3b pyhon3.5. Many people may not know much about it. In order to make you understand better, the editor summarized the following contents. I hope you can get something from this article.
Reminder: make sure there is enough space first, and it is best to reserve the remaining space of 3Jing 4G.
Install dependency packages
The old step is to update the existing software package before installing the software:
Sudo apt-get update sudo apt-get upgrade # update the system, choose carefully
Note: you have to do apt-get update, but do not run apt-get upgrade unless you install it unsuccessfully, it may take a long time.
Install cmake:
Sudo apt-get install build-essential cmake pkg-config
Install packages in various image formats:
Sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
Install the video Icano package:
Sudo apt-get install libavcodec-dev libavformat-dev libswcale-dev libv4l-dev sudo apt-get install libxvidcore-dev libx264-dev
Install the GTK development library:
Sudo apt-get install libgtk2.0-dev
Install a few more dependencies to further optimize OpenCV:
Sudo apt-get install libatlas-base-dev gfortran
Confirm the installation of the python development environment (you don't have to do it):
Sudo apt-get install python2.7-dev python3-dev downloads OpenCV source code
I created a new opencv folder under ~ to store all kinds of things to be used next. Then switch to this directory.
Cd~ mkdir opencvcd opencv
Download the opencv 3.1 source code
Wget-O opencv.zip https://github.com/Itseez/opencv/archive/3.1.0.zip unzip opencv.zip
After the full installation, we also need to crawl OpenCV's contrib repository:
Wget-O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.1.0.zip unzip opencv_contrib.zip
Warning: the versions of opencv and opencv_contrib must be the same!
Note: git is used to download the source code here in many articles, but the opencv is relatively large, so it will take a long time to download the source code. Download the time controllable point of the compressed package by wget. The most time-saving way: download these two zip files with Thunderbolt under windows, and then decompress them under raspberry pie, which takes the least time.
Install python's virtual environment management software
That is: virtualenv and virtualenvwrapper
I have already written an article, the specific installation process reference:
Https://my.oschina.net/u/2396236/blog/1632522
Create a new virtual environment
After the installation and configuration of virtualenv and virtualenvwrapper, create a new python3 virtual environment called opencv
Mkvirtualenv-p / usr/bin/python3 opencv
Confirm that you have entered the virtual environment. If you do not, you need to use workon to enter the virtual environment.
Workon opencv
After entering the virtual environment, the name of the virtual environment appears in parentheses on the left side of the command line
The next thing we do is in a virtual environment called opencv, which is created using python3.
Install numpy
Numpy is a dependent package for opencv and needs to be installed in a virtual environment first.
Pip install numpy compilation and installation of OpenCV
Then we use the CMake settings to build:
Cd ~ / opencv/opencv-3.1.0/ mkdir build cd build cmake-D CMAKE_BUILD_TYPE=RELEASE\-D CMAKE_INSTALL_PREFIX=/usr/local\-D INSTALL_PYTHON_EXAMPLES=ON\-D OPENCV_EXTRA_MODULES_PATH=~/opencv/opencv_contrib-3.1.0/modules\-D BUILD_EXAMPLES=ON.
Note: you need to pay special attention to the parameter OPENCV_EXTRA_MODULES_PATH here. Specify your own opencv contrib directory address.
The next step is to compile.
Make
Most articles will recommend using
Make-J4
To call 4 cores to compile, the time is greatly shortened. But it is said that this is not too stable and error-prone. I directly used the make command single-core compilation, took almost 4 hours, it is said to use 4 cores, almost an hour and a half. You might as well give it a try.
In the process of make, you are likely to report the following mistakes, making people gasp for breath:
Generating precomp.hpp.gch/opencv_core_Release.gch 2 In file included from / usr/include/c++/6/bits/stl_algo.h:59:0, 3 from / usr/include/c++/6/algorithm:62, 4 from / opt/opencv/opencv-3.1.0/modules/core/include/opencv2/core/base.hpp:53 5 from / opt/opencv/opencv-3.1.0/modules/core/include/opencv2/core.hpp:54, 6 from / opt/opencv/opencv-3.1.0/modules/core/include/opencv2/core/utility.hpp:52 7 from / opt/opencv/build/modules/core/precomp.hpp:49: 8 / usr/include/c++/6/cstdlib:75:25: fatal error: stdlib.h: no file or directory 9 # include_next
Reference https://www.cnblogs.com/liutianchen/p/6089878.html
It probably means that the include_next in the / usr/include/c++/6/cstdlib file doesn't work here, so you have to honestly replace it with include. So we need to modify the source code of the error part to change include_next to include. In the process of make, there are probably two things that need to be modified here. Just do it.
After the lengthy compilation is 100% complete, it is finally ready to install
Install opencv
Sudo make installsudo ldconfig
Reference class libraries for virtual environments
If it is a python3+ virtual environment, link the compiled so file to the virtual environment.
Cd ~ / .virtualenvs/opencv/lib/python3.5/site-packages/ln-s / usr/local/lib/python3.5/dist-packages/cv2.cpython-35m-arm-linux-gnueabihf.so cv2.so
Note that there is another pit here:
All articles indicate that the compiled so file is located in / usr/local/lib/python3.5/site-packages and the file name is cv2.so.
I have tried it twice, and the original file name of cv2.so should be cv2.cpython-35m-arm-linux-gnueabihf.so. The directory name generated by the two times is actually different:
The first time: there is no site-packages directory under / usr/local/lib/python3.5/, there is only a dist-packages directory, and there is no cv2.so file under dist-packages, but there is a cv2.cpython-35m-arm-linux-gnueabihf.so file, which is the compiled file after opencv.
The second time: site-packages exists, and the cv2.cpython-35m-arm-linux-gnueabihf.so file is in the site-packages directory. The reason is unknown. I feel so panicked.
Install successfully, check version number python > > import cv2 > print (cv2.__version__) 3.1.0
If the version number is displayed successfully, the opencv installation is successful.
Delete downloaded and unzipped files and folders, which take up a lot of space:
Opencv_contrib.zip opencv.zip opencv_contrib-3.0.0/ opencv-3.0.0/
After reading the above, do you have any further understanding of how to install opencv3.1 in raspberry pie 3b pyhon3.5? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.