In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about how to install Python and OpenCV on raspberry pie 2ripple B+. Many people may not know much about it. In order to make you understand better, the editor summarized the following. I hope you can get something from this article.
Install Python and OpenCV on raspberry pie 2 or raspberry pie B+, mainly based on the GTK library, and install with Python2.7 and OpenCV 2.4.X.
My Raspberry Pi 2 just arrived in the mail yesterday, and this guy looks small and cute.
This little guy has a 4-core 900MHZ processor with 1 gigabyte of memory. You know, Raspberry Pi 2 is much faster than most computers in my high school computer lab.
In other words, since the release of Raspberry Pi 2, I have received a lot of requests for me to write a detailed description of installing OpenCV and Python on it.
So if you want to start running OpenCV and Python on Raspberry Pi, read on!
In the rest of the blog post, I will provide detailed installation instructions on Raspberry Pi 2 and Raspberry Pi B+.
I will also explain that each step of the installation takes time. Some of these steps require more processing time. For example, it takes about 2.8 hours to compile OpenCV in Raspberry Pi 2 and 9.5 hours on Raspberry Pi B+. So please arrange your installation accordingly.
Finally, a reminder that we will use Raspberry Pi in the PyImageSearch Gurus computer Vision course. Our project will include home monitoring applications, such as motion detection and personnel tracking in the room.
Here is a simple example of motion detection and tracking when I was walking around the apartment on the phone.
Install OpenCV and Python on the Raspberry Pi 2 Plus B+
It is assumed that you already have Raspberry Pi 2 Compact Bones and that they have been installed. If not, I suggest you buy one. They are both cheap and fun.
Personally, I'd rather spend a little more money on it from Canakit. Their logistics is fast and reliable, and their ready-to-go service is also very good.
All right, let's start the installation of OpenCV and Python.
Step 0:
Let's assume that you have turned on Raspberry Pi 2 gamble B+. Open the terminal, we first update and upgrade the installed package, and then update the Raspberry Pi firmware.
?
one
two
three
$sudo apt-get update
$sudo apt-get upgrade
$sudo rpi-update
Step 1:
Install the required installation tools and packages:
?
one
$sudo apt-get install build-essential cmake pkg-config
Both build-essential and pkg-config may already be installed. Just in case, let's type them into the apt-get command.
Time consuming:
Raspberry Pi bandwidth: less than 2 minutes
Raspberry Pi 2: less than 40 seconds
Step 2:
Install the necessary image Iamp O package so that you can read images in these formats such as JPEG,PNG,TIFF.
?
one
$sudo apt-get install libjpeg8-dev libtiff4-dev libjasper-dev libpng12-dev
Time consuming:
Raspberry Pi bells: less than 5 minutes
Raspberry Pi 2: less than 30 seconds
Step 3:
Install the GTK development library, which is used to build GUI. The highgui library in OpenCV also needs it to display images on the screen.
?
one
$sudo apt-get install libgtk2.0-dev
Time consuming:
Raspberry Pi financing: less than 10 minutes
Raspberry Pi 2: less than 3 minutes
Step 4:
Install the necessary video Iamp O packages, which are needed by OpenCV to read the video files.
?
one
$sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
Time consuming:
Raspberry Pi bandwidth: less than 5 minutes
Raspberry Pi 2: less than 30 seconds
Step 5:
Install the libraries required for OpenCV optimization operations.
?
one
$sudo apt-get install libatlas-base-dev gfortran
Time consuming:
Raspberry Pi bandwidth: less than 2 minutes
Raspberry Pi 2: less than 30 seconds
Step 6:
Install pip:
?
one
two
$wget https://bootstrap.pypa.io/get-pip.py
$sudo python get-pip.py
Time consuming:
Raspberry Pi bandwidth: less than 2 minutes
Raspberry Pi 2: less than 30 seconds
Step 7:
Install virtualenv and virtualenvwrapper
?
one
$sudo pip install virtualenv virtualenvwrapper
Then, update the ~ / .profile file as follows:
?
one
two
Export WORKON_HOME=$HOME/.virtualenvs
Source / usr/local/bin/virtualenvwrapper.sh
Reload the .profile file:
?
one
$source ~ / .profile
Create your computer vision virtual environment
?
one
$mkvirtualenv cv
Time consuming:
Raspberry Pi bandwidth: less than 2 minutes
Raspberry Pi 2: less than 2 minutes
Step 8:
Now let's install the Python 2.7 development tools:
?
one
$sudo apt-get install python2.7-dev
Note: we will use Python2.7. Because OpenCV 2.4.X does not support Python 3, it is not clear when the python interface of OpenCV 3.0 will be perfect. So I suggest using OpenCV2.4.X now.
We also need to install NumPy because the Python interface of OpenCV represents images through a multi-dimensional array of Numpy.
?
one
$pip install numpy
Time consuming:
Raspberry Pi bandwidth: less than 45 minutes
Raspberry Pi 2: less than 15 minutes
Step 9:
Download and extract OpenCV:
?
one
two
three
$wget-O opencv-2.4.10.zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.10/opencv-2.4.10.zip/download
$unzip opencv-2.4.10.zip
$cd opencv-2.4.10
Installation:
?
one
two
three
$mkdir build
$cd build
$cmake-D CMAKE_BUILD_TYPE=RELEASE-D CMAKE_INSTALL_PREFIX=/usr/local-D BUILD_NEW_PYTHON_SUPPORT=ON-D INSTALL_C_EXAMPLES=ON-D INSTALL_PYTHON_EXAMPLES=ON-D BUILD_EXAMPLES=ON..
Time consuming:
Raspberry Pi bandwidth: less than 3 minutes
Raspberry Pi 2: less than 1.5min
Compile OpenCV:
?
one
$make
Important: make sure that you are in the cv virtual environment, and the OpenCV is also compiled according to the Python and NumPy in that environment. Otherwise, OpenCV will be compiled with Python and NumPy in the system, causing all kinds of problems.
Time consuming:
Raspberry Pi hours: less than 9.5hrs
Raspberry Pi 2: less than 2.8h
Finally, we install OpenCV:
?
one
two
$sudo make install
$sudo ldconfig
Time consuming:
Raspberry Pi bandwidth: less than 3 minutes
Raspberry Pi 2: less than 1 minute
Step 10:
By the time you get to this point, OpenCV should already be installed in / usr/local/lib/python2.7/site-packages.
But in order to use OpenCV in a cv virtual environment, we first need to comply with the link to our site-packages directory:
?
one
two
three
$cd ~ / .virtualenvs/cv/lib/python2.7/site-packages/
$ln-s / usr/local/lib/python2.7/site-packages/cv2.so cv2.so
$ln-s / usr/local/lib/python2.7/site-packages/cv.py cv.py
Step 11:
Finally, let's test the installation of OpenCV and Python:
?
one
two
three
four
five
$workon cv
$python
> import cv2
> cv2.__version__
'2.4.10'
OpenCV and Python have been successfully installed on your Raspberry Pi.
This is a running example on my Raspberry Pi where I log in to Raspberry Pi with ssh and then read and display an image.
With the upgrade of Raspberry Pi, the installation instructions may change. If you encounter some extreme situations or changes in installation instructions, please feel free to contact me. Of course, I can't guarantee that every email will be answered, so it's best to summarize the ways to install OpenCV and Python on Raspberry Pi into a list.
After reading the above, do you have any further understanding of how to install Python and OpenCV on raspberry pie 2gamble B+? 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.