My Raspberry Pi 2 just arrived in the mail yesterday, and man is this berry sweet.
This tiny little PC packs a real punch with a 900mhz quadcore processor and 1gb of RAM. To give some perspective, the Raspberry Pi 2 is faster than the majority of the desktops in my high school computer lab.
Anyway, since the announcement of the Raspberry Pi 2 I’ve been getting a lot of requests to provide detailed installation instructions for OpenCV and Python.
So if you’re looking to get OpenCV and Python up-and-running on your Raspberry Pi, look no further!
In the rest of this blog post I provide detailed installation instructions for both the Raspberry Pi 2 and the Raspberry Pi B+.
I’ve also provided install timings for each step. Some of these steps require a lot of processing time. For example, compiling the OpenCV library on a Raspberry Pi 2 takes approximately 2.8 hours versus the 9.5 hours on the Raspberry Pi B+, so please plan your install accordingly.
Finally, it’s worth mentioning that we’ll be utilizing the Raspberry Pi inside the PyImageSearch Gurus computer vision course. Our projects will include home surveillance applications such as detecting motion and tracking people in a room.
Here’s a quick example of detecting motion and tracking myself as I walk around my apartment on the phone:
Install OpenCV and Python on your Raspberry Pi 2 and B+
UPDATE: The tutorial you are reading now covers how to install OpenCV 3 with Python 2.7 and Python 3 bindings on Raspbian Wheezy. Raspbian Jessie has now replaced Raspbian Wheezy and if this is the first time you are reading this tutorial then in all likelihood you are using Raspbian Jessie. Please use the following updated guides to help you install OpenCV + Python on your Raspberry Pi.
- How to install OpenCV 3.0 on Raspbian Jessie.
- Install guide: Raspberry Pi 3 + Raspbian Jessie + OpenCV 3.
I’m going to assume that you have either your Raspberry Pi 2 or Raspberry Pi B+ unboxed and setup. If you don’t have a Raspberry Pi yet, I definitely suggest picking one up. They are super cheap and a lot of fun to play with.
Personally, I prefer to spend a little extra money and purchase from Canakit — their shipping is fast and reliable, plus their complete ready-to-go bundles are really nice.
Anyway, let’s get into the OpenCV and Python install instructions.
Step 0:
Again, I’m going to assume that you have just unboxed your Raspberry Pi 2/B+. Open up a terminal and we’ll start by updating and upgrading installed packages, followed by updating the Raspberry Pi firmware:
$ sudo apt-get update $ sudo apt-get upgrade $ sudo rpi-update
Step 1:
Install the required developer tools and packages:
$ sudo apt-get install build-essential cmake pkg-config
Both build-essential
and pkg-config
are likely already installed, but just in case they are not, be sure to include them in your apt-get
command.
Timings:
Raspberry Pi B+: < 2 minutes
Raspberry Pi 2: < 40 seconds
Step 2:
Install the necessary image I/O packages. These packages allow you to load various image file formats such as JPEG, PNG, TIFF, etc.
$ sudo apt-get install libjpeg8-dev libtiff4-dev libjasper-dev libpng12-dev
Timings:
Raspberry Pi B+: < 5 minutes
Raspberry Pi 2: < 30 seconds
Step 3:
Install the GTK development library. This library is used to build Graphical User Interfaces (GUIs) and is required for the highgui
library of OpenCV which allows you to view images on your screen:
$ sudo apt-get install libgtk2.0-dev
Timings:
Raspberry Pi B+: < 10 minutes
Raspberry Pi 2: < 3 minutes
Step 4:
Install the necessary video I/O packages. These packages are used to load video files using OpenCV:
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
Timings:
Raspberry Pi B+: < 5 minutes
Raspberry Pi 2: < 30 seconds
Step 5:
Install libraries that are used to optimize various operations within OpenCV:
$ sudo apt-get install libatlas-base-dev gfortran
Timings:
Raspberry Pi B+: < 2 minutes
Raspberry Pi 2: < 30 seconds
Step 6:
Install pip
:
$ wget https://bootstrap.pypa.io/get-pip.py $ sudo python get-pip.py
Timings:
Raspberry Pi B+: < 2 minutes
Raspberry Pi 2: < 30 seconds
Step 7:
Install virtualenv
and virtualenvwrapper
:
$ sudo pip install virtualenv virtualenvwrapper $ sudo rm -rf ~/.cache/pip
Then, update your ~/.profile
file to include the following lines:
# virtualenv and virtualenvwrapper export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh
Reload your .profile
file:
$ source ~/.profile
Create your computer vision virtual environment:
$ mkvirtualenv cv
Timings:
Raspberry Pi B+: < 2 minutes
Raspberry Pi 2: < 2 minutes
Step 8:
Now we can install the Python 2.7 development tools:
$ sudo apt-get install python2.7-dev
Note: Yes, we are going to use Python 2.7. OpenCV 2.4.X does not yet support Python 3 and OpenCV 3.0 is still in beta. It’s also unclear when the Python bindings for OpenCV 3.0 will be complete so I advise to stick with OpenCV 2.4.X for the time being.
We also need to install NumPy since the OpenCV Python bindings represent images as multi-dimensional NumPy arrays:
$ pip install numpy
Timings:
Raspberry Pi B+: < 45 minutes
Raspberry Pi 2: < 15 minutes
Step 9:
Download OpenCV and unpack it:
$ 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
Setup the build:
$ 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 ..
Timings:
Raspberry Pi B+: < 3 minutes
Raspberry Pi 2: < 1.5 minutes
Compile OpenCV:
$ make
Important: Make sure you’re in the cv
virtual environment so OpenCV is compiled against the virtual environment Python and NumPy. Otherwise, OpenCV will be compiled against the system Python and NumPy which can lead to problems down the line.
Timings:
Raspberry Pi B+: < 9.5 hours
Raspberry Pi 2: < 2.8 hours
Finally, we can install OpenCV:
$ sudo make install $ sudo ldconfig
Timings:
Raspberry Pi B+: < 3 minutes
Raspberry Pi 2: < 1 minute
Step 10:
If you’ve gotten this far in the guide, OpenCV should now be installed in /usr/local/lib/python2.7/site-packages
But in order to utilize OpenCV within our cv
virtual environment, we first need to sym-link OpenCV into our site-packages
directory:
$ 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, we can give our OpenCV and Python installation a test drive:
$ workon cv $ python >>> import cv2 >>> cv2.__version__ '2.4.10'
OpenCV and Python is now successfully installed on your Raspberry Pi!
Here is an example of me ssh’ing (with X11 forwarding) into my Raspberry Pi, followed by loading and displaying an image:
What's next? I recommend PyImageSearch University.
30+ total classes • 39h 44m video • Last updated: 12/2021
★★★★★ 4.84 (128 Ratings) • 3,000+ Students Enrolled
I strongly believe that if you had the right teacher you could master computer vision and deep learning.
Do you think learning computer vision and deep learning has to be time-consuming, overwhelming, and complicated? Or has to involve complex mathematics and equations? Or requires a degree in computer science?
That’s not the case.
All you need to master computer vision and deep learning is for someone to explain things to you in simple, intuitive terms. And that’s exactly what I do. My mission is to change education and how complex Artificial Intelligence topics are taught.
If you're serious about learning computer vision, your next stop should be PyImageSearch University, the most comprehensive computer vision, deep learning, and OpenCV course online today. Here you’ll learn how to successfully and confidently apply computer vision to your work, research, and projects. Join me in computer vision mastery.
Inside PyImageSearch University you'll find:
- ✓ 30+ courses on essential computer vision, deep learning, and OpenCV topics
- ✓ 30+ Certificates of Completion
- ✓ 39h 44m on-demand video
- ✓ Brand new courses released every month, ensuring you can keep up with state-of-the-art techniques
- ✓ Pre-configured Jupyter Notebooks in Google Colab
- ✓ Run all code examples in your web browser — works on Windows, macOS, and Linux (no dev environment configuration required!)
- ✓ Access to centralized code repos for all 500+ tutorials on PyImageSearch
- ✓ Easy one-click downloads for code, datasets, pre-trained models, etc.
- ✓ Access on mobile, laptop, desktop, etc.
Summary
In this blog post I detailed how to install OpenCV and Python on your Raspberry Pi 2 or Raspberry Pi B+. Timings for each installation step were also provided so you could plan out the install accordingly.
As the Raspberry Pi (along with Raspbian/NOOBS) evolves the installation instructions will likely change. If you run across any edge cases or variations in the install instructions, please feel free to let me know. While I can’t promise that I can reply to every email, but I think it would be good to curate a list of methods to setup OpenCV and Python on Raspberry Pi systems.
And in future blog posts we’ll explore how to utilize the camera add-on for the Raspberry Pi.
Until then, take a look at the PyImageSearch Gurus computer vision course. We’ll be utilizing the Raspberry Pi inside the course for a few projects, including building a home surveillance application that can detect motion and people in rooms.
Join the PyImageSearch Newsletter and Grab My FREE 17-page Resource Guide PDF
Enter your email address below to join the PyImageSearch Newsletter and download my FREE 17-page Resource Guide PDF on Computer Vision, OpenCV, and Deep Learning.
centryfox
What are the FPS looking like with openCV+python on the RPi2?
Adrian Rosebrock
I’m actually in the process of figuring that out. More posts to come 🙂
Niyas NAJEEM
How can we get your kit
Adrian Rosebrock
What do you mean by “my kit”? Can you elaborate? Thanks!
Adrian Rosebrock
Hey, as I followup I wanted to let you know the results of my testing. I am able to run 32 FPS at 640×480 for motion detection without a problem at all. Very, very fast.
RJ
May I know if this installation runs on multi-cores processing or it’s a single core processing? My installation with synaptic packages give around 10fps on 640 X 480 on color tracking. And the CPU usage monitors only shows 30- 40% utilizations.
Regards
RJ
Adrian Rosebrock
The OpenCV installation can utilize multiple cores, but your bottleneck with the camera is likely the I/O between the module and the OS.
RJ
I’m using the CSI camera like the one you have. How come the performance difference? Any tweak that you made that’s not covered in this tutorial?
Adrian Rosebrock
Nope, no difference in tweaks. Are you using the Pi2 as well?
Rajeev
Hey Adrian, awesome work. My OpenCV installation seems to be using only a single core (25% CPU usage) on my Pi 2. I’m making use of the inRange function to isolate colored lines for a line following bot. Any way of making my code run on all 4 cores? I’d already compiled OpenCV with TBB and OPEN_MP, but there seems to be no noticeable difference.
Adrian Rosebrock
Hey Rajeev, not all OpenCV functions are setup in a way to utilize multiple cores.
Shaun
Hi Adrian. I’m a total noob when it comes to the pi and image processing in general, so forgive me if this is a silly question “^^
How do you check the frame rate when doing something like motion detection? If I wanted to show some evidence of the frame rate, what would I need to do?
Thanks in advance! Your blog posts have helped me quite a bit.
Adrian Rosebrock
Hey Shaun — the easiest way to check the frame rate is use the
time
ordatetime
Python module. You’ll basically want loop over a preset number of frames (i.e. 2,000) and accumulate how long it takes to loop over each of those frames. Then you divide the total number of times by 2,000 (or whatever your number is) to get your average FPS. This isn’t a perfect method, but it will give you a rough estimate.Shaun
Alright, I will try that. Thank you!
By the way, if it’s not much trouble to ask, when tracking a ball specifically, using the pi 2, what sort of frame rate would you expect?
My approach for tracking is as follows:
1. Grab a frame from pi camera
2. Convert to HSV color space (for better accuracy)
3. Filter out the ball’s color range
4. Convert that filtered image to gray scale
5. Hough Circles to find the ball (accounts for partial occlusions) – initially I used moments, but that doesnt work for multiple tracking, and I will be doing that, hence another reason to use hough circles
Just judging by eye, it looks like I’m getting anywhere between 15-30 fps. Should I be able to get higher than that? Or at least a constant 30fps?
Adrian Rosebrock
Out of curiosity, if you can filter the ball’s color range using color, why even bother with Hough Circles? You could compute the moments directly on the mask generated by the color range. That said, 15-30 FPS sounds about right depending on the complexity of the image. If you get rid of Hough Circles you should be able to go even faster. You could also try downscaling your image which should improve the speed.
Mike
I am trying to do the exact same thing that you are trying to do: track a ball using HoughCircles.
I cannot get it to work! When I do only color detection, I get very low FPS, like 1-3 FPS.
Can you send me your source code for what you did to get 15-30 FPS?
Adrian Rosebrock
Hey Mike — if you have a question related to ball tracking or motion detection, please comment on the appropriate blog post. This post is dedicated to installing OpenCV on your Raspberry Pi. You’ve also submitted multiple comments on most OpenCV installation threads. Please do not spam the blog. If you have a question, comment on the appropriate post or email me directly.
aaron
Hi Adrian,
I’ve got everything banging away on my pi2, the only thing is I’m not seeing those kinds of frame rates, no where near when using a webcam.
I pretty much stripped everything out of the webcam case study code until all it’s doing is reading from the camera and updating the window and I’m only seeing just over 17 FPS. If I take out even displaying the frame, I’m clocking in at 24 FPS (not super useful like that, but I’m troubleshooting). I tried 2 different web cams with (near) the same results (maybe they’re both old)
When I run the cam.py example and add some timings, I see a wretched 1.65 FPS. I stuck some timers in for the loop and for the facial detection, and it’s spending .5 seconds running through the cascade! This is obviously the long straw even if my cameras suck.
What am I doing wrong? Is there a tweak or something I need to do to get this to run faster?
Adrian Rosebrock
Ouch, 1.65 FPS is quite slow. How large are the frames that you are trying to process? The first step is always to resize your frame, making it smaller, thus there is less data to process. By doing a simple resizing you should be able to get the cascade to run much faster.
Gabriel
One of the best compiled manuals/tutorials.
Installation went so smooth and according to the estimates provided.
Thanks a lot.
Adrian Rosebrock
Thanks Gabriel! 🙂
Romeo Eduardo Luna Arias
hello I have a problem with step 9 and 10, opencv not installed in the folder
/usr/local/lib/python2.7/site-packages
and i do not know why
I am newbie
Adrian Rosebrock
Did you run
sudo make install
after OpenCV was compiled?shawn
Hi Andrian! I have same problem. I’ve tried sudo make install and sudo ldconfig several times but the folder /usr/local/python2.7/site-packages is still empty.
How should I proceed this install? Thank you
Adrian Rosebrock
Hi Shawn, please read the other comments on this post. Check your
dist-packages
directory and make sure that the output of cmake has correctly picked up your Python version.mrar
I compile on UDOO board using your guide and successful. i face the same problem where I couldn’t find ang cv2 in that folder “/usr/local/lib/python2.7/site-packages” even after running this command “sudo make install”
Adrian Rosebrock
Try checking the
dist-packages
directory and seeing if the output of cmake has correctly picked up Python.Kevin Karagitz
Same issue for me. I ran the make install and it’s not installed under /usr/local/lib/python2.7/sites-packages
A quick sudo find / -name “cv2.so”
comes up empty… Thoughts?
Adrian Rosebrock
That’s definitely really strange. I would re-run cmake and make sure that the compilation is picking up the appropriate Python version correctly.
Kevin Karagitz
One thing of note, I noticed the make install log doesn’t show it installing any files under a python directory.
Marcellus
Hi Adrian,
I’m stuck at this import cv issue as well. I have read all of the comments in regards to this issue. You mentioned removing OpenCV, and re-installing it; how do I un-install something off of Raspberry? Also, I just realized that my Raspberry had Python 3.0 and 2.6 installed on it, so do I need to un-install 3.0 and 2.6 as well?
Adrian Rosebrock
Hi Marcellus, in your particular case it might be easier to just wipe your Raspbian install and try again. For questions related to uninstalling software from the Raspberry Pi, I’ll refer you to the Raspberry Pi forums. You shouldn’t need to uninstall Python 3, provided that your cmake command picked up the 2.7 version of Python. You can verify this by viewing the output of cmake.
Marcellus
Hello Adrian,
Wiping Raspian, and re-installing it did the trick. The mistake I made was doing 2 steps a day; I would do 2 steps, then poweroff Raspian. I realized that I needed to do Steps 7 – 11 all in one day. Thanks! Now, I just need to install the camera; I’m not sure if you have a tutorial for installing cameras on Raspian, but I’ll find it if you do. Thanks again!
Adrian Rosebrock
Hi Marcellus, here you go: https://www.pyimagesearch.com/2015/03/30/accessing-the-raspberry-pi-camera-with-opencv-and-python/ 🙂
Marcellus
Thanks!!!
Neil
Alternatively, I’ve had success with:
sudo apt-get install python-numpy
sudo apt-get install python-scipy
sudo apt-get install python-imaging
sudo apt-get install libopencv-dev
sudo apt-get install python-opencv
Adrian Rosebrock
Hi Neil, that certainly will work, but I strongly recommend against using apt-get to install these packages. You will not have direct control over the versions of each library (including OpenCV, which can be a problem) and you’ll effectively lose the ability to leverage virtual environments.
Chris Viehoff
Hi Neil, thanks for the excellent tutorial. Will you be covering
$ sudo apt-get install python-picamera
to access the PI camera module as well? Or are you using a webcam via USB for your vision projects?
Adrian Rosebrock
It’s Adrian, actually 🙂 And yes, I will be covering the
picamera
module in the future, which is what I use for my Raspberry Pi + computer vision projects.Helmut
I guess that “workon cv” is needed right before Step8 ?
This way Python2.7 is installed in the cv environment. Same for numpy and OpenCV?
In other words: Is it correct to work withinin the cv environment starting from Step8 onwards?
Thanks for this great tutorial !
Adrian Rosebrock
Yes, that is correct. If you followed the tutorial exactly, then running
mkvirtualenv cv
will drop you into thecv
virtual environment. But after you logout and login to your Raspberry Pi again, you’ll need to use theworkon cv
command to access yourcv
virtual environment.shawn
Hi Adrian! in case I happen to run “mkvirtualenv cv” again after re-login, will the old virtual environment “cv” is overridden?
Adrian Rosebrock
No, you’ll get an error message saying that the virtual environment already exists.
Chris Viehoff
Just noticed picamera is already installed. On another note, I have to run
source ~/.profile
to get the command “workon” to work. I this ok or does the change need to be
done in .bashrc.
Adrian Rosebrock
You can put it in .bashrc if you would like. I personally like to keep my .bashrc file as tidy as possible and keep separate source files. It’s a personal preference.
Ban
Hello.
Great tutorial, thank you Adrian!
I have some issues, any help would be highly appreciated
How can i check this?
Make sure you’re in the cv virtual environment
I wish to SSH from a win7 computer with putty, i set the X11 forwarding in putty, but io get the following error:
PuTTY X11 proxy: wrong authorisation protocol attempted
(Face:2193): Gtk-WARNING **: cannot open display: localhost:10.0
And i get command not found for the workon command.
Thank you
Adrian Rosebrock
Hi Ban, make sure you
source ~/.profile
when you login. Then you will be able to use theworkon
command. Once you are in thecv
virtual environment your shell will have(cv)
at the front of it.Kevin
Hello Adrian,
We finished the installation and wanted to run the test.py so we …
-closed our putty session
-enabled x11 forwarding
-opened an ssh session
– logged in and typed …
pi@raspberrypi ~ $ source ~/.profile
pi@raspberrypi ~ $ workon cv
(cv)pi@raspberrypi ~ $ python test.py
python: can’t open file ‘test.py’: [Errno 2] No such file or directory
(cv)pi@raspberrypi ~ $
Any suggestions?
Thanks
Kevin
Adrian Rosebrock
Hi Kevin, there is no
test.py
file pre-loaded on the Raspberry Pi. You need to create thetest.py
yourself. Sorry for any confusion. Anyway, here is the contents of test.py:import cv2
image = cv2.imread("image.jpg")
cv2.imshow("Example", image)
cv2.waitKey(0)
This of course assumes that you have an image named
image.jpg
in your directory.Manish Gupta
Adrian. Thanks for this very detailed set of steps. I was able to go through the steps as you mentioned. Ran the above program. The image popped up but it does not show the “face” as it is shown in the final step of your example. Any suggestions where I could have gone wrong?
Adrian Rosebrock
Hey Manish, there is nothing that you have done wrong. The “face” example was a quick Python script that I wrote to demonstrate that an image could be loaded from disk and displayed to screen. I would go read this post on on loading and displaying an image or the first few chapters of Practical Python and OpenCV to learn more about loading and displaying images to your screen.
CadoroV
Adrian ))).
Your guide is very good , btw after this answer i think you’re a good enginering
😀
Abhi
Hi Adrian, Do you have to be in ‘workon cv’ everytime you want to use opencv?
Can I just not do ‘workon cv’ and run my python script? would it work?
Adrian Rosebrock
You only have to execute the “workon” command once per terminal session.
Milan Kryl
You need to install Xming to Windows to enable X11 forwarding with PuTTY.
http://sourceforge.net/projects/xming/
Adrian Rosebrock
Great tip, thanks for passing it along.
Michael Little
Awesome and thorough tutorial. Much appreciated
Michael Little
This virtual environment is confusing to me. The install when fine but when I try to use the cv2 in python it says No module named cv2. How does this virtual environment come into play? thanks
Adrian Rosebrock
Hi Michael, make sure that you
source ~/.profile
followed byworkon cv
. Also, here’s a little more information on Python virtual environments.Michael Little
Works perfectly. Thanks for the tutorial.
Adrian Rosebrock
Fantastic, I’m glad it worked for you! 🙂
GooseNinja
This is an awesome Tutorial, and so is this website 🙂
But I would like to point out one thing about the Raspberry Pi 2 installation.
When you compile with make you are only using 1 of the CPU’s cores.
I followed your instructions, but I changed
make
to
make -j 5
by doing that, make runs in parallel mode and utilize each core.
Making the installation faster.
unfortunately, I didn’t time my progress. So I’m not sure how much faster it went.
Adrian Rosebrock
Very true! The reason I only used 1 core was so I could directly compare to the B+. But you’re absolutely right, utilizing multiple cores will dramatically increase the compilation stage. As Matt reports above, by using
-j4
he was able to reduce the compile time to 45 minutes.Justin
What is the point of directly comparing a single core of the Pi 2 to the B+? Few of us want to see the comparison at the expense of missing those 2 hours of useful time. Besides, the merits of the Pi 2 are in the quad core chip, so you might as well highlight those instances where it’s particularly helpful.
apri triansah
hi adrian, it is nice tutorial, im newbie in raspberry. is raspberry can run c++ code in open cv tutorial,bcause im not familiar with pyton
Adrian Rosebrock
Hi Apri, yes, the the Raspberry Pi can run C++ code as well.
Matt Kraemer
Hi Adrian,
I’m loving my rPi2 as well. I’m curious why you installed the virtual environment to run your programs in?
Also if you use ‘make -j4’ it only takes 45 minutes to build opencv on the rPi2 🙂
You may notice that the rPi and rPi2 both have hardware h264 support through the OMX driver. Gstreamer offers a plugin that wraps the OMX driver. Since OpenCV can use Gstreamer… this would enable writing h264 video to file without slowing down the 4 cores.
I’ve been trying to get this working but there are still a few bugs in the build process. hmmphf. Any chance you could lend a hand… or a friends hand?
Adrian Rosebrock
Hi Matt, thanks for the
make -j4
tip! I left it out of the original post so I could do a single core comparison to the B+. But you’re absolutely right, using-j4
will dramatically speed up the compile.Also, the reason virtual environment is used is so we can have different “environments” for each project that won’t conflict with each other. For example, you may be working on a legacy project that requires a very early version of NumPy. But your newer projects require the latest version of NumPy. Using virtual environments allows you to create containers for each of your projects where libraries do not overlap and cause versioning issues.
dim
Hi Adrian,
Thanks for the great tutorial! Do you think it would be possible to use a GoPro instead of whichever camera you are using? I’m assuming the processing will be a lot slower, but I’m probably fine with 1-2 fps. I know it’s possible to get composite out from the USB since it uses a 10 pin USB as opposed to the usual 5 pin USB. I can then use a composite to USB to connect to the RPi. I’m not sure where I would go from there, however. Do you have any pointers?
Thanks!
Adrian Rosebrock
Hi Dim, that’s a really great question. I personally have never used a GoPro before, so perhaps I’m not the best person to answer that question. Perhaps start with this forum post?. Best of luck and be sure to let me know how it goes!
dim
Hi Adrian,
Unfortunately, I will not be using wifi to connect to the GoPro. I have decided to look into using the HDMI port instead. Will something like this: http://www.auvidea.com/index.php/theme-styles/2014-12-30-22-32-06/b100-hdmi-to-csi-2-bridge
work?
Thanks!
Adrian Rosebrock
Hi Dim, sorry I can’t be of much help, but the only camera I have used in the standard Raspberry Pi camera so I can’t honestly say if that approach will work or not.
Skuli Oskarsson
Great Tutorial, thanks
alex
could you guys kindly provide some help on this step? I m a very beginner in linux.
“update your ~/.profile file to include the following lines:” in step 7
I have tried “vi ~/.profile” to edit the file.
However, it seems that it is empty file and when i finished editing, i failed to save.
Adrian Rosebrock
Hi Alex, you save a file in vi after editing you need to press escape, followed by
:
and thenwq
to save and exit the editor. I would suggest reading up on some vi basics.krzivn
I just used nano, not as l33t as vi, but way less cryptic.
Technoshaman
I installed everythig smoothly on my new Pi 2 (new to RPi, OpenCV, and Python) thanks to your tutorial. Thank you 🙂 However, I was careless and naive to think that I could think fit all these on a 4G SD card, with 3.7G Raspbian image installed (opencv’s make failed thanks to a full SD). So I had to copy my image to an 8G SD, expand and make again. Without the quad core and the -j4 switch, I’d probably suffer for a whole day. I have 3 BeagleBone’s, but this my first, RPi. I’m glad I waited, this is a very mature and powerful platform right now. Time to get into OpenCV and Python…
Adrian Rosebrock
That’s awesome, congrats on getting all setup! And if you’re just getting started with Python and OpenCV, consider signing up for one of the free OpenCV crashes courses on PyImageSearch. But if you’re really interested in jumpstarting your education, take a look at Practical Python and OpenCV. You’ll be able to run programs like face detection, handwriting recognition, and book cover identification right on your Pi 2.
Technoshaman
Thank you again. I’m really considering your courses here now.
phython
~/.virtualenvs/cv/lib/python2.7/site-packages $ workon cv
bash: workon: command not found
work on cv is not working
Adrian Rosebrock
Please see the other comments. You need to
source ~/.profile
before using theworkon
command. If you do not want to use thesource
command, then I suggest putting the virtual environment scripts inside your.bashrc
file.Vishaal
Hi Adrian,
I was facing a similar problem. Just finished installation and I shut the LXterminal and opened it again to test it out (So, I’m at the home directory). I typed in the following:
1. source ~/.profile
2. workon cv
I’m still getting the error saying command not found. Do i have to type in script after being in a certain directory or is something else wrong?
Adrian Rosebrock
It sounds like your
~/.profile
file was not updated correctly with the virtual environment export path.Miguel Amezcua
and what can we do if we have this error??
Adrian Rosebrock
You can open up your
.profile
usingvi ~/.profile
(or whatever you prefer) and copy + paste in the following contents:Then save and exit the editor. Please see Step 7 for more details.
aaron
Had something similiar happen to me. The workon cv command worked from the bare terminal, but would not work once I startedx. running the source .profile command fixed it. Not 100% sure why it didn’t just work though.
mobin
Hi Adrian
I have it problem,How ~/.profile file updated correctly?
Adrian Rosebrock
Hey Mobin, all you need to do is load the
~/.profile
file in your favorite text editor and copy in paste the lines from Step 7. You can open the file using editors such as vi, nano, etc. For example, to open the~/.profile
in nano, just execute this command:$ nano ~/.profile
And you’ll be able to edit the file.
mohamad
Hello Adrian
To Do this, need to install vision software such as guvcview or luvcview? If not how to open the image in Open CV ?
Adrian Rosebrock
Hi Mohamad, no, you do not need to install other vision software if you do not want to. It sounds like you are just getting started using OpenCV, so I would suggest taking a look at this blog post on OpenCV basics.
Vishaal
Hi Adrian,
The tutorial was awesome because it was very simple and easy to follow. I had a query regarding the ‘make’ step. I had started the building process when I came across the comment regarding the option of using multiple cores. If I were to terminate the building and start with ‘make -j5’ would it work? Or will have to delete everything built till now and start over again from the beginning?
Thanks in advance!
Adrian Rosebrock
Hi Vishaal, that’s a good question. Theoretically you should be able to terminate the build and restart with
make -j5
. However, due to compilation dependencies I would play it safe and domake clean
followed bymake -j5
. The compilation should only take roughly 45 minutes.Also, only do this if you’re using a Raspberry Pi 2. The B+ does not have multiple cores and thus you can’t take advantage of making the compile process parallel.
Vishaal
Ok, definitely sticking to the safer side and yes I am using an RPi.
Helmut
The prior messages refer to “make -j5”.
But Matt Kraemer wrote in an earlier message:
<>
I believe that the Raspberry Pi2 is a quad core.
So shouldn’t it be j4 instead of j5?
@Adrian: I’m loving your tutorials.
Adrian Rosebrock
Yep, you’re exactly right. I prefer to use -j3 instead, leaving one core open to the OS for other tasks. Otherwise you run into the problem of too much context switching.
Vishaal
Hello Adrian,
I was retrying your procedure and am facing a peculiar problem. While installing pip if I type in exactly what you’ve said I get an error saying ‘unable to resolve the bootstrap host ‘whereas i have confirmed that the link is active. The link refuses to open on the RPi 2’s browser as well but opens perfectly on a Windows browser. Any ideas as to what may be the issue?
Thanks!
Adrian Rosebrock
Hi Vishaal, I honestly have never ran into that error before, that’s very strange.
Rob Stevens
If I want to use this locally compiled version 2.4.10 outside of the CV virtual environment… how would I install it.
Adrian Rosebrock
OpenCV itself is actually not installed in the virtual environment (it’s only symbolically linked there). If you open up a Python shell (again, assuming you are not in a virtual environment) and type
import cv2
, OpenCV will import. However, if you go this route make sure you install the latest version of NumPy usingpip install numpy
to install the latest version of NumPy system-wide.Nishanth
Hi Adrian,
The installation went fine thanks to your tutorials, however if i open Python shell and use the command “import cv2” I am getting this error
“Traceback (most recent call last):
File “”, line 1, in
import cv2
ImportError: No module named cv2″
What might be wrong?OR do i have to write the program in the terminal itself,I am new to RPI so kindly help.
OR do i have to write the program in python shell and just call it using the the terminal?
Adrian Rosebrock
Hi Nishanth, please make sure you are in the
cv
virtual environment prior to importing cv2. As long as you are in thecv
environment, you will not have to write a script. You can simply execute it from Python IDLE. Also, please take the time to read the comments on this post. A lot of other readers have had the exact same error as you. There are many steps in this process where the problem could arise, so please be sure to read through the comments and see which ones apply to you.Jon Brown
Hi Adrian.
Thanks for great tutorial! I followed it and it works 🙂 You also mentioned that you are going to write tutorial on how to use PI camera module in OpenCV. Is it coming soon? Can you please briefly explain the procedure so that I can do it myself? I have some deadlines soon…
Kind regards,
Jon
Adrian Rosebrock
Hi Jon, I’ve got a bunch of blog posts in the queue right now so I can’t give a firm timeframe regarding the camera module post just yet. The gist is that you need (1) a Raspberry Pi camera (of course) and (2) the
picamera
module. That will get you started.Jeehyung Lee
Jon
The way I got it working:
1. install pi camera physically (make sure the ‘silver’ part faces away from network port)
2. run sudo raspi-config and enable camera (may ask you to reboot)
3. go into your virtualwrapper environment (if you went through Adrian’s tutorial above – type > workon cv)
4. run pip install picamera (note: http://www.raspberrypi.org/documentation/usage/camera/python/README.md tells you to install with sudo apt-get install python-picamera , you could, I actually haven’t checked if it installs any dependencies but my virtualenv cv could not find the module until after I did pip install picamera. It could be my virtualenv setting…)
5. Test / Use (instruction: http://www.raspberrypi.org/documentation/usage/camera/python/README.md)
Adrian Rosebrock
It does not install any dependencies, actually. 🙂
I would also make sure you include the “array” package of picamera to ensure you have NumPy support:
pip install "picamera[array]"
I’ll definitely accelerate the blog posts on setting up picamera and the camera module in the schedule.
William Tandy
Hi Adrian!
I have already followed your tutorial to install opencv in my raspberry B+, but at the step 11 I’m stuck.
when I executed “import cv2” it always show error “importError: No module named cv2”
Can you help? I’m beginner on Linux..Thanks before
Adrian Rosebrock
Hi William, please read through the previous comments as these comments address your problem. Your error is likely because you (1) did not update your .profile file, (2) did not
source .profile
after updating it, or (3) did not sym-link the cv2 module into your virtual environment.William Tandy
Hi Adrian! It looks like the problem is pip-numpy installation (numpy not installed correctly). when I re-do the step, it’s going well. Thanks Adrian, for the tutorial and the followed up..really helpful!
Adrian Rosebrock
Awesome, glad to hear it!
Kevin Carlson
Thanks for the great tutorial on installing cv!
Other “RPi newbies” such as myself might notice that keys such as the “tilde” (~) won’t work correctly out of the box. In the US, it is necessary to modify the keyboard settings from the default Great Britain settings.
At the command line, you can enter sudo raspi-config to get the configuration menu.
Alternatively, at the command line you can enter
sudo nano /etc/default/keyboard
and change “gb” to “us”. Use Ctrl-O to save the changes and Ctrl-X to exit.
Thanks again,
Kevin
Adrian Rosebrock
Good point, thanks for sharing!
Kevin Carlson
Would you consider posting SD card images on Github, with CV preinstalled?
That could save users a lot of time, who would then have a dedicated “known good” instance of Raspbian/CV to play with…
Adrian Rosebrock
Certainly, I would love to do that. I have never generated a SD card image for the Raspberry Pi though, so I would have to do some research on how exactly that is done. If you have any resources, please pass them along!
MIhaly Sogorka
Hi,
thanks for the tutorial.
Any progress with the Raspbian SD card image that includes OpenCV? Raspberry PI 2 devices are often using OpenCV so this should be part of the OS.
Adrian Rosebrock
I’ve tried a few times, but the resulting
.img
file is near 7gb, which is too large to distribute. I am looking at alternative ways to create the.img
file, or even forking the Raspbian OS itself.meysam
Hi Kevin
do you have this now ?
Jose Antonio
Hi Adrian,
Thanks to take the time to make this kind of tutorial, maybe can you help me with the links of the hardware that you use with it? I will travel to USA in the next months and I want to buy the hardware that I need to follow your course.
Thanks again.
Adrian Rosebrock
Hi Jose, the only real hardware that I use outside of the Raspberry Pi 2 itself, is the camera, which you can get off Amazon.
Dim
Also worth mentioning that some OpenCV requires SciPy, which can be installed by:
sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose
Adrian Rosebrock
OpenCV does not actually require SciPy, just NumPy. And it’s also a good idea to stay away from apt-get installs for the stack. Install from source to ensure the latest versions are used and your life will be much, much easier.
Toon
Hi,
I have some problems by step 7.
Is there anybody who can help me?
Thanks
Adrian Rosebrock
What are your problems with Step 7?
Christian
Thank you for this tutorial I am very interested for personal application. I followed exactly the procedure (used gedit to edit ~ / .profile file and make -j4) but after sudo make install and sudo ldconfig : /usr/local/lib/python2.7/site-packages is empty. ..
Where is my mistake, what can I do ? Thanks in advance.
Christian
Adrian Rosebrock
Hi Christian, that is indeed very strange. I would the
cmake
script again and see if you can figure out where OpenCV is getting installed to. Also, make sure you were in thecv
virtual environment before compiling OpenCV.Christian
Hi Adrian, thank you for your fast reply.
I just recompile, with the same result, but I just found out that everything seems in : /usr/local/lib/python2.7/dist-packages
Did I finish the installation with that subdirectory name?
Adrian Rosebrock
I’m not sure why it would be in the
dist-packages
directory, but if it compiled correctly and you can import the OpenCV library, I guess I wouldn’t worry about it.Stephane Richardier
Hi Adrian,
Same thing for me, site-packages directory is empty but everything is in the dist-packages.
I’ve modified the “ln” commands to adapt the path and it seems to work.
Great tuto, very nice job!
Stephane
Adrian Rosebrock
Awesome, I’m glad that it worked for you 🙂
Govind agrawal
Hi Adrian, there is a problem in unpacking of the files. when I was opening the file opencv-2.4.10.zip its showing “Can’t open file “/home/i/opencv-2.4.10.zip”.So I am confused , What should I do?
Thanks
Adrian Rosebrock
Hi Govind, that’s definitely a strange error. But is
/home/i/opencv-2.4.10.zip
the actual path to your file? Because that/i/
should be/pi/
and I’m willing to be that you’re trying to unzip a file that doesn’t exist.Christian
Hi Adrian,
I actually compiled outside of the virtual environment cv.
Now it works fine !
And I look forward to more on motion detection and tracking !
Best Regards
Christian
Cameron
Fantastic walk-through!
Adrian Rosebrock
I’m glad you enjoyed it Cameron! 🙂
Shopnodip
after i put the “make” command as :
(cv)pi@raspberrypi ~/opencv-2.4.10/build $ make
The following error message comes up :
make: *** No targets specified and no makefile found. Stop.
Please help me out how to solve this issue…
Adrian Rosebrock
Based on your error message, t sounds like either (1) you did not run cmake so the Makefile could be generated or (2) cmake exited with an error and thus the Makefile was not generated. Please investigate the output of cmake and ensure that it was properly generated.
Shopnodip
Yeah it worked! 🙂 I didn’t run cmake…. Thanks a lot!
I have one more question :
Do I ALWAYS need to work in “cv” virtual environment while writing programs in Python + Opencv ?
Adrian Rosebrock
Yes, you should be in the
cv
virtual environment when writing programs for Python and OpenCV. But that’s the beauty of virtual environments — you could create a new virtual environment calledshopnodip
and just sym-linkcv2.so
andcv.py
into there as well! The possibilities are endless.Shopnodip
What if I need to install packages like “matplotlib” ?
1. Which directory should I install it in?
2. Is it necessary to be in “cv” virtual env as well when downloading and installing the packages for Python 2.7
Thanks in advance!
Adrian Rosebrock
If you need to install matplotlib:
where
your_virtualenv_name
could becv
or your own custom virtual environment. If you are in that virtual environment, pip will only install into that virtual environment (and no others). If you’re new to virtual environments I would definitely take some time and read up on them! They are an amazing tool.decepticon
I got the same error but I couldn”t understand how I can fit it
Randy
Hi Adrian. I have installed OpenCV successfully. Now, is it safe to remove the extraction directory and the build directory? Secondly, is it possible to use the build directory to install OpenCV on other raspbian installation so I don’t have to do another compilation? Thank you very much.
Adrian Rosebrock
Hi Randy, yes, you can safely remove the build directory and .zip now. And if you are installing on the exact same Raspberry Pi model and followed the exact same install steps detailed in this post, then yes, you can save the build directory and not have to do another compilation.
Scott Routley
Fantastic Tutorial! Easily the best OpenCV installation instructions I have found, mostly because it worked the first time!
Unfortunately I don’t understand the virtual environment very well, which is where my question stems from.
1) I have a test script, “testCamera.py” that will take a picture with the raspberry pi camera. It works as expected.
2) I have run your tutorial and after running “workon cv” the import cv2 statement works great in scripts. Your test script will give me the version number
3) When I am in the “cv” environment, i can’t run “testCamera.py” as the statement “import picamera” fails.
4) When not in the “cv” environment, I cannot the version number to print (I think this is expected behavior)
My interpretation is that I need to install the”picamera” within the “cv” environment, but I tried that with no success. apt-get seems to recognize that it’s already installed.
Do you have any suggestions on how to resolve this issue?
Adrian Rosebrock
Hi Scott, thanks for all the comment. All you need to do is
workon cv
followed bypip install picamera
— that will install thepicamera
module inside thecv
environment. Next week I’ll have a blog post on exactly how to do this and access the raw Raspberry Pi camera stream using OpenCV.Scott Routley
Thanks Adrian,
Oh I did an apt-get instead of a pip…maybe that is the issue. I’m not sure as it was late last night.
I’ll try again when I get home and report back on the results.
I appreciate the reply and I immensely look forward your upcoming blog post! 🙂
Scott Routley
Hi Adrian, Just to confirm the pip did work! I would have bet 1 doughnut that I had tried that already. 😉
Thanks for your help and thank you for creating such great content.
Adrian Rosebrock
Of course, happy to help! And I’m glad to hear that the pip-install worked! 🙂
Max Kostka
Hi Adrian,
I can totally agree with everbody else. Thanks for this great tutorial.
I have been working with the old raspberry and opencv before, but this is the best tutorial i have come across. Great work!
Adrian Rosebrock
Thanks Max, I really appreciate that 😀 Check back on Monday for another post on the Raspberry Pi!
Max Kostka
I will! And after taking a look at the sample chapter of your book and considering this great tutorial i ordered a copy, hopefully this will give a boost to my project, the mice detecting cat flap 🙂
Adrian Rosebrock
Thanks for picking up a copy Max! 😀
Harry
Hi, Adiran
I have an issue. I was fine after installing Opencv following by your tutorial. However, after i reboot raspberry pi, i can not get into virtual environment any more.
What i did:
reboot.
log in pi
type : source ~/.profile
type : workon
-bash: workon: command not found
( it is showing now.)
Do you have any solution for this then i will be vary happy.
Adrian Rosebrock
Hi Harry, it sounds like you didn’t update your
.profile
file with the paths for virtualenvwrapper. Go back to Step 7 and ensure your.profile
file is updated correctly.Nagaraj
Hi Adrian,
In the final step,we tried to import cv2 after the python instruction, but we are getting an error saying “importError: No module named cv2”
what should be done to resolve this.kindly help ASAP.
Thank you
Adrian Rosebrock
Hi Nagaraj, please see the other comments on this article. Your error could be any number of issues. Did OpenCV install correctly? If so, did you edit your
.profile
file correctly? Other readers have had similar problems so please take the time to read through their solutions as well.Shivam Gargshya
I followed all the steps mentioned above still not able to start virtual environment with workon cv.when I type workon cv following error message is displayed.
~bash:workon: command not found.
Adrian Rosebrock
Hi Shivam, take a look at the rest of the comments on this article. Make sure you have properly updated your .profile file and that virtualenv has been properly installed. There are many steps that things could have gone awry.
Nagaraj
Hi Adrian, OpenCV was installed successfully,However when I tried to edit the .profile in the vi window I am getting an error saying “~/.profile E212: Cant open file for writing” so i just edited it in the .profile text window. Is that the problem? If so how to should i get it done in the vi window?
The workon command works fine,but after the python command in step 11 if i import cv2 I am getting the same error as above.
kindly help
Thank you
Adrian Rosebrock
I have honestly not encountered that error before with vi. From what I understand that is a permission issue? You should look into the problem of why you cannot write to the
.profile
file before proceeding. Also, make sure you have sym-linked thecv2.so
andcv.py
files as detailed in Step 10.jerryk
Has anyone else had an issue running get-pip/py on Step 6?
When I run the command I get error:
bash: $: command not found
Adrian Rosebrock
Leave off the “$” from the command. The “$” is simply meant to signify the command line prompt.
Nagaraj
Hi Adrian,
After installing the opencv-python in raspberry pi, i tried to code in python IDLE. When type “import cv2” its giving an error named as “no module named cv2”.Please help me to solve this error.
Thank you.
Adrian Rosebrock
Hi Nagaraj, other readers have had similar issues. Please read through the comments to this post and ensure you have followed all steps correctly.
Nagaraj
Hi Adrain, i tried installing matplotlib using “pip install matplotlib” however after 99% its showing an error called “Memory Error” and it fails install later.
I still have 8gb worth of free space in my SD card.
What might be going wrong?
KIndly help
Thank you.
Adrian Rosebrock
If you are getting a memory error it’s because the Raspberry Pi is out of RAM, not out of space on your SD card. Installing matplotlib takes a lot of memory to compile from source — I am looking into alternatives to install matplotlib on the Raspberry Pi that do not involve apt-get.
Nishanth
Hi Adrian,
I want to install matplotlib in raspberry pi ,so i followed your instruction that you mentioned for others in above comments but i am getting an memory error. How to overcome this problem..?
Thank you.
Adrian Rosebrock
Please see my reply to Nagaraj:
If you are getting a memory error it’s because the Raspberry Pi is out of RAM, not out of space on your SD card. Installing matplotlib takes a lot of memory to compile from source — I am looking into alternatives to install matplotlib on the Raspberry Pi that do not involve apt-get.
Neeraj
Hi Adrian,
Wow! Thanks a lot, struggling with open cv installation for so many days, came to your link and installed open cv successfully, This is one of the best tutorials I came across on open cv installation and I am sure the knowledge which you have on this topic will surely reflect in your book, I am now going to order your book now and want to learn more on opencv library.
Thanks & Best Wishes
Neeraj
Adrian Rosebrock
Thank you for the kind comment Neeraj, I appreciate it! I’m happy that I could help. And enjoy the book! 🙂
ReneLunna
Adrian, first… thanks a lot. Great tutorial.
i dont have any experience in Linux based OS but i can follow all steps and have no errors during setup, but when i tried import cv2- in (cv)- i have the same error:
“No module named cv2”. I read all comments 4 times and all the things sound perfect… Any idea?
thanks again!
ps* i have a picamera whit pip install in virtual enviroment…so…no idea.
ReneLunna
I found! i Dont do right step 10.Nagaraj, try Again step 10 and i think… your problem is solved. One Thousand thanks Adrian;)
Martin
I’m stucked at Step 7. after entering vi ~/.profile, i don’t know where to write down the stated coding.
Adrian Rosebrock
Hey Martin, I’m not sure what you mean by “write down the stated coding”? You can edit the
~/.profile
file with whatever your favorite text editor is.Morganna
Hi,
I’m stucked at step 7. done with the vi ~/.profile but i don’t seems to understand on how to enter the required coding you had stated
Adrian Rosebrock
Hi Morganna, you don’t have to use vi, you can use whatever text editor you are comfortable with.
Morganna
can i know how? please explain step 7 more because i’m new on this thing and i don’t understand how to proceed with the step
Adrian Rosebrock
Take a look at the list of available text editors on the Raspberry Pi, I’m sure you’ll be able to find one that suites your needs.
Morganna
finally done with step 7, but i’m stuck at step 11 where the error stated was “no module named cv2”
Adrian Rosebrock
Hey Morganna, there are a lot of reasons why the import statement could fail. You could not be in the
cv
virtual environment. You might not have edited the~/.profile
correctly (or reloaded it after editing). There are a lot of comments on this post about why import statement could fail, so definitely take some time and read through them to see which one is most relevant to you.Morganna
how exactly you reload the ./profile? been editing the /.profile and still the error is present
Adrian Rosebrock
Please see Step 7:
source ~/.profile
Morganna
i guess i have problem not at step 7, but at step 10 or 11 where i don’t know how to do the sym link.how to do the sym link by the way?
Adrian Rosebrock
Step 10 shows you how to sym-link using the
ln
command.Morganna
At which line shall step 7 be written down in the editor? at the first line?
Adrian Rosebrock
Yes, the first line.
Morganna
Do you provide a youtube video for this post? i think i did everything (plus reinstall the raspbian just in case i made a mistake for the first 10 steps) but the error of no module CV2 still occur. i did the editing ~/.profile, resource it and also sym-link, everything. i think if you do have the youtube tutorial video will help me identify the mistake(s) i might do.
Adrian Rosebrock
Currently I do not have a YouTube video, but I will definitely consider it in the future.
Ishank gulati
Hi Adrian
Thanks a lot for this post. I have successfully installed openCV on my pi as per your instructions and I am using it in a robot. So i have to execute my python script automatically on boot but the problem is OpenCV is installed in a virtual environment and I dont know how to automatically enter in Virtual environment before executing my script. Can you help me on this, I have to demonstrate it in a few days.
Adrian Rosebrock
Hi Ishank, you should be able to create a crontab entry on reboot that calls a script that (1) enters in the
cv
virtual environment and (2) executes your script. Do a little research on crontab on reboot and this will help solve your problem.Ishank Gulati
Thanks for quick reply. I will do the same
Darren
I have followed each step precisely and when I get to Step 9 and type:
(cv)pi@raspberrypi ~/opencv-2.4.10/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
I get this error:
CMake Error: The source directory “/home/pi/opencv-2.4.10/build/BUILD_EXAMPLES=ON” does not exist.
Specify –help for usage, or press the help button on the CMake GUI.
Should the last part be: -D INSTALL_BUILD_EXAMPLES=ON
What I am I doing wrong?
Thanks everyone
Adrian Rosebrock
Hey Darren, the reason you are getting the error is because you’re forgetting the “..” at the end of the command, indicating that cmake should look up one directory:
$ 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 ..
Notice how I have the
..
right after the-D BUILD_EXAMPLES=ON
Marcellus
Bro, this saved my life right here!!! I thought . . was a couple of spots on my tv screen! LOL! Thanks a lot Darren and Adrian!!! Great tutorial & much, much, much appreciated!!!! You rock!
Adrian Rosebrock
Nice! 🙂
Péter Lehoczki
The exact same happened to me too, thanks a lot!
Maula Ramadhan
Hi, Adrian.
I’ve actually followed these steps, except that I’ve already installed the opencv before the virtualenv installed and run. Now I am having a problem that I cannot find any ‘cv2.so’ or ‘cv.py’ anywhere. When I run the command
$ workon cv
$ python
>>> import cv2
it says that no module of cv2 there. where is the problem lies here? Is it because the way I’ve installde the opencv not on the (cv) state?
Waiting for your answer soon. Thanks.
Adrian Rosebrock
Hi Maula, you mentioned that you installed OpenCV prior to running these steps? Was it via an
apt-get
installation? If so (as far as I understand), that’s where your problem is. If at all possible I would try removing the previous version of OpenCV from your system and then re-following the steps in the tutorial. Hopefully the whole setup isn’t hosed, but you might be in a state where you need to re-install Raspbian to get everything to place nicely together again.Maula Ramadhan
Thank you for the reply.
Actually I installed it by downloading the package via PC (Windows) then I copied them into pi and do the rest of the steps after “wget” thing.
But I can’t seem to get the “sudo pip install virtualenv virtualenvwrapper” the raspi says that it is downloading the package but cannot fetch the index base, then keep says that “could not find any downloads that satisfy the requirement virtualenv” –> “No distribution at all found for virtualenv”.
I’ve tried a step where I separate the sudo command :
sudo pip install virtualenv
sudo pip install virtualenvwrapper
It’s actually work, but when I’ve done with it I can use any function of python used inside the (cv) always having an error.
so if the problem was as you said it was, i would just install my backup image (before the OpenCV installed) and did the steps all over again. There are several questions that I want to ask you.
will it be a problem if I do the steps in ‘root’ mode?
which one is the right state that is necessary to install OpenCV?
“pi@raspberry ~:” or “(cv)pi@raspberry”
I am sorry for the very long question, but I am being really curious about all this. 🙂
Adrian Rosebrock
Yeah, given your situation I definitely suggest that you revert to back your backup image and follow the steps I provided exactly. It’s pretty hard to diagnose where the error would be coming from. As for being root, OpenCV needs to be installed via root anyway, so that shouldn’t be an issue. And you’ll want to make sure you are in the
cv
virtual environment prior to compiling OpenCV. As long as you follow the steps I detailed, your install should go painlessly.Hung
Thanks Adrian, It is successfully installed and run test.py ok, but after reboot, I can’t control raspberry by remote destop connection on win 7
ibrahim Sholeh
thanks for your tutorial adrian… but, after installation, what i should to do to compile opencv with c++ ??? im just familiar with c/c++…
Adrian Rosebrock
Hi Ibrahim, thanks for the comment, but this blog focuses only on Python + OpenCV. I don’t cover compiling OpenCV apps with g++ here.
ibrahim Sholeh
please adrian give me a tips… 🙁 should i install gcc and g++ compiler through apt-get install build-essential… please help me… 🙁
Adrian Rosebrock
Yes, you’ll need gcc/g+++ to compile OpenCV through the build-essential package. I discuss this at the top of the article. Just follow the steps one at a time as I have detailed them.
Happysangs
I have a question.
when I install opencv and python , I have to use only pi cam?
can I use the web cam?
Adrian Rosebrock
You certainly could, although you would have to setup and install the drivers required for the Pi to read frames from your web cam. I personally have not done that so I’m not sure about the best way to go about it.
ibrahim sholeh
By the way, you have tested it can run motion detection project at 32 fps/640x480p on raspberry pi 2 … I think it is very fast… Does it mean opencv 2.4.10 can utilize quad core cpu of raspberry pi 2???
Adrian Rosebrock
The reason the Pi 2 is able to achieve such high frame rate is because it is significantly faster than it’s predecessors. The raw processing power itself makes it more capable of higher frame rather. And since it has more cores, less time is wasted doing context switching.
srikanth
hello adrain.i have a problem with pi using in windows through putty.do u have any idea of connecting in this way?
Adrian Rosebrock
Hey Srikanth, I only use OSX and Ubuntu, I do not have a Windows machine. Hopefully another PyImageSearcher reader can help you though!
Jonathan
Hi Srikanth.
If you have access to your Pi directly, in a terminal run ifconfig to find out the Pi’s ip address then simply connect to that via Putty. If taht doesn’t work then you may need to connect via a specific port. Try :1 after the ip address or :22 or :5901 which have all worked for me at various times. Hope that helps.
Thanks Adrian for the great tutorial. Just working through it.
Adrian Rosebrock
Hey Jonathan, the standard port for SSH is port 22, so you should always try to connect to the Pi via port 22 over SSH. SSH also defaults to port 22 so this shouldn’t be an issue. When I ssh via my terminal, my command looks like:
$ ssh pi@pi_ip_address
Where “pi_ip_address” is replaced with the IP address of your Pi.
Cyb
So,
After reading all post, I wrote the new lines of .profile at the beginning instead of the end of the file, and mkvirtualenv is working now.
Sorry.
Cyb
Adrian Rosebrock
No problem, I’m glad it’s working for you!
vix
why when i script this 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 ..
i get reply
-bash: cmake: comment not found
how to solve?
Adrian Rosebrock
You need to install cmake first. Please see Step 1 of this tutorial.
Daniel Kim
sudo apt-get install cmake? will that solve?
Adrian Rosebrock
Yes, as per the instructions in Step 1, that command will install cmake for you.
Markus Flaig
I used “make -j4” instead of just “make”, which finished the build process in less than an hour on my Raspberry Pi 2.
Tushar
Hello, Adrian.
This is an awesome tutorial. I have a question. I need to use the gpio pins while I’m running the cv code. Therefore, I need to use the sudo. But it doesn’t work in the cv. Gives my a python error that cv2 is not installed. What should I do?
Thanks
Tushar
Adrian Rosebrock
Unfortunately, I do not have any experience working with the GPIO pins so I’m not the right person to answer this question. Hopefully another PyImageSearcher reader can jump in and help!
Aron
Tushar, I’m facing the same problem. Did you find the solution?
Thanks.
Aron.
sovann
Dear Adrian Rosebrock
I don’t know how to do step 7 in LXTerminal. Could you screenshot the command line again, please?
Adrian Rosebrock
All you need to do is use your favorite editor, such as vi or emacs, and copy + paste the content into your
~/.profile
file.SAS
install matplotlib using pip on raspberry pi 2
1) sudo rapi-config => memory split => choose lowest level 16 MB => reboot
2) login to your pi => no need to startx (graphical ) yet
3) source ~/.profile
4) workon cv
5) pip install matplotlib
hope this help
Adrian Rosebrock
This is incredible. Thanks for the tip!
karthik
install matplotlib on rasp 2
I tried this and worked for me
Adrian Rosebrock
Thanks for sharing Karthik!
Paula
Hi Adrian, thanks for the tutorial, I just have a few questions:
1- After creating my virtual environment in Step 7, should I stay in cv for the rest of the steps?
2- If so, why in step 11 the first line is “workon cv”, can’t I just type python after step 10?
3- Is it necessary to reboot in the middle of the process, or just follow the steps?
4- I’m using a 8GB SD with Raspbian, do you think it’s enough to run real-time computer vision applications or should I get a 16GB?
(5) Sorry for bothering.
Thanks in advance!
Adrian Rosebrock
Hey Paula, to answer your questions:
1. Yes, you should stay in the
cv
environment for the rest of the steps.2. The
workon cv
step is included as a manner of completeness. If you were to reboot your system, you would need to re-enter the virtual environment using theworkon
command.3. I would only reboot when prompted to when upgrading the system in Step 0.
4. 8gb is more than likely enough, but it’s always helpful to have extra space.
HYCCC
Hi Adrian,
Thanks so much!! Indeed, it’s the best tutorial for installing opencv!!!
But I have a problem and maybe you can help me to figure out, when I launch test.py for face detection. I get this error msg ”
GLib-GObject-WARNING **: Attempt to add property GtkSettings::gtk-label-select-on-focus after class was initialised”
I am using 2015-2 raspibian img, is this error is a bug from the new camera module driver?
I am looking forward to hear back from you
Thank you very much!!
HYCCC
Adrian Rosebrock
The GTK error is actually related to the
libgtk2.0-dev
package. It will not impact your OpenCV usage.Kevin
Hi Adrian,
Thanks for the great tutorial. I seem to have, after following all the steps, encountered an error when trying to import cv2 in the virtual environment. I’ve read all the comments regarding the importing of cv2 but I believe I have done everything correctly. However, if this is of any use, I can successfully import cv2 when I’m not in the (cv) virtual environment (i.e. when I just launch python from bootup and import cv2). Where could the problem lie? Thanks.
Regards,
Kevin
Adrian Rosebrock
Hi Kevin, based on your comment it sounds like OpenCV may not be symbolically linked into your
cv
virtual environment correctly. Go back to Step 10 and make sure that everything is sym-linked into your virtual environment.Harini
I have a problem with step 9 and 10, opencv not installed in the folder /usr/local/lib/python2.7/site-packages
and i do not know why, i’ve followed the steps exactly and it shows me no module found when i write import cv2.
please help, I’m entirely new to this.
Adrian Rosebrock
Check and see if it’s in the
dist-packages
directory. Also be sure to read through all the comments on this post as other readers have had similar problems.Morganna
It works perfectly. Do you ever encounter a project that calculate the angle between two objects using these python,opencv and pi cam?
Adrian Rosebrock
If you know the location of the two objects, then you an apply basic triangle properties and compute the angle between them. I do not have any code on the PyImageSearch blog on doing this, but I’ll make note about potentially doing one in the future.
Morganna
i saw one post from PyImage on the distant calculation, i wonder can the idea be done in measuring the angle as well?
Sergio
404 not found when trying to download at step 9 : (
Adrian Rosebrock
Hey Sergio, make sure you are using the entire command:
wget -O opencv-2.4.10.zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.10/opencv-2.4.10.zip/download
Sergio
Working now thanks !
Problem is, Im accesing my raspberry pi 2 trough SSH from my Windows 8.1 PC and every time y try executing a python script which includes cv2.imshow i get this error:
(image:24957): GLib-GObject-WARNING **: Attemp to add propery GtkSettings::gtk-button-images after class was initialised
Im googled it and found some solutions which did not worked for me, so right now I`m a bit stuck since I cannot even display the result of any image processing.
Hope u can help
Thnks !
Adrian Rosebrock
Hey Sergio, please see my previous comment on this blog post: “The GTK error is actually related to the libgtk2.0-dev package. It will not impact your OpenCV usage.” Your image will still display to your screen, but you might see that error message related to GTK. And if you’re SSH’ing into the Pi, you need to make sure you are using X11 forwarding so your window will show up.
Martin Mayr
Hello Adrian,
I followed all the 11 steps and in step 11 i’m struggling now:
the command workon cv worked (I think) since there is no reply I don’t really know ….)
the python command opens Python 2.7.3…. (looks fine too
But then the >>> import cv2 replies:
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named cv2
What did I miss ????
Thanks for any help
Best regards
Martin
Adrian Rosebrock
Hey Martin, there are a lot of things that could have gone wrong, such as not properly sym-linking the OpenCV files into your virtual environment, not updating your
.profile
file correctly, or even forgetting to runmake install
. Read through the rest of the comments on this post (I know, there are a lot of them), but they address many different areas as to where the problem could be.Martin Mayr
Hello … I redid step 10 after deleting the files cv2.so and cv.py (which were displayed red in the directory ~/.virtualenvs/cv/lib/python2.7/site_packages/ before then I recreated the ln … commands and now the two files are colored cyan …
Since that the problem of the import mentioned before has disappeared …
No idea why ?
Best regards
Martin
Adrian Rosebrock
If they were red, then the sym-link did not point to an existing file. If they are cyan now, then the sym-link does point to a valid file.
Andre
Hi Adrian
Thank you for a very comprehensive tutorial.
I am a new to Pi & Programming. I have followed every step but when I type in: workon cv I get: workon: command not found.
Any sugestions?
Thank you in advance
Eclectic_Energy
Adrian Rosebrock
Hey Andre, definitely take a few minutes and read through the comments on this post (I know there are a lot of them). Other readers have had issues like this and have posted their solutions. The main reasons why the
workon
fails is because (1) either your.profile
was not updated correctly or (2) you did notsource ~/.profile
after updating it.Andre
Hi Adrian
My mistake was to edit vi filename instead of vi ~/.profile
Hopefully everything will work now.
Adrian Rosebrock
Nice, congrats on getting it to work! 🙂
Max Web
do it also work with the Raspberry Pi B Model?
Adrian Rosebrock
Theoretically yes, but I have not personally tried with the B model: only the Pi 2 and B+.
leonard
Hello Adrian , first of all thanks a lot for this tutorial , am kinda new at raspberry and opencv and such … can you please explain how to make the step 7 am stuck at /.profile update thingy , i dont get it at all . i mean where is it how can i modify it and put those lines that you say ?
Second after this tut i can run any code with python for color tracking and controlling 2 servos for tracking the moving color ?
Thanks again
Adrian Rosebrock
Hey Leonoard, the
.profile
thingy is actually a (hidden) file that resides on your disk. The~/
is actually just shorthand for our “home” directory. We use thevi
command to open up our text editor and insert the virtualenv lines. However, you could use any text editor that you want — including the graphical text editor shipped with Ubuntu. If you’re struggling a bit withvi
then try using nano:nano ~/.profile
— the nano editor should be a bit easier for you to use and insert the required lines.As for your question, once you have followed the tutorial you will absolutely be able to perform color tracking on the Pi, provided that you have a camera connected to it of course. I actually over color/object tracking inside my Case Studies my book, so that might be worth checking out as well!
Sam
I followed your tutorial and installed openCV along with the virtual environment.
But I want to run my python program at START-UP of the raspberry pi.
How can I do that?
Adrian Rosebrock
Hey Sam, you’ll want to look into using crontab to schedule a task whenever you Pi boots up.
sar1
Hi
I want to install the openCV in my raspberry pi Model B (512Mb) . Can I fallow the same steps as you mentioned in tutorial ?
Adrian Rosebrock
I have never tried to install OpenCV on the Pi B, but theoretically yes, you can follow the same steps detailed on this tutorial.
juan christophel
hey buddy, it’s works, so helpful for me.. i so appreciate.. thank you so much..God bless you more
Adrian Rosebrock
Very nice Juan, I’m happy it worked for you! 🙂
Luiz Felipe
Hi there! Thanks for this excellent guide…worked flawlessly.
The only question I have is if it’s possible to run the “source ~/.profile” and “workon cv” commands on boot/startup.
Thanks.
Adrian Rosebrock
Nice! I’m glad the guide did the trick for you. As for your question, I would suggest putting the contents of
~/.profile
followed byworkon cv
inside your~/.bashrc
file. Anytime you startup, reboot, or open a terminal window the configurations in.bashrc
will be executed.Luiz Felipe
Hello, Adrian. Sorry for my delayed feedback.
Thank your for the reply, it worked worked exactly as I expected/wanted.
Unfortunately, I thought this trick would solve my main issue, but it didn’t.
The python script works perfectly when I launch it directy from the terminal, but I need to execute it indirectly, using a bash file e,g or more specifically (my project), I need to run it from the Mathematica/Wolfram software. This sofware has a function called Run[], and it works with any other shell command.
Can you help me?
Thanks!
Adrian Rosebrock
I’m actually not familiar using Mathematica, but if you want to launch your Python script from a bash file, you would follow the same process. Just have the bash script call the
workon cv
before calling your Python script. That will make the bash session drop into thecv
virtual environment prior to calling your Python script.Andrew Stroz
Hey Adrian, do you have have some recommendations on how to get this working with python 3 and opencv 3?
Adrian Rosebrock
Hey Andrew, I actually have not tried to setup OpenCV 3 on the Raspberry Pi just yet. OpenCV 3 is still in RC phase and until the final version is fully released I’m not planning on doing any tutorials on OpenCV 3 and Python 3. But in general, you should be able to follow the steps I outlined, only using Python 3.
As a side note, if you decide to go with OpenCV 2.4.X, you’ll need to use Python 2.7 as OpenCV 2.4.X does not support Python 3.
Akshit Tyagi
Hey. I am new to RaspPi B+ . In my installation process the file ~/.profile doesnt exist and hence I couldnt update it to new virtualenvs. What should I do?
Adrian Rosebrock
If the
~/.profile
file does not exist, just create it.eliaz
Bello Adrián! Thank you so much for the tutorial ¿ this aplication, open cv & phyton is it compatible with banana pi m2?
Adrian Rosebrock
Hi Eliaz, I do not own a Banana Pi M2 so I have not been able to test out this tutorial with it. Perhaps another PyImageSearch reader can help you with this question.
Dot
Question: I am successfully going into my virtual environment with the commands:
$ source ~/.profile
$ workon cv
However I have to type
$ cd ~/.virtualenvs
in order to import cv2 in python. Additionally, this means that I can’t access any of the sample codes stored in the directory
/home/pi/opencv-2.4.10/samples/python
because when I try to run a sample script (for instance python camera.py) I get the error
” File “camera.py”, line 4, in
import cv2.cv as cv
ImportError: No module named cv2.cv
Any ideas? Thanks!
Adrian Rosebrock
Hey Dot, you definitely should not have to be in the
.virtualenvs
directory to import OpenCV. Go back to Step 10 and ensure that your sym-links are properly setup.Austin Crane
Thanks for this! 1+
Adrian Rosebrock
No problem Austin, I’m glad you found it useful!
phu
i use GPIO library, but GPIO.setup running as root. Can you help me?
Adrian Rosebrock
Hey Phu, as I’ve mentioned in previous comments, I don’t have any experience with the GPIO library so I’m not the right person to ask. However, it seems to be that you should be able to execute the commands detailed in this tutorial under the
root
account rather than thepi
user and they should still work. That would also allow you to install GPIO under root.abanoub emil
hi Adrian i have a problem when i write command workon cv it say command not found .thanks !
Adrian Rosebrock
Take a look at Step 7 again. You likely did not update your
.profile
file orsource
it after updating.Nithin
Hi Adrian,
Thanks for your awesome detailed installation guide.
I have followed all of the steps and finished the make install, only to find that the cv2.so and the cv.py are in the dist-packages folder and not the site-packages folder. And this causes the import cv2 command to fail. Is this then a simple copy and past into the site-packages folder or have done something wrong.
I have an updated ./profile file and and am in cv.
Thanks
Nithin
Adrian Rosebrock
It’s strange that the binaries are in the
dist-packages
directory. I would suggest going back to Step 10 and update the sym-links to use yourdist-packages
directory rater than thesite-packages
directory. You could also manually move the binaries into thesite-packages
directory.Nukul Sehgal
Thanks a lot for this wonderful compilation of tutorial and help provided in the comments !!
Adrian Rosebrock
No problem Nukul, I’m glad it was helpful for you! 🙂
nikko
Hi adrian, how to fix this?
” source ~/.profile
workon cv
-bash: workon: command not found”
Adrian Rosebrock
Go back to Step 7 and ensure (1) virtualenv and virtualenvwrapper are properly installed and (2) you have properly updated your
.profile
file.Joe Landau
In step 9, the admonition to “Important: Make sure you’re in the cv virtual environment ” will be most unclear to those who are not familiar with virtual environments. They won’t know how to “make sure”, won’t have a reference, and will have to go hunting for it.
just sayin’
Adrian Rosebrock
Thanks for the feedback Joe, you’re definitely right. I’ll make sure to make this point more clear in future revisions.
Neal Yang
cmake: commend not found
How can I solve this problem?Thanks a lot!
Adrian Rosebrock
Please see Step 1 of this tutorial. You need to install cmake.
Neal Yang
Thanks a lot! I have another problem here, when I do the “pip install numpy” ,there is something like” insecure platform worning” message,,and the install just stopped somewhere, I can’t fix it ,have to go on the the next step and have a try . As a result, I can’t find the two files anywhere, both site and pisc-pakage…….tried several times even erase the SD card .what should I do ?Thanks a lot.I’m using pi 2 by the way
Adrian Rosebrock
The insecure warning is related to the
urllib3
that pip uses to download packages to install. That all said, it’s just a warning and should not stop the NumPy package from installing. NumPy can definitely take a few minutes to install, so I would make sure that it’s compiling before quitting the script.orta
Hi adrian~
I faced this problem:
ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so
ln: failed to create symbolic link `cv2.so’: File exists
and
>>> import cv2
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named cv2
Could you please give me some sugguestions?
thanks!!
Adrian Rosebrock
Please see my response to Wei’s comment (June 2, 2015 at 6:54 pm) below, he asked the exact same question.
Wei
Hello, there are two problems for help~
ln: failed to create symbolic link `cv2.so’: File exists
>>> import cv2
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named cv2
Adrian Rosebrock
If the symbolic link already exists, I assume that you tried to create it before? Just use
rm cv2.so
in the virtual environment directory to delete the sym-link and then re-create it. Give that a try and see if it fixes your issue.spex
Hi Adrian
After checking on the web my 153.3kib file is a little bit on the small side, not sure how that happened, i’ve tried the instruction maybe 5 times. Anyway i downloaded it [OpenCV] in a browser 87.4 mib and copied it across, writing over the old one. Currently building, all looking well. 😉
Adrian Rosebrock
Awesome, glad to hear it! Make sure you are copying the complete URL from the
wget
command, it sounds like only part of the URL was copied and pasted into your terminal.Mike Brandt
Nevermind. I got it working. Thanks for such a fun a detailed tutorial.
Adrian Rosebrock
Awesome, I’m happy to hear that everything is working for you Mike!
Kronos
Now that Open-CV has just released 3.0 with support for Python 3.0, does this process change much for installing on the RasPi using Python 3.x?
Adrian Rosebrock
It changes a little bit, mainly to the
cmake
command and constructing your virtual environment, but that’s it. I’ve already installed OpenCV 3.0 on my Raspberry Pi, so in the coming weeks I’ll have a new tutorial published. Be sure to look out for the blog post on Monday, June 8th that will detail the changes to the PyImageSearch blog now that OpenCV 3.0 is released.karthik
hey Adrian,
I’ve have successfully installed opencv on my pi! thank you for the tutorial, I would like to know if i need to create a virtual environment every time i login to my pi to use openCV? also is there a way to use opencv in python on the raspbian GUI…?
Adrian Rosebrock
Hey Karthik, you don’t need to create a virtual environment each time you login to your pi, just use the
workon
command to access thecv
environment, like this:$ workon cv
And this will drop you into your
cv
virtual environment. And you can certainly access thecv
environment from the GUI, but you’ll still want to use the terminal application.Myrijam
Hear Adrian,
thanks a lot for this tutorial – i was able to go through it without any errors. But I am stuck on 2 aspects involved:
a) installing PyFirmata unter the virtual environment so that I can send commands to an Arduino
b) using that virtual environment inside LDXE. I tried updating the profile as described in the posts, but it does not seem do work.
For Firmata I used
sudo apt-get update && sudo apt-get install python-serial git-core
git clone git://github.com/tino/pyFirmata
cd pyFirmata
sudo python setup.py install
but id did not work 🙁
Any help would be greatly appreciated… 😉 Thanks
Adrian Rosebrock
Hi Myrijam, thanks for the comment. But unfortunately I’m not familiar with PyFirmata or LDXE. Perhaps another PyImageSearch reader will be able to help you out with that 🙂
Is it possible to install PyFirmata without the sudo command and install it into the
cv
virtual environment? That would make OpenCV available to PyFirmata.If not, you can just create a new virtual environment under the root user — that way OpenCV is exposed to the root account as well.
Alain
Hi Adrian,
I’ve been following your blog posts and it’s been great so far. However on step 9 as I was trying to setup the build (typing up line 3) it gives me a CMake Error: The source directory “home/pi” does not appear to contain CMakeLists.txt.
What can I do to resolve this? Thanks again for sharing your knowledge.
Adrian Rosebrock
Hey Alain, be sure to go back to Step 9. You need to be in the
build
directory before running the cmake command.Alain
All sorted now! I did not unzip the OpenCV file. Thanks for the two tutorials I have gotten everything working. Also just bought your book to read, so far so good!
Adrian Rosebrock
Nice, congrats on getting OpenCV installed Alain! And enjoy the books! 😀
Igor
very nice! thank you very much!
Adrian Rosebrock
No problem, I’m happy it worked for you!
Tyrone
Hello I’m new with the raspberrpi, and I’m looking forward to buying you’re book so I can understand opencv with the raspberrypi. But first I want to install open cv and test it with the pi cam. I’m stuck on Step 7 where it’s saying to update you’re -/.profile file to include the following lines:
How do you access the -/.profile to add 1-3. I’m sure this is easy. But I can use your help.
Thank you.
Adrian Rosebrock
You can edit the
~/.profile
file using your favorite editor such as vi, emacs, or any other editor listed here.Stefano
Hi…you are my hero?
I have only question…
All operation after step7 (install virtual env) must be on CV virtual env?
Thanks
Adrian Rosebrock
Correct, executing your Python scripts or installing new packages via pip must be done within the
cv
virtual environment.
Stefano
Perfect Works for me….Perfect tutorial
Adrian Rosebrock
Awesome — I’m happy it worked for you Stefano!
Njin
Thank you for this tutorial page.
Cathush
hello Adrian! I followed your steps carefully but i have not updated .profile to include those two lines you mentioned in step 7. But um sure open CV compiled with in cv virtual environment. open cv got installed successfully but when i cant import cv2 in python shell. So i tried to include those two lines in the .profile later but um not sure where to put exactly because there are ‘if[]’ commands also. If i paste those lines just above the ‘if []’ will it be okay ? and i couldnt figure out how to save that file.
Do i have to follow the other steps after step 7 again or will it work just updating .profile ?
Adrian Rosebrock
I would suggest placing the edits to the
~/.profile
file at the bottom. After you make the edits and save the file, you’ll need to re-run the commands following Step 7, including sym-linking thecv2.so
file into your virtual environment.Remi Theriault
Hi Adrian,
Step 10: Sym-link OpenCV into the ‘site-packages’ directory. First command (cd) results in: bash: cd: /home/pi/.virtualenvs/cv/lib/python2.7/site-packages/: No such file or directory.
OpenCV installed in expected directory. Tried to reinstall virtualenv and virtualenvwrapper but I get: Requirement already satisfied. ~/.profile also updated successfully to include the three relevant lines, AND reloaded. Computer vision virtual environment created (command prompt displays: (cv)pi@raspberrypi ~/opencv-2.4.10/build $).
I feel like this is a stupid mistake but can’t seem to find a solution.
However, I noticed that files and folders containing virtualenv and virtualenvwrapper can be found in /usr/local/lib/python2.7/dist-packages.
Adrian Rosebrock
That’s interesting that the virtual environment directory cannot be found. Try doing
echo $VIRTUAL_ENV
in your terminal while in thecv
virtual environment and try to figure out where your virtual environment was installed at.Remi Theriault
Thanks Adrian, that did it (I had made the following typo while editing the .profile file: …HOME/.virtuallenvs). I normally copy paste directly from your tutorial in my terminal to avoid this kind of mistake, but I was not able to copy paste adequately from an external application in vi (new at vi), so I had written it manually. Thanks again for this quick answer and awesome tutorial 😉
Adrian Rosebrock
No problem, I’m glad it’s working for you now! 🙂
Vin
Hi Adrian
I finally got everything installed properly and everything works. But I have a question about the workon cv command. Is it necessary to always enable the virtual environment before using python? I see I can run python and import the cv2 without any problems, without the virtual environment.
Thanks
Adrian Rosebrock
Hey Vin, congrats on getting OpenCV installed and working, that’s great. When installing OpenCV, the
cv2.so
file (your OpenCV bindings) are installed in thesite-packages
directory of Python that is system-wide. However, I do still recommend using virtual environments and theworkon
command, just in case you ever want to install any other packages into thecv
virtual environment. This will ensure that your system Python is kept neat and tidy.Vin
Oh I see, so its for better practice. I was thinking without the virtual environment I wouldn’t be able to do certain things as well, but thanks for clearing that up.
Oh one thing though, in my case the cv2.so and cv.py files were installed in the dist-packages directory. I had to copy them manually to the site-packages folder in order to carry on with your steps. Would this cause any problems in future? And does it mean I did something wrong? I was so sure I followed every step you showed exactly as it were, and I did it all in a single session.
Thanks again
Adrian Rosebrock
You can do anything inside a virtual environment that you can using the system version of Python — the added benefit is the better organization, the ability to have multiple Python environments (and versions), and completely independent and non-conflicting libraries.
As for the
dist-packages
question, other readers have ran into this as well. It’s definitely not a problem, just for whatever reasoncmake
generated build files that instructed the system to install OpenCV into thedist-packages
directory rater thansite-package
. You likely did not do anything wrong, it’s likely just a peculiarity of your system. Regardless, you did the right thing by moving it to thesite-packages
directory.Vin
Ah ok, I just found it a bit tedious repeatedly typing the source profile and workon cv commands every time i wanted to work on something. But I understand the benefit now.
Awesome, so no problems then.
Thank you for responding!
Adrian Rosebrock
No problem, glad to help out 🙂
jack
Hi !
I have a little problem.
I did the tutorial, and at the end, it worked well !
However, I closed the window, and opened an other, and tried :
source ~/.profile
workon cv
–> bash: workon: command not found
And I do not understand why it worked one time…
Do you have an idea ?
Adrian Rosebrock
Hey Jack, that is quite strange. But it sounds like your
~/.profile
file was not updated properly. Definitely check again and make sure that the changes have taken affect.jack
What do I see Inside ?
Adrian Rosebrock
See Step 7. You should have added the following lines to the your
~./profile
file so thatvirtualenv
andvirtualenvwrapper
can be found:# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
Jack
Thanks a lot ! It is working now ! Maybe, if you can write it in the step 7, as you explain perfectly for me 😉
Otherwise very good tutorial !!
Neilesh
Hey Adrian,
Thank you for the tutorial. I am trying to install opencv on my B+ but on step 10 when I use the ln commands, I get the error that cv2.so is not a directory and cv.py is not a directory. Any tips would help.
Adrian Rosebrock
Hey Neilesh, it sounds like the paths to your cv2.so and cv.py files are incorrect. Check to see where they are installed (you should be able to find out by looking at the output of cmake). You’ll also want to make sure you run
make install
after OpenCV is compiled using themake
command.Neilesh
Thank you for the fix. I just went back and tried make install again and it all worked.
Neilesh
Another question. What are the steps required to use a USB webcam, Logitech c525, that I got working with guvcview without drivers, with opencv.
Adrian Rosebrock
I haven’t played around with any Logitech cameras on the Pi just yet, so I’m not sure about that one. My Logitech C920 just arrived yesterday, so as soon as I get a chance, I’ll be playing around with it. Once I get a chance to set it up, I’ll have some more meaningful comments.
EDIT: My mistake, I thought you were asking how to install the drivers to get the Pi to access your camera. If you are looking to access your webcam, take a look at any of my articles that utilize the
cv2.VideoCapture
function. I also detail how to access the webcam inside my book, Practical Python and OpenCV.Adrian Rosebrock
Awesome, glad to hear it! 🙂
cipri_tom
I’m sorry, I used openCV3, so there is no cv.py. I can’t wait for the new tutorial haha.
However, when I say import cv2 my python crashes with “illegal instruction” :(. Any ideas ?
p.s. you can remove the prev comment
Adrian Rosebrock
No worries! I’ll have a new OpenCV 3 install tutorial with both Python 2.7 and Python 3+ support online within the next few weeks 🙂
Bogomil
Any plans for updating this excellent guide to include installation of openCV 3 to raspberry pi 2?
Adrian Rosebrock
You bet! I’ll have a new OpenCV 3.0 install tutorial for the Raspberry Pi 2 online within the next 2-3 weeks. This guide won’t be updated, but I will be creating a new one. Keep an eye on the PyImageSearch blog as well as this page for more information on OpenCV 3 tutorials, how-to’s, and install guides.
cipri_tom
Cool! I’m killing myself now with getting cmake detect everything nicely.
florin
Cannot find the /.profile file ….
Adrian Rosebrock
Hey Florin, if your ~/.profile file does not exist, create it.
Matt
Thanks for the tutorial and all the great Q&A! I am having a problem when running the test.py. I get the following output (“Example:2828): Gtk-WARNING **: cannot open display:” I’ve double checked my ~/.profile and ensured that I have my CV virtual environment active. I’ve also used the image viewer in X Server to view the image file to ensure it seems okay. This was a completely new install from NOOB. I’m not sure where to look from here. Thanks Adrian.
Adrian Rosebrock
Hey Matt, take a look at the other comments on this thread. You’ll need to SSH into your Pi with X11 forwarding. Your command should look something like this:
$ ssh -X pi@your_pi_ip_address
Notice how i have specified the
PABLITO
Hi Adrian, I want to use RPi.GPIO library with opencv but I can’t , I need to access as root but if I do that I can’t use opencv.
I have this error:
RuntimeError: No access to /dev/men. Try running as root!
Adrian Rosebrock
Hey Pablo, take a look at the other comments on this post. A few other readers are looking to have access to GPIO and OpenCV via root as well. I personally do not have any experience with GPIO so I unfortunately cannot address that question. But I can help with OpenCV: In general, just follow the same install process, but perform the steps under the root account and in the
/root
directory — that way you’ll have an OpenCV install setup for root.PABLITO
Hi Adrian, I’m so grateful for your answer because everything worked fine, i could join RPiGpio library and Opencv. I have another question about how eliminate noise in an image.I’m working with video stream and i need to recognize three figures (square, circle and triangle) in a not controled environment. so I have noise if the brightness change. I’m working with hsv space color and i separate “h” canal to do a mask.
I’m sure that you know how can i solve my problem.
Again Thanks for the last answer.
Adrian Rosebrock
A Gaussian blur is normally used to reduce noise. After reducing noise, I would probably suggest using a simple contour approximation to identify each of the shapes.
Izwan
Can you explain how to do it? join RPiGpio library and Opencv
Adrian Rosebrock
Please see the other comments on this blog post related to GPIO and OpenCV as I’ve answered this question multiple times. All you need to do is launch a root shell, create the virtual environment under the root account, and then install the GPIO library.
Izwan
In general, just follow the same install process, but perform the steps under the root account and in the /root directory — that way you’ll have an OpenCV install setup for root?
then install gpio library?
i will try this but something to make sure, this will make opencv working together with gpio?
Adrian Rosebrock
Yep, that’s correct! And if you already have OpenCV installed, all you need to do is create a virtual environment for the
root
user, install NumPy, and then sym-link thecv2.so
file into thesite-packages
of your virtual environment. Lastly, you can install GPIO as well and you’ll be able to use both GPIO and OpenCV together.mizz1205
Hello,please help me.
I am step9 did $make, however I have opened new window of raspberry LXterminal before this step and started step9.
Is this mean that I am not in cv virtual environment? How do you know if you are in virtual CV?
(your comment…)
“important: Make sure you’re in the cv virtual environment so OpenCV is compiled against the virtual environment Python and NumPy. Otherwise, OpenCV will be compiled against the system Python and NumPy which can lead to problems down the line.”
Raspberry is now doing compiling like below..
“[ 5%] Building CXX object modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/undistort.cpp.o
[ 5%] Building CXX object modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/thresh.cpp.o
[ 5%] Building CXX object modules/imgproc/CMakeFiles/opencv_imgproc.dir/src/sumpixels.cpp.o”
I am wondering if I am on right truck.
Adrian Rosebrock
Anytime you open up a new terminal, login, reboot, etc. you’ll need to ensure you are in the
cv
virtual environment by using the following command:$ workon cv
If done correctly, your terminal will change slightly and you’ll see the text
cmake
inside thecv
virtual environment — you can runmake
outside of the virtual environment, that shouldn’t be an issue.Jack
I would do a `dist-upgrade` in step zero rather than an upgrade. The difference is that `dist-upgrade` will remove packages and update all packages.
Girish Kumar
Hi Adrian,
HAve you tried Open CV on Raspiberry PI-2 B+ with more than one Web-cam ? I would like to try this out, just want to check whether you had attemted this before or not
Purpose is just motion detection
Regards
Girish
Adrian Rosebrock
Hey Girish, I have not used the Raspberry Pi with more than one webcam. But it should be pretty simple using the
cv2.VideoCapture
function. You can usecv2.VideoCapture(0)
to access the first webcam,cv2.VideoCapture(1)
to access the second, and so on.Nichten
Hi,
I have done all steps twice and still get nothing. I have clear install of Raspbian and every thing works fine if i have close terminal window. after closing it and reopen i cannot type workon cv. I have tried everything what was said in comments. What i am doing wrong?
I have also tried creating new virtual enviroment named cv and i get error that comment not exist :/.
Adrian Rosebrock
Hi Nichten, it really sounds like your
~/.profile
file was not updated correctly. Go back to Step 7 and ensure you have (1) updated it correctly and (2) have reloaded it using thesource
command.Nichten
Unfortunately I have tried it again :/. I have no idea what to do more… I have also tried modifying ~/.profile with vi and nano but nothing helps me…
Adrian Rosebrock
Hi Nichten, this could be a silly question, but have you made sure
virtualenv
andvirtualenvwrapper
installed? If after updating your~/.profile
file with the correct contents (and you still can’t access the virtual environment), then the only remaining suggestion is thatvirtualenv
andvirtualenvwrapper
have not been installed correctly.Mesut
Hello Adrian
I preformed all steps by copying the exact bash codes you mentioned above. step by step without modifying every single word, I even compiled the openCV library three times but when I’m going to give a test it says:
/**********************************************
>>> import cv2
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named cv2
>>>
/**********************************************
I’m now going to hit my head to a wall! I can’t realize what’s the problem could you please help me?
Adrian Rosebrock
Hey Mesut — please see the other comments on this blog post. The most likely cause is (1) your
~./profile
was not updated correctly, (2) the~/.profile
was not reloaded, (3) thecv2.so
andcv.py
files were not correctly sym-linked into thecv
virtual environment, and (4) not being in thecv
virtual environment when trying to import OpenCV. Please see the other comments for more information on each of these cases.Mesut
Thanks and hi again, I almost read all of the comments on this page, and I updated my profile as you mentioned. Used source ~/.profile many times and cv.so and cv.py are both symbolic-linked perfectly because now I tried again and it said: “failed to create symbolic link `cv.py’: File exists”
I have done these all in cv virtualenv because the workon command works correctly and I see a ‘(cv)’ right behind of my username shown in PuTTY.
Also after opening ‘Python->help()->modules()’ there are cv and cv2 modules but still can’t import’em 🙁
So what’s wrong with this?
Adrian Rosebrock
Hey Mesut, I’m sorry to hear about the continued problems, that’s super frustrating. It definitely sounds like your virtual environments are working which is a great start. If the symlink already exists, I would suggest deleting it and ensuring the path to the files are indeed correct. It could be possible that the
cv2.so
andcv.py
files could have different paths on your system.Josh
Hello Adrian,
Very nice tutorial, thank you for doing this. When on step 11, I get the error “bash: workon: command not found.” I have tried in the ~./virtualenvs/cv/lib/python2.7/site/packages cd and in the regular pi@raspberrypi – $ cd. I have also tried with source ~/.profile. Any help is greatly appreciated. Thank you.
Adrian Rosebrock
Hey Josh — please see the other comments on this blog post, other readers have had similar problems. In most cases the
~/.profile
has not been updated properly.Josh
Hello Adrian,
Thank you for the response, I was able to load the workon command and work withing the cv. However, now when I try to load ~/.profile, it tells me permission denied. Any thoughts?
Adrian Rosebrock
It sounds like you may had edited and saved the file as root. You’ll likely need to change the permissions of the file back to the
pi
user. Read up on thechown
command for more information.Josh
Hello Adrian,
Don’t know how I messed up, but I ended up formatting the SD card and starting from scratch. Got all the way through with no hiccups this time. Thanks a lot for your help! Looking forward to ordering the camera and setting up the motion detector.
Adrian Rosebrock
Nice, congrats on getting it to work!
Sahil Naran
This is very strange, I could not find my cv2.so and cv.py file in neither the dist-package nor the site-packages
However, I located in /home/pi/opencv-2.4.10/build/usr/local/lib/python2.7/site-packages/
I then tried did step 10 the symbolic linking with /home/pi/opencv-2.4.10/build/usr/local/lib/python2.7/site-packages/cv2.so
AND
/home/pi/opencv-2.4.10/build/usr/local/lib/python2.7/site-packages/cv.py
and it worked.
Will this solution lead to problems ahead?
Adrian Rosebrock
That will most certainly work; however, if you ever delete your
opencv-2.4.10
directory than your symlinks will be invalid (since the files they point to don’t exist). In your case, I would suggest explicitly copying thecv2.so
andcv.py
files into thesite-packages
cirectory.Sahil Naran
Thanks for the speedy reply.
Joseph
Hello Adrian! Thanks for your unique way of passing information efficiently to your readers. However, at step 10, the command cd ~/.virtualenvs/cv/lib/python2.7/site-packages/ it said no such file or directory but when i checked the path cv was installed in it says the directory exists. I’m wondering why i cannot utilize the cv virtual environment.
also, the workon cv command did not work.
Adrian Rosebrock
Hey Joseph, I am sorry to hear about the error. However, I would take a few minutes and read the rest of the comments on this post. If the
workon
command does not work, then it’s likely that either virtualenv and virtualenvwrapper have not been installed, or your~/.profile
has not been properly updated, or it needs to be reloaded.jack
hello adrian,
i have a problem, i can not import “serial” library in opencv virtual environnement. Do you know why ?
have a good day !
jack
Adrian Rosebrock
Hey Jack, I don’t use the serial Python package, but it sounds like you have not installed it inside the
cv
virtual environment. Popping into thecv
virtual environment and then installing it via pip should take care of the issue:$ workon cv
$ pip install pyserial
Jack
Thanks a lot Adrian ! It is working ! 🙂
Have a good day !
John
hi Adrian, I have installed openCv sucessfully with this tutorial! I want to implement opencv with a PWM driver which uses smbus module. However, the virtual environment which opencv was operating in does not include smbus module.
Is there a method to add smbus into existing virtualenv?
Adrian Rosebrock
Hey John, take a look at the other comments on this blog post. I would also read up a bit on Python virtual environments.
The
cv
virtual environment is entirely independent of your system install and you can install whatever Python packages you want into it. I have never used smbus before, but if I wanted to, I would just enter thecv
virtual environment and let pip install it:$ workon cv
pip install cffi
John
Hey Adrian! I searched for a solution for days, and your reply just inspired me to reach a solution!! Many thinks!
The code I have used:
$ workon cv
pip install smbus-cffi
John Tran
Mine doesn’t work until I’ve used:
workon cv
sudo apt-get install libffi-dev
pip install cffi
Thanks
Antonio
The workon command does not work
Adrian Rosebrock
Hey Antonio, please see the other commends in this post — there are many reasons why the workon command is not working, the most likely ones being that your
~/.profile
file has not been updated and reloaded.Cédric Verstraeten
Instead of motion you can also use Kerberos.io, it’s also open-source and a lot more user friendly to install and configure. You can find more information on the website.
Adrian Rosebrock
Wow, Kerberos is pretty awesome — thanks for mentioning it.
Mike
Hello,
Very nice tutorial. All set up perfectly. Is there any way to set it up so i can leave it in my house to record all day and have access to the live feed via cell phone?
-Mike
Adrian Rosebrock
Hey Mike, that’s certainly possible! You might want to take a look at this post on home surveillance to get you started.
Mike
Hi Adrian,
This info is awesome. Thanks a lot! Just a few questions, nothing to pressing. 1) is there a certain order I should follow? In the article you directed me to, there were like 5 links to other pages all setting this up, Should I do 1 thing before the next? I don’t want to mess the order up and screw everything up. 2) is it possible to set this up BEFORE getting my camera? I am about to order it, but would like to plug and play. If I have to wait to install the camera prior to coding, that’s perfectly fine, just want to make sure. Thanks a lot for your help.
Mike
Adrian Rosebrock
Hey Mike, the first step you’ll need to do is setup your Raspberry Pi and the camera module. This step needs to be done first, you really can’t move forward without first installing OpenCV on your Pi and confirming you have access to the camera. Form there, the tutorial is entirely self-contained and you’ll be able to follow it straight through.
Talha
Hey man thanks for the tutorial.
Running into an issue when running the long cmake command. I made sure to have the two dots to check in the previous dir but it says “/home/pi” does not appear to contain CMakeLists.txt
Went back up to step one and tried reinstalling it but realized im getting two errors like so:
E: Unable to locate package build
E: Unable to locate package essential
Any help?
Adrian Rosebrock
Hey Talha, I would suggest going back and making sure you are copying and pasting your commands correctly. There is supposed to be a dash in between the name:
build-essential
, notbuild essential
.Paul Conroy
Adrian,
Awesome tutorial! I’ve never used a Raspberry Pi before and am new to Linux, but the whole install and setup ran pretty seamlessly.
One thing I note, for other users. I didn’t have a USB keyboard or USB mouse, so I had to do a “headless” setup of the Raspberry Pi initially. This entailed first editing the NOOBS setup SD to just select Raspberian OS and do a Silent install.
Next, I used SSH to login to the RasPi and do the setup of OpenCV. the only issue I had was that the SSH connection kept timing out on the Make. Each time it did, I went back in and did:
Workon cv
cd cd opencv-2.4.10
cd build
cmake xxx
make
and make picked up where it had left off.
Just out of curiosity, is it possible to stop the SSH session from dying? I edited the .SSH on my Mac and the SSH_Config on the RasPi with what was supposed to be variables to send a ping every 2 minutes, but it didn’t work?
Cheers,
Paul
Aaron
Adrian,
I am having problems at Step: 9. After entering the “cmake” command with all of the options…I get a whole lot of errors of this sort:
“CMake Error: Cannot open file for write: /home/pi/opencv-2.4.10/build/samples/cpp/CMake Files/tutorial_hull_demo.dir/build.make.tmp
Cmake Error: : System Error: No such file or directory”
I can’t seem to figure out what I did wrong…none of the other posts deal with this issue. Obviously I am new to Unix, but excited to get started learning OpenCV…any help would be great.
Aaron
Reinstalled OS…everything working fine now. Problem solved.
Adrian Rosebrock
Nice, congrats on fixing the problem Aaron 🙂
Yousif
Hi Adrian,
I am trying to import cv2 as shown in step 11 but the module doesn’t seem to exist. I tried running cmake in step 9 but that doesn’t seem to work either. Do you know what the problem might be?
Thanks,
Yousif
Adrian Rosebrock
Hey Yousif — there could be a lot of reasons why the module is not importing. I could read through the rest of the comments on this post and see which ones apply to you. If CMake is not working, then I would consider restarting from Step 0 and following the instructions exactly.
Johnny
Nice Adrian. I appreciate the details.
Johnny
Sahil Naran
Good day
I have a file named a.py
when I use : python a.py my opencv works
However,
when I use sudo python a.py I get import error: No module named cv2. I need to use sudo to control my pins
Adrian Rosebrock
Please read through the other comments on this post related to GPIO and sudo. The trick is that you need to launch a sudo shell and re-create the
cv
virtual environment, but for the root user instead. From there, you can just open up a root shell, enter thecv
environment and runpython a.py
(again, as root) and the script will work for you.Sahil Naran
Thank you Sir!
Just to be clear –
I enter the sudo shell by using sudo su and start with step 7?
Sorry, linux is not my strong point
Adrian Rosebrock
Yes, that is correct. Start at Step 7 in your root shell, create your virtual environment, install NumPy, skip Step 9 since OpenCV is already installed on your system, and then do Step 10. When do you Step 10 make sure you are creating the sym-link in the virtual environment for the root user.
Sahil Naran
In shell:
root@raspberrypi: python a.py works
“Use in cv”
root@raspberrypi: source ~/.profile
root@raspberrypi: workon cv
(cv)root@raspberrypi: python a.py
(cv)root@raspberrypi: No module named RPi.GPIO
Adrian Rosebrock
You need to install the GPIO package into the
cv
virtual environment for the root user:$ pip install rpi.gpio
Humberto
Hi, excellent tutorial!!
I´m a question, how to setup python-smbus and 12c-tools in the virtual env?
Adrian Rosebrock
Hey Humberto — please see the previous comments on this post. I mentioned to another reader how to install python-smbus inside the virtual environment.
jpiat
To get max performance out ot the PI2 with openCV built-in functions your need to add the :
-D ENABLE_NEON=ON
to the Step 9 “cmake” command. On the B+ the flag :
-D ENABLE_VFPV3=ON
could also improve built-in functions results. Beware that with those flags you won’t be able to move your install from a B+ to a PI 2. Those flag can make a bigg difference depending on the functions.
Adrian Rosebrock
Thanks for the tip, I’ll be sure to try these out!
Antonio
Is this actual on the Pi 3?
ilan
Thanks for the incredibly in depth tutorial. If I can make one recommendation, step 7 is a bit confusing for people new to linux that might not realize it is in fact a text file that needs to be edited. At least it was for me.
I do have a question: After completing all steps successfully, this whole installation uses up 1.9GB of space on my SD card, 1.7GB of which is used by the “build” folder we created. Is this folder still necessary after installation or can we delete this to save space? I am using an 8GB card.
Adrian Rosebrock
After you have completed the installation you can delete the
build
directory and the source code directory itself.Tang
Hi Adrian,
I can’t seem to get pass the mkvirtualenv command. Somehow it says command is not found.
pi@raspberrypi ~ $ mkvirtualenv cv
bash: mkvirtualenv: command not found
*** for the moment I have skipped that step and is now at Step 9.
How do I get the mkvirtualenv to work properly?
Thanks in advance.
Adrian Rosebrock
Hey Tang, it sounds like your
.profile
file was not updated correctly. Go back to Step 7, ensure it’s updated, and then run thesource
command. Also, you do not want to run thecmake
command in Step 9 if you are not in thecv
virtual environment.Francois
Hey Tang,
I’m having the same problem, I looked at Adrian’s response, I edited my profile but I have no idea how to reload it, do you remember how to do that?
Also when I use this command : sudo rm -rf ~/.cache/pip
nothing happens
did you have the same issue?
Adrian Rosebrock
Pleas see Step 7 of this post. Reloading your profile can be done via:
$ source ~/.profile
PzCampus
make sure you are not running “source .profile” command with sudo
Adrian Rosebrock
You can use the sudo command, but I would just make sure it’s the full path to the
.profile
file:$ sudo source /home/pi/.profile
haim
Hi,
i follow the install tutorial and all went well.
then i run the picamera tutorial, it worked well at first but after i terminate the script i got error when i tried to access the camera again.
(not related but it was: mmal: mmal_vc_component_enable: failed to enable component: ENOSPC – if you know somethiong about this…)
so i reboot the device and after the reboot i can’t get “workon cv” to work.
i get error: “-bash: workon: command not found”
i tried: “source ~/.profile” but it doesn’t help.
this make me wonder:
A. did all the work and hours in compiling are lost?
B. why i need all this virtual thing?
C. how can i fix this?
some background:
raspberry model B+, kernel update to 4.X, raspberian OS, working via Putty ssh and Xming.
Adrian Rosebrock
That is very strange behavior — I would check your
~/.profile
file and ensure the changes made from Step 7 are still present. It would be very odd, but it sounds like during the reboot the contents of your~/.profile
file were reverted or changed.OpenCV and the associated packages are still installed, I wouldn’t worry about that. I would just make sure that your
.profile
file didn’t change somehow.Won Kyoung Jeong
Hello Adrian!
I have a problem with step 7
You said that “update your ~/.profile file to include the following lines.”
# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
How can I do? Should I type those through python, Lxterminal??
Where should I type those??
Adrian Rosebrock
Open up your
~/.profile
using your favorite text editor such as vi, vim, emacs, etc. and then insert those lines.Won Kyoung Jeong
Oh! I’m glad to thank to you.
I did it yesterday. And I had to know how to do with vi editor.
So I found it and I went to step 10.
Won Kyoung Jeong
Thank you very much…
But…
How can I operate this program ,opencv2.4.10 ?? Just through Lxterminal??
And where did you get the test.py??
Adrian Rosebrock
Yes, you use your terminal to execute Python scripts that import OpenCV. The
test.py
script was created by writing a simple script to load an image from disk and display it to my screen. I would suggest reading this post to get you started.Girwan
Hello Adrian,
I followed your steps and completed all.Updated the ~/.profile,there are two files named cv,py and cv2.so on the directory: usr/local/lib/python2.7/site-packages but when i execute pa python script i get an error ImportError: No module Named cv2.
what should i do about it? Please help.
Adrian Rosebrock
Make sure you are in the
cv
virtual environment before trying to import OpenCV.Girwan
Yes,it shows the (cv)….after creating virtual environment. Then i am trying to run program from the python ide pre installed on the raspbian and get the same error.Or I should run .py file from the virtual environment itself if so how do do it please give detailed steps ..i am
new to python and raspberry pi.
Thanks.
Adrian Rosebrock
If you are in the
cv
virtual environment and still having issues importing OpenCV, I would go back to Step 7 and make sure that thecv2.so
andcv.py
files are properly sym-linked into the virtual environmentsite-packages
directory. It sounds like you have everything working okay, it’s just that the sym-link are not in the virtual environment.Girwan
I got it. I was trying to run .py files from the system python IDE not the virtual (cv) environment…
…and why don’t we install the open cv and other dev tools against the system python..??..being curious…
And Thank you so much for great tutorial.
Adrian Rosebrock
You certainly can install OpenCV and other Python packages against the system Python; however, I don’t recommend it. It’s much wiser to use Python virtual environments that are entirely sequestered from each other. For example, suppose you installed v1.8.1 of into your system Python. However, 10 months later, there is some computer vision or machine learning package that requires NumPy 1.7.8. Do you change your current system setup? Risk breaking scripts? Of course not! Just create a new virtual environment install the older verison of NumPy, and you’re ready to go!
armin
Hello
Have anyone used sift algorithm related functions implemented in opencv in RPi2?
Is it possible to process more than one VGA image per second with sift and keypoint matching related functions ?
Thanks.
Adrian Rosebrock
Are you referring to the DoG keypoint detector or the SIFT local invariant descriptor? In either case, both are unsuited for real-time matching, especially with the Pi. Detectors like FAST and binary descriptors like BRIEF, BRISK, ORB, and FREAK are much better suited for this type of task.
I think this question could also make for a good blog post in the future 😉
armin
My final goal is finding matched key points between two captured images for some specific use.
I don’t have access to RPI2 now, in fact i want to choose between some of available sbcs(beagle bone, RPI, cubie board,…) for doing this task.
how can i decide between single and multi core processors for this task?will multi core processing be helpful for me?
Adrian Rosebrock
Multi-core is really only useful if you can efficiently distribute your process between multiple tasks (obviously). When researching between the Raspberry Pi, Beagle Bone, etc. I would also keep in mind the problem you are trying to solve. If you can efficiently distribute the process over multi-cores, then the Pi 2 would be a great route to go.
Izwan
How i can do features matching with this setup (opencv 2.4.10)?
match? or…..?
Please advice.
Thanks.
Adrian Rosebrock
I cover feature matching applied to recognizing the covers of books inside Practical Python and OpenCV.
pradeep
Hello Adrain,
Could you please advice, how to efficiently distribute the process over multi-cores on raspberry pi2.? If there is any video link, that would be very helpful…
Adrian Rosebrock
It’s a bit of a pain, but you can use TBB when compiling OpenCV to utilize multiple-cores. Another great method is to utilize “threading” where you distribute certain processes (such as reading frames from the camera) across multiple cores. I’ll try to do a tutorial on threading and how it can optimize various operations within OpenCV in the future.
mobin
Hi adrian
I want use autostart,i have to use it code:
sudo nano /etc/xdg/lxsession/LXDE/autostart
and edit:
@lxpanel –profile LXDE
@pcmanfm –desktop –profile LXDE
@xscreensaver -no-splash
@/usr/bin/python /home/pi/test.py
but befor run test.py,i how ran workon cv?
Adrian Rosebrock
I’m not familiar with autostart, but you just need to (1) run
workon cv
to drop into thecv
virtual environment, (2) change directory to where your code lives, and (3) execute it.John Tran
Hello Adrian,
I have similar concern as mobin. I’d like to make Pi to plug & play a python script (eg. taking a photo in every a min). Normally, I need to open the terminal and type:
@ source ~/.profile
@ workon cv
then I have (cv) @ : python mycode.py
Since your instructions on using opencv + python is very rock and special, I haven’t found any info to solve this problem. I’ve found many way to run a script at start up, but none about auto accessing to virtual environment.
Would you give some advice?
Thanks
Adrian Rosebrock
Having a script run at startup is actually quite simple. The first step is to create a cronjob that runs on startup. Have the job start a script named
myscript.sh
.Inside
myscript.sh
, source the.profile
, run theworkon
command, and then execute your Python script.The trick is that instead of calling your Python script at startup, you’re instead calling a shellscript.
I hope that helps!
John Tran
Thanks for great advice. I’ve tried that, but I might be having problem with opencv. I tested with many my python code, it was just working good for not using import cv2. For eg.,
well-worked script:
source ~/.profile
workon cv
python code_without_using_openCV.py
NOT working script:
source ~/.profile
workon cv
python code_with_using_openCV.py
However, once I ran the shellcript manually (by typing /home/pi/autoscript.sh, the 2 cases worked fine.
Would you give some idea?
Thanks
Adrian Rosebrock
Check to see if your shellscript is being executed as root or the pi user. If it’s being executed as root, you’ll need to update the shellscript to switch to the
pi
user. From there, thesource
andworkon
commands will work.John Tran
Hi Adrian,
I’ve finally figure out the problem. First, the method to add “source ~/.profile and workon cv” along to the script is failed since we’re using the virtual len. Here is my solution:
create a shellscript.sh contains those lines:
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
workon cv
python /home/pi/test_image_using_openCV.py
—-
THEN go to file manager–>Ctrl + H to show hidden files. Open .bashrc file using any text editor. Add this line add the very bottom:
source ~/.shellscript.sh
Finally, save the file, and using the crontab to executive the lxterminal at start up.
Thanks
Adrian Rosebrock
Thanks for sharing John! It’s interesting that the
.bashrc
file had to be edited rather than.profile
for this particular issue.Vivek
After Step 6,
I ended up tying:
$ sudo pip install virtualenv virtualenvwrapper
$ sudo rm -rf ~/
And now I cannot access anything. What am I supposed to do? Also can you elaborate upon how to edit the profile file?
Adrian Rosebrock
Hey Vivek — Ouch, if you executed
sudo rm -rf ~/
then you wiped out your entire home directory. It’s not a good idea to usesudo
andrm
in conjunction with each other unless you are sure of what you’re doing. I would suggest reinstalling NOOBS/Raspbian on your Pi at this point.As for editing the
~/.profile
file, any text editor will do such as vi, emacs, or an editor with a GUI.Tang
Adrian,
I think vi is difficult for person who has just stated playing with linux.
When I first tried to edit the .profile, I had used leafpad. But leafpad had picked up the wrong .profile file.
I think it is best that you recommend nano…. by issuing sudo nano immediately after the LXTerminal is launched.
… it is just my suggestion.
Tang
Hi Adrian,
can i run python idle from the virtual environment?
Adrian Rosebrock
Of course! Just start the
cv
virtual environment and then open up Python:Tang
Adrian,
But that is not running from idle.
That is running from the command prompt.
When I was in the CV environment, I typed idle to launch the python idle.
Then I keyed in
import cv2
and the response inside idle was that there is no such library
Adrian Rosebrock
Oh, you’re talking about the GUI version of IDLE, not the command line version of IDLE. I honestly never use the GUI version of IDLE, so I’m not sure about that. If you would like to use a GUI along with the OpenCV library, I suggest installing ipython notebooks which is basically a super-charged version of IDLE that can run in your browser.
Oren
when your on the workon (cv) prompt type
python -m idlelib.idle
see https://stackoverflow.com/questions/4924068/how-to-launch-python-idle-from-a-virtual-environment-virtualenv
Girwan
Hello Adrian,
I am facing problems on getting access to the GPIO pins from the virtual environment (cv).I am not being able to run a .py program with import GPIO as GPIO from inside the (cv) if i do not use sudo command and if i do so i can not import cv2 library…
Thanks in advance.
Adrian Rosebrock
I answer this question multiple times in multiple comments on this post. Please see the other comments. (cmd + f/ctrl + f for mentions of GPIO).
Fran
Thanks! It was very useful. I am wondering how neat would be a tutorial using miniconda instead.
http://www.continuum.io/blog/new-arch
Kister Genesis Jimenez
Have you tried adding -j4 in building openCV?
I used “make -j4” just trying out if parallel support is available in the build script. it did not produce an error and I think it is faster than when I tried without the -j4.
Adrian Rosebrock
Indeed adding
-j4
during yourmake
command can increase compilation speeds since it allows the Pi to use multiple cores.Ragav
ur procedure worked succesfully… after doin tht i closed the terminal and again opened the terminal and did the step 11.. it shows bash: workon: command not found
Adrian Rosebrock
Each time you open up a terminal you need to run
source ~/.profile
to ensure its loaded correctly. From there,workon
will work without an issue.Ken
Hi Adrian,
I have been working through your excellent tutorial on installing OpenCV with Python 2.7 on a Raspberry Pi 2. One issue that no one has mentioned is way back at step 2. When I try to install the libraries listed I get the following:
libtiff4-dev has no installation candidate
When I try to substitute with libtiff5-dev I run into dependency issues. I am new to the raspberry pi, but I am really surprised that no one has brought this up, since I am starting with a clean version of raspbian and I can’t believe I am the only one this has happened to.
Adrian Rosebrock
Hey Ken — are you by chance using Raspbian Jesse? I have personally not had a chance to try Jesse out yet, but I have received a couple issues about the error related to
libtiff5-dev
. I’ll try to get Jesse installed on one my micro-SD cards this weekend and see what the error is.That said, if you can install Wheezy on your card, this tutorial will work without an issue 🙂
Ken
Hi Adrian,
You were right; Raspbian Wheezy worked just fine. I originally installed Raspbian using NOOBS, and Jesse is the version that is highlighted. Its probably worth mentioning that at the start of the tutorial.
Thanks
Ken
Dat
Hi Adrian
why i can’t not “workon cv”?
everytime i type : workon cv
then: bash workon command not found
i google it but cant figure that out
would you help me?
thank you
Dat
Adrian Rosebrock
Hey Dat — I’ve covered this question many times on the comment thread to this post. Please do a ctrl+f and search for “workon” on this page. Again, I’ve addressed the many reasons why in other comments.
decoo
Hi,
can you update your tutorial to work with newest rasbian image?
Adrian Rosebrock
Just to clarify: are you referring to Raspbian Jesse?
Bruno Cesar
Hey, I’d like to know if this would be possible with a USB camera.
Where I live the CSI camera is pretty expensive, and I’d like to avoid having to buy it.
Great post, thanks for your work.
Bruno Cesar
Adrian Rosebrock
You can use a USB camera with the Raspberry Pi, but keep in mind that only a few of them work right out of the box without installing any extra drivers. This list on verified webcams should help get you started.
Rusyadi
Hi Adrian,
I just want to know, can I use raspberry pi and openCV for detect an object ?
Thanks
Adrian Rosebrock
You most certainly can! Be sure to start off by reading this post on accessing the Raspberry Pi camera. From there, you can modify other tutorials on object detection to work with the Pi. Or you can take a look at my book, Practical Python and OpenCV where I cover it as well.
Francois
What’s up Adrian?
I have a question concerning step 7…I have no idea how to access the file i’m supposed to be editing. Do you mind giving me step by step instruction on how I can do that?
I’ve only been working with the pi for two weeks, and to be honest i’m not that knowledgeable with regular computers to start with except for the basics but I’m learning as i go.
Adrian Rosebrock
Hey Francois — please see my latest Raspberry Pi install tutorial where I have video instructions on how to edit your
.profile
file.Francois
Thanks for the reply, I figured everything out after doing a little googling, I turned off the FFMPEG in the make command, after that it was smooth sailing. You have taught me a lot with your tutorial, thank you good sir
Adrian Rosebrock
Awesome, I’m glad it worked for you Francois! 🙂
Kevin
hello Adrian!
I have a quetsion concerning step 9.
when I enter the command cmake then receive the error “bash: cmake command not found”
I’ve done all the steps like incense guide.
Adrian Rosebrock
Go back to Step 1 and make sure you have successfully ran the
apt-get
command — this will install CMake for you.pradeep
Hello Adrain,
I am using cvBlob in my project. Do I need install it separately or it will be installed while installing Opencv.?
Thank you
Adrian Rosebrock
I have not personally used cvBlob before, but in order to use it, you will need to install it separately.
Jorge
Hi, i’m installing opencv on a rpi because i need to use a webcam with python, it’s there another way to install it without installing all unusued libraries? Thanks you!
Adrian Rosebrock
I’m not sure what you mean by “installing all the unused libraries”, but in order to get OpenCV and Python installed on your system, you will need to follow these instructions.
Moataz
Hi Adrian,
Thanks a million for the well structured, straight to the point tutorial. I really dig the virtual environment concept. I’m new to development on Raspi BTW.
I was wondering where can I learn about the structuring of these different packages? I am following your provided steps blindly tbh since I need the openCV environment setup asap.
You, and most of the users, seem to know from/to where different packages are downloaded/installed.
Again, thanks a lot.
Moataz
Adrian Rosebrock
Hey Moataz, can you clarify what you mean by the “structuring these different packages”? Most of the steps in this tutorial are simply installing dependencies so OpenCV can be compiled. If you do not know what a specific package is, the easiest way to learn more about it is to copy and paste the name into Google and read more on it.
Luke Taylor
What camera case is that? Where did you get it?
Adrian Rosebrock
This is the camera housing I am using.
Joe
Hi Adrian. After following all your steps I had an error with step 9 where you enter
‘$ make’ in the terminal. (I did not enter the $ sign). I tried repeating each step again but I keep getting these errors below during the make process. I am kind of new to Linux and the Terminal so I hope you can help me.
Could you help me?
Adrian Rosebrock
If you are getting an error related to the
highgui
module, (which is the module OpenCV uses to display GUIs to your screen), then it’s likely that you didn’t install GTK. Go back to Step 3 and ensure GTK was installed properly:$ $ sudo apt-get install libgtk2.0-dev
Joe
Hi Adrian,
Thank you so much for the quick reply. I did step 3 again for a few times and this is what keeps coming up. I even tried downloading the newest version of libgtk and I still got the same error when executing $ make. Could this be related to wrong directories or anything like that? Here is what it says when I execute step 3:
Reading package lists… Done
Building dependency tree
Reading state information… Done
libgtk2.0-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Adrian Rosebrock
Once you use apt-get, make sure you delete your “build” directory and re-create it. This will ensure nothing is cached and CMake can start fresh.
Joe
Hi Adrian,
I deeply apologize. It’s my mistake because I was following this tutorial even though I had Jessie installed. I am now following your other tutorial for OpenCV 3.0.0 for Raspbian Jessie. Thank you for your tutorials and help!
Adrian Rosebrock
No worries Joe, I hope the install goes cleanly on Raspbian Jessie!
Joe
Hi Adrian,
Thanks! I actually got OpenCV 3.0 installed perfectly. Thanks again!
Keith Tomes
Hi Adrian. I also ran into the same issue that Joe did. Rather than re-install my pi 2 with Wheezy (SD was preloaded with Jessie) I was curious if the code from your blog ‘Home surveillance and motion detection with the Raspberry Pi, Python, OpenCV, and Dropbox’ will work with Opencv 3 and Jessie?
Thanks!
Adrian Rosebrock
The home surveillance & motion detection code was intended for OpenCV 2.4; however, you can easily make it compatible with OpenCV 3 (it will run on both Wheezy and Jessie, so that’s not an issue) Check the comments section of the post for more information. The only thing you should need to change is the
cv2.findContours
call.yasser
Hi, I did follow same as u mentioned related the highgui error. however i do have same error. any help?
Adrian Rosebrock
After you install the GTK library, delete the
build
directory, re-create it, and then run CMake + make again.rafii
how to delete the build directory?
Adrian Rosebrock
Change directory to where your “build” directory is stored and then do:
$ rm -r build
karam
Hi could you test my openc cv c++ code on raspberry pi 2?
Paul-G
Hi Adrian,
I am about to start setting up a spare Pi B+ as above. The goal is to end up with your ‘Home surveillance and motion detection with the Raspberry Pi, Python, OpenCV, and Dropbox’ running. This is for a security system to monitor the interior of an empty property so needs to auto-run if rebooted after a power outage.
My question – can I do all above without the virtualenv etc. as I am not using this as a development platform?
Cheers, Paul.
Adrian Rosebrock
You certainly do not need to use a virtual environment, that is just a recommendation, not a requirement.
Paul-G
Hi Adrian,
Reply posted but vanished?
Thank you for that. It will make the final boot sequence simpler for me.
I am hoping to get away with using a spare Pi B+ that I have spare. Can you recommend a suitable environment – Raspbian Wheezy or Jessie? With OpenCV 2.4 or 3.0?
I have already started with Wheezy and 2.4 as they are older but can easily start again from scratch if newer is more efficient.
Cheers, Paul.
Adrian Rosebrock
Hey Paul — all comments are moderated by me, so no worries, your comments do not “vanish”, they just go into the moderating queue.
As for your question, I prefer using OpenCV 2.4 with Raspbian Wheezy. You can do it with Jessie, but (1) the commands are different and (2) I don’t have a tutorial that you can follow along with.
Tan
Hello Adrian,
Thank you for your help earlier. I have been able to successfully compile and install OpenCV. However, my major issue right now is that my import cv2 file is failing to import. I get the standard error that everyone else gets above. My ~/.profile is written correctly and I’m able to enable the virtual environment. My main issue lies with the soft linking cv2.so and cv.py files. When I check the location
/usr/local/lib/python2.7/site-packages
I am unable to find any cv2.so or cv.py files. It is empty actually.
There is an opencv-2.4.10 folder on /home/pi. I am unable to find the cv2.so files and cv.py files. One of the users above found the files in
/home/pi/opencv-2.4.10/build/usr/local/lib/python2.7/site-packages/cv2.so
I have no such directory in the opencv-2.4.10 folder.
Do you have any suggestions or possible fixes? I would really like to avoid having to recompile this since it takes about 10 hours.
Adrian Rosebrock
Did you check
/home/pi/opencv-2.4.10/build/lib
as well?I would try to use the
find
command to help you out:sri harsha
Hello Adrian, I am facing problem in step 9.
After the command “make” , it installs upto 18% and starts showing a very huge error. It finally ends up showing recipe for target ‘modules/highgui/CMakeFiles/opencv_highgui.dir/all’ failed
Adrian Rosebrock
Make sure you have done Step 9, which installs GTK the library OpenCV depends on to create GUIs:
$ sudo apt-get install libgtk2.0-dev
Blessy
Hi Audrian!
good work out there. I’m more comfortable with “c” , so is it possible to detect features using opencv in c??
thanks in advance
Adrian Rosebrock
It is certainly possible to perform feature detection and extraction using C/C++. I don’t cover any C++ code on this blog, so you’ll have to refer to the OpenCV documentation.
Nicolas
Hi,
I want to stream video with OpenCV.
I wrote GUI and webkit browser for HTML page. It didn’t work for Motion so I’m installing OCV right now. Can you tell me – will webkit handle it ? Or is it possible to stream directly into the app window ?
Adrian Rosebrock
If you want to perform streaming, I would suggest using using ffmpeg to handle streaming from your Raspberry Pi to another system. If you want to further process the frames before writing the frames to a stream, that becomes substantially harder. I would suggest starting the project using the streaming provided by ffmpeg and see how far that gets you.
Nicolas
So you think that wbkitGTK+ will handle ffmpeg stream ?
Nicolas
Of course I just want to recieve image, no processing.
Adrian Rosebrock
Yep, as long as you simply want to receive the stream, ffmpeg should do the trick for you.
Nicolas
Ok, I’ll try, but now I’m getting symbols (with motion) and I can’t install ffmpeg :/
And btw. Merry Christmas.
Adrian Rosebrock
Merry Christmas as well Nicolas! As far as ffmpeg, I have only used it once before and it was not on the Raspberry Pi. I would suggest posting on their community/mailing list.
Gowtham
Hello Adrian,
This is Prog.Gowthm from Amrita University.
We have taken a “early warning” system project which needs to process the live video, Audio, and geo signals Streamed.
Is it possible to use Raspberry PI2 to do this heavy task? if possible pls.guide us insight in the area. If not possible what is the best way of doing this.
Adrian Rosebrock
You can certainly perform video processing with the Raspberry Pi. I would suggest taking a look at this tutorial for an example. However, the issue is that the Pi is not fast enough for more advanced video processing algorithms.
While I have never done audio processing with the Pi, I’m sure it’s capable of this as well. The same goes for gathering geo signals. But doing all three at the same time is likely going to be too taxing for your Pi 2, especially if you want to apply any type of “advanced” algorithms. In that case, I would recommend using a different type of hardware. Even your standard off-the-shelf laptop/desktop with multiple cores running at 2GHz+ and a moderate amount of RAM would be better suited.
Rutvik
sudo ldconfig doesn’t worked out. Everything else is done. What should i do. Is that command is necessary?
Adrian Rosebrock
Are you getting an error message when running
sudo ldconfig
? Also, go ahead and try to access the OpenCV bindings within the Python shell from your virtual environment and see if it works.john
Hi Adrian. Nice work btw. your guides are always helpful to me. I am buying a new raspberry pi 2 and i want to setup opencv (in release mode) along with c++ as my language. have you tried using c++ instead of python alongside opencv in pi? if so, how do i set it up? thnx in advance
Adrian Rosebrock
Once you have OpenCV installed on your Pi, you can compile C++ programs, that’s not an issue at all.
Mark Harris
Adrian,
Thanks so much for very clear instructions!
Mark
Adrian Rosebrock
No problem Mark, I’m glad they worked for you!
Luis Jose
Hi Adrian,
I have been following the tutorial in order to install OpenCV and python in my Raspberry pi B. However, I’m having some problems. When I follow the steps in section 11, the library is not recognized. If I avoid using the command “workon cv”, the library works.
Maybe this is because I didn’t understand the paragraph:
“Important: Make sure you’re in the cv virtual environment so OpenCV is compiled against the virtual environment Python and NumPy. Otherwise, OpenCV will be compiled against the system Python and NumPy which can lead to problems down the line.”
Please, can you elaborate more on that? What do you mean when you say “Make sure you’re in the cv virtual environment”? Does that mean, be sure to execute the command “mkvirtualenv cv” before Step 8?
I really appreciate your help. Thanks again for sharing your knowledge with the world!
Adrian Rosebrock
All I mean by “make sure you’re in the cv virtual environment” is that you access it via the
workon
command prior to running CMake:Usman
Hi Adrian,
I was installing OpenCV as mentioned above. I have been following the tutorial completely but when I execute “unzip opencv-2.4.10.zip” in step 9, it gives an error stating:
unzip: cannot find or open opencv-2.4.10.zip, opencv-2.4.10.zip.zip or opencv-2.4.10.zip.ZIP.
Any solution on how to correct the issue?
Adrian Rosebrock
Make sure that you have downloaded the .zip correctly and that the file is in the same working directory prior to executing the unzip command.
Nicolas
So, I’m back and first time everything worked but my SD card was damaged and I had to reinstall everything. Now I did everything just like you told here and It’s not working.
It’s saying that there is no module like cv2 and no command like workon.
What can I do ?
Adrian Rosebrock
I address both these questions in the “Troubleshooting” section of this post. Also, keep in mind that the post you are replying to uses Raspbian Wheezy. The latest version is Raspbian Jessie, which is what the tutorial I linked you to covers.
Mathilda
hi there… thanks for your awsome tutorial
I’ve got a problem in Step 9
and that is, I get ERROR 403: Forbidden
I don’t know why does it occur and how to solve it…
I’d be grateful if you could help me, thanks
Adrian Rosebrock
I’m not sure why you would be getting a 404 error (I just tested on my machine and it downloads fine), but try copying and pasting the download URL into your browser and downloading manually:
http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.10/opencv-2.4.10.zip/download
Mark
Hello, I receive an error on step 9, when you say to type in “make”. I get to about 21-22% into the make process and it kicks me out. here is a pastebin of the full error http://pastebin.com/sFWZpapu
Adrian Rosebrock
Based on your
make
output, I get the impression that you’re using Raspbian Jessie? If so, use this tutorial instead (the tutorial you are currently using is dedicated to Raspbian Wheezy).jeck
Hey Adrian. awesome tutorial. I just want to ask if you have successfully opened a video (avi, mp4 etc) using opencv in raspberry pi? Ive tried opening a video, then displaying it, but it failed. (Ive used videocapture(“myvideo.avi”)). Based on what ive learned, the problem is ffmpeg. Ive installed the necessary packages but it still doesnt work. It seems opencv is unable to communicate with ffmpeg in order to read videos. The video i have works perfectly fine because omxplayer can play the sample video in raspberry pi. Did you ever have a problem similar to this in the past? Truly appreciate the help you can give me.
Adrian Rosebrock
Yes, absolutely, it’s totally possible to use
cv2.VideoCapture
with a video file. In fact, it’s covered multiple times on the PyImageSearch blog. Your particular issue sounds like a codec problem though. Have you compiled OpenCV with--WITH-FFMPEG=ON
during the CMake stage? This will (ideally) help resolve the error.Ananda
Great work!!! This has been a life saver so far!
But I have been trying everything to get matplotlib installed with all this. ‘pip’ and ‘apt-get’ all seems to be failing. Can you please help? Thanks a lot!!!
Adrian Rosebrock
Please refer to this post on installing matplotlib.
Gertjan
libtiff4-dev is obsolete. Please update this blog.
Adrian Rosebrock
Be sure to check out the link to installing OpenCV 3 on Raspbian Jessie which is linked to multiple times in this post.
Newbie
hello dear sir
I have difficulty in step nine
two error codes appear when compiling opencv
error message : https://goo.gl/hdsh19
how do I fix it?
looking forward to your reply
thank you
Adrian Rosebrock
Based on your error message, it sounds like you’re using Raspbian Jessie (correct me if I’m wrong). Use this tutorial to install OpenCV instead.
Tomas
Hi Adrian,
thank you for great work!!! I had to install it about 5 times to make it working. The first time I installed it like root, it worked only to the first restart. I found that I made some mistakes in installation so I made new installation as pi user. As pi user I was not able to use it, I got error “ImportError: No module named cv2.cv” and was not able to solve it. Since it was working as root for the first time, I was trying again and again. Finally I installed it correctly under pi user following your steps. I think the biggest problem was that I was not reading text after rpi-udate. There was written to restart RPI, which I did not do. I think it was the basic problem why the previous installations were not working. As I was reading previous posts I think some other users may have same problem. Thank you!!
Keron.W
Dear Adrian,
I followed all the steps to install and upon checking my open cv version I get 3.0.0. However when I attempt to run my python script in terminal, I get the error, “no module named cv2”. What can be the cause of this and how do I fix it.
K.W.
Student.
Adrian Rosebrock
Please see the “Troubleshooting” section of this post for details on why OpenCV cannot be imported.
Shashank
wget https://bootstrap.pypa.io/get-pip.py
When I run this command, the terminal says “No space left on device”. But its an 8 GB sd card, and hardly 3 GB is used. Could you help me out with this? Thanks in advance
Adrian Rosebrock
Make sure you have executed
raspi-config
and selected the first option, ensuring the entire filesystem has been expanded, and then reboot your Pi. If you do not do this, then you might not be utilizing the entire 8GB card.Daniel
Hi Adrian, thanks for this tutorial. Do you have a tutorial for installing OpenCV2.2.0 on raspberry? Im having trouble from step 9: build cmake. After I compile the OpenCV i have an error. Please help, thankyou!
Adrian Rosebrock
OpenCV 2.2 is very old — is there a particular reason you need to install it?
Tomas
Tested on RPI 3, ubuntu Mate – OK 🙂
Thank you!!!
Adrian Rosebrock
Fantastic, thanks for sharing Tomas!
Kerem
Tomas any particular changes to the install procedure outlined by Adrian? Thanks for sharing.
Sydney
I guess it is obvious to some but why do I need OpenCV installed on my Pi to track a color with Python and a Pi camera? This part is not clear to me and others I’ve talked to.
Why is its exact function/purpose in this project? It’s not facial recognition, just a color value.
Kindest regards,
Sydney
Adrian Rosebrock
You certainly could implement color tracking functionality simply using NumPy functions (or even pure Python functions). The primary benefit is that OpenCV provides many convenience functions to facilitate easier image processing and computer vision operations.
Sydney
I think I’ll try to stick with Python for now and some may be able to incorporate NumPy. Learning Python for some basic projects was our goal as a precursor to next year. Do you have any recommendations for that, such as resources or code samples online? I’m not asking you to solve my problem and appreciate all your input and willingness to help so many people.
Adrian Rosebrock
Are you referring to learn more about Python? If so, then I highly recommend the RealPython course.
Dogan Ibrahim
Thanks, I managed to install the opencv first time!
Adrian Rosebrock
Great job Dogan!
James
How come I cannot run the “workon cv” command directly from Terminal? It seems to only work remotely from Putty.
Adrian Rosebrock
Make sure you run
source
followed byworkon
:It sounds like your SSH session isn’t automatically sourcing the
.profile
file. The above example should resolve the issue.Roo
Hi Adrian,
Looking fir your advice here.
i’m new to OpenCV, and also to raspberry pi. My raspberry pi’s running on raspbian jessie. However, from what I have read online, it seems that opencv 2.4 has more support and is more suited for a beginner, am I correct? That’s the only reason for me choosing to go with opencv 2.4. I’m doing a project on vision systems, and I think the examples and resources from opencv 22.4 will help me out a lot.
Also, I noticed that you did not post a tutorial for installing opencv2.4 on raspbian jessie. Is there a compatibility issue with raspbian jessie and opencv 2.4? Will I be better off running raspbian wheezy and opencv 2.4?
Thanks so much,
Adrian Rosebrock
There are indeed more tutorials for OpenCV 2.4; however, I wouldn’t let that stop you. I cover both OpenCV 2.4 and OpenCV 3 here on the PyImageSearch blog, so feel free to start with whatever version you want. It’s also a bit more complicated to get OpenCV 2.4 installed on Jessie, so I normally recommend using Raspbian Wheezy if you want to utilize OpenCV 2.4. Otherwise, use Raspbian Jessie for OpenCV 3. Finally, if you’re just getting started, consider going through Practical python and OpenCV, which will help you get up to speed quickly.
jos
hello adrian,
while following your tutorial every wen’t smooth till i reached the part were i test the import cv2
then i get the error no module named cv2
i’m in the cv vitualenv
i’ve got the idea that tha module isn’t placed in the right place
in the map /usr/local/lib/python2.7/site-packages are no files and when i open /home/pi i see 2 files one named cv.py and one named cv2.so
is that the problem??
and if so how could i move those files to the right place since cuttin and pasting give me an errror saying access denied
i hope you could help me thanks in advance
greetings jos
Adrian Rosebrock
If you have the
cv.py
andcv2.so
files, then yes, all you need to do is move them into thesite-packages
directory for your Python install.Q
Hi Adrian! Really appreciate your instructions! But I got a big problem. When I open the python and import cv2 in the cv environment, it keeps telling me that there is no module named cv2. I read through all the comments and replies. I am pretty sure I have already had the cv2.so and cv.py these two files in the site-packages(that directory), but the things keep showing up. I adjust add the two lines ( export and source that two) into ~/.profile, but still not working.
And also I searched on the website ,tried to do the import sys, and sys.path.append(“my working directory”), but its still not working. I found out another solution that suggests me to do the sudo gedit ~/.bashrc, but after I download the gedit, and do the sudo gedit ~/.bashrc, I even cannot connect to the init server, and Gtk-Warnning cannot open display. Really need some kind of help.
Adrian Rosebrock
If you need further help debugging the import issue, I would suggest going through the Troubleshooting section of this tutorial.
As for the GTK warning, it sounds like you’re SSH’ing into your Pi, in which case you need to enable X11 forwarding:
$ ssh -X pi@your_ip_address
moayed
hello awesome Adrian , i have two questions kindly answer me
1- i Neglected 🙁 to execute this command while i following steps ( # virtualenv and virtualenvwrapper) but after i finish install every thing i re execute it and every things look OK i have open CV and i am in cv virtual environment , will it make problem in future ???
2- i did all step and every things going fine until i reach to step 11 line 3 ( import cv2)
i got No module named cv2
i am in cv virtual environment and i check the files in my current dirctory and i found the cv2.so in red color
kindly help me sweet adrian
Adrian Rosebrock
If you skipped the virtual environment steps, that’s not ideal, but you should still be able to get everything to work. First, check to see if your
cv2.so
file is in/usr/local/lib/python2.7/site-packages
. If it’s not, then you might be in some trouble — in which case I would recommend wiping the SD card and restarting the install process.Adi
Hey Adrian,
Can you please tell me if this project is compatible with the latest Raspberry 3 ?
Thank you,
Adi
Adrian Rosebrock
If you want to install OpenCV on your Raspberry Pi 3, please use these instructions instead.
moayed
hello adrian , no module named cv2 again
i update my source ./profile and i execute the workon cv and everything good
when i check the files in ~/.virtualenvs/cv/lib/python2.7/site-packages/ its show cv2.so and cv.py in red color ( iread trhe comment about this ) i unlink it becuase my open cv downloaded in /home/pi i dont know why ! i tried to link it to home/pi but it doesn’t work
noitce: when i check files in opencv-2.4.10 there are not files call cv2.so or cv.py
kindly help me adrian
Adrian Rosebrock
If your sym-link is in read, then it’s because the file you’re trying to point to doesn’t exist. After you compile OpenCV, do a double check that there is a
build/lib/cv2.so
file. If not, OpenCV did not compile correctly.moayed
hello adrian , everything OK with me expect
i found cv.py but there is no file call cv2.so in all system ( i used find command as root ) and i didn’t find it can i install cv2.so individually or i have to restart all installation of opencv
Adrian Rosebrock
Hey Moayed — I would suggest consulting the “Troubleshooting” section of this blog post.
Chris
Hi Adrian,
Great article. I have gone through all the steps and managed to upload some photos to my Dropbox.
Having gone through the development phase, I now want to deploy this as a standalone project, where I won’t have/need a screen attached. I still want to log in remotely using SSH and am using Putty. I have set the X11 forwarding as suggested above, but am getting this error:
Gtk-WARNING **: cannot open display: localhost:10.0
I don’t need the X11 now – can opencv be used without it?
If so, what needs to change in the pi_surveillance.py program?
Chris
Adrian Rosebrock
Please see my reply to Matt on July 5th above. I detail exactly how to resolve this issue.
Xuân Đức Đoàn
Hi Adrian, I have a question, do I need to access the cv virtual environment when I work with opencv ?
Thanks and Best regards.
Adrian Rosebrock
If you use the instructions detailed in this tutorial, then yes, you need to access the “cv” virtual environment when you use OpenCV.
keith
Then, update your ~/.profile file to include the following lines:
where is my ~/.profile located so i can edit it?
Adrian Rosebrock
Your
.profile
file is located in/home/pi/.profile
. The~
is shorthand for your user directory.Randy
Hi, When you are making the virtual environment, and when you have to edit the code in a text editor, how do you save it?
Adrian Rosebrock
That depends entirely on which text editor you are using.
Raman Raja
If you are using a GUI editor, click the file-save menu. If using nano editor, press CTRL+O.
Howver, you may not have edit permission for some files, so saving will fail. In that case, start the editor in super user mode:
$ sudo nano myfile.config
Luis Nieto
hi Adrian , i follow all the steps , but when i compile (step 9) , the process beginning and in the 22% appear this error : fatal error: can´t write PCH file:No space left on compilation terminated , and then all stop. how i can fix this? i really appreacite that you can help me.
Adrian Rosebrock
The “No space left” error message indicates that your Raspberry Pi ran out of disk space. I would suggest deleting unused files, expanding your disk, or purchasing a new, larger SD card that you can use.
Andy
Hello, I follow all the steps and it works perfect but I would like to use OpenCV without the virtual enviroment. I am trying to install Scipy in the virtual enviroment but “pip install scipy” takes a long time. However, I dont have that problem when I use “sudo apt get python-scipy”, but Scipy is not installed in the virtual enviroment. So I think is better without the virtual enviroment.
Adrian Rosebrock
When you run
pip install scipy
the SciPy package is downloaded and compiled from source. When you useapt-get
to install packages, pre-compiled binaries are installed. But, there’s an issue with that — the binaries/libraries in theapt-get
repositories are out of data. Furthermore, I would encourage you to read this blog post which explains why using virtual environments are a better choice.Tri Nguyen
Hi Adrian, after cmd: sudo rpi-update, i didn’t see my taskbar, or it flicked, so how can i next step, i cannot open terminal (with ways i fould on internet).
Adrian Rosebrock
I’m not sure why that would happen — that is certainly an issue with Raspbian or your Raspberry Pi. I would suggest posting on the official Raspberry Pi forums regarding the issue.
Rak
Hi Tri,
I also got the same issue but i resolved the issue after removing the volumealsa plugin from this file ~/.config/lxpanel/LXDE-pi/panels/panel .
You can visit this link for more info:
https://github.com/Hexxeh/rpi-firmware/issues/115
Hope this helps
Amal
Hi.. I am trying to install opencv on my pi… when giving make command it was not progressing from 18%. From 18% it is displaying errors and opencv is not installed…. Please help me to find the problem
Adrian Rosebrock
Which version of the Raspberry Pi are you using?
Sufiyan
I got the same error.Can u help me with it?
I’m using raspberry pi 3.
Twinkle
Is there any way to run this program without using the arguments?
Adrian Rosebrock
Without the command line arguments? Sure, but you would have to hardcode the paths into the script.
Adarsh
Hi Adrian,
pi@raspberrypi:~ $ workon cv
-bash: workon: command not found
is there any solution to the above problem…??
Harika
I too have same problem… is there any solution??
Harika
pi@raspberrypi: $workon cv
-bash:workon :command not found…
Adrian can u plz help me with this problem
Jo
I’m getting an error, ‘cv2’ not defined. Could you walk me through this?
Bibaswan
Hi Adrian,
Can i use USB camera instead of pi cams.
If yes then what are the changes i have to do in your coding.
Adrian Rosebrock
Yes, you can use two USB cameras. Please see this post for more information.
Joe
Hi, Adrian:
I tried it on opencv2.4.13 but failed with the following errror, any advice would be appreciated:
$ sudo python capture-positives.py
…
import RPIO._GPIO as _GPIO
SystemError: This module can only be run on a Raspberry Pi!
Adrian Rosebrock
Hi Joe — are you using Raspbian for your OS?
fjgeek
Hi adrian, i want to use opencv3 and opencv2 how i can in the same raspberri pi. i need this cuz i have projects in opencv2 and another into opencv3
Adrian Rosebrock
I offer a Raspberry Pi Raspian image with my Practical Python and OpenCV + Case Studies Quickstart Bundle that has both OpenCV 3 and OpenCV 2 installed. Just flash the memory card and put it in your Pi. Then you can get started.
Cesar
Hello Adrian,
This website is great. I have a quick question, could you quickly talk about the advantage of downloading cv2 this way instead of doing the good old “pip install opencv-python”?
Before finding this website that is what I did but I do not know if your way will increase performance and such.
Thank you
Keep up the good work.
Adrian Rosebrock
The short version is that you won’t have access to GUI functions like
cv2.imshow
. They may error out completely (most likely) or be buggy. Furthermore, you won’t have as much control over the compile and whether or not additional libraries are included during the install to optimize OpenCV.Eric
hello,
this post was of great help, but i have a question.
i did everiting as you told and i have now a simple program working, now what i what to do is to load it at starup, but the problem i have is that i cant figure out how to load the virtual enviroment so that the program can run whitout having to tipe de source ~/.profile and workon cv manually.
any ideas?
best regards
Adrian Rosebrock
Please see this blog post where I discuss how to run a Python + OpenCV script on boot.
Calvin chow
may i know how to auto-run
source ~/.profile
mkvirtualenv cv
after switch on the raspberry pi or reboot
thanks
Adrian Rosebrock
Please see this blog post.
Akbar
Hello Adrian, thanks for your tutorial
I got some problems when following your steps, i can’t do the 9th step when compiling OpenCV using “$make” command. I got this messages “from /home/pi/opencv-2.4.10/build/modules/core/precomp.hpp:48:
/usr/include/c++/6/cstdlib:75:25: fatal error: stdlib.h: No such file or directory
#include_next “.
And anyway, on .profile files, should i replace them all or just add ur code under the default .profile?
Thank You
Adrian Rosebrock
Hey Akbar — the issue you are having is due to precompiled headers. Add the following flag to your “cmake” command:
-D ENABLE_PRECOMPILED_HEADERS=OFF
You should delete your “build” directory, create a new one, and then run the updated “cmake” command.
Akbar
Sorry Adrian but I already wipe my raspi. Thanks a lot for your solution. I wanna ask about source ~/.profile, i already add the code that you wrote but this message still appear “root@raspberrypi:/home/pi# mkvirtualenv cv
bash: mkvirtualenv: command not found”. I dont know what is wrong.
Akbar
I already reload it and the profile is work but mkvirtualenv still command not found
Akbar
but when i type it on terminal manually (not using .profile), it works.
Adrian Rosebrock
It looks like you’re trying to execute your script as “root”. Keep in mind that the “root” and “pi” user are two different users on the system. you would need to install mkvirtualenv and create a new Python virtual environment for root. But an easier solution would just be to supply the full path to the “cv” Python binary when executing your script:
$ /home/pi/.virtualenvs/cv/bin/python your_script.py
Akbar
Ohh, I see. Thank you, Adrian. And what should I do with that script? Copy it or execute it? And about “your_script.py” is that a default name or should i change it with what files?
Akbar
or maybe can i just re-install mkvirtualenv on “pi” rather than “root”?
Adrian Rosebrock
The “your_script.py” was just an example. Change it to whatever your script name is.
Akbar
Thanks Adrian, I already know the solution
Harika
I have a problem with workon …. when i try to run workon cv command then it is showing me workon command not found…
Adrian Rosebrock
It sounds like either:
1. Virtualenv/virtualenvwrapper did not install correctly
2. You did not update your .profile correctly
Double-check both of those steps
Venky
Hello sir, I found an error in 5th step ” compile and install opencv actually” it is showing that – CMake Error: The source directory”/home/pi/opencv-3.1.0/build” does not appear to contain CMakeLists.txt. You make be think this problem is due to 2nd step, but i have done it successfully and again checked it also. so, please give the solution for this solution as fast as you can.
hjagadish
Hi Adrian,
Thank you for the tutorial. I am a newbie for Python and raspberry-pi. While following the above steps I am stuck in step 9. I keep getting the error message – “stdlib.h: No such file or directory”. Could you please help me out here ? I have the following configuration :
1. Rasbian OS
2. Raspberry 3
Adrian Rosebrock
See my reply to Akbar.
MD.Sifatul
After completing the installation of opencv workon cv does’nt work what can i do?I am using Raspbery pi 3 B+
Adrian Rosebrock
Double-check that virtualenv and virtualenvwrapper were successfully installed. You may also need to check your “.profile” file and ensure you have properly updated it like I have done in the tutorial.
Artun
Hello there Adrian,
Thank you for great post.
I’ve been trying to work on “person tracking camera” even tho I tried to use your codes about it. But somethings are not working properly. When I make “workon cv” then python and “import cv2 ” I get an error which says ” no module named cv2″ but when I do it without “workon cv” it doesnt give any error about it. Eventho it gives me the version of cv2 aswell.
Appreciate your help
Adrian Rosebrock
I would recommend you follow one of my more recent OpenCV install guides.
Justyna
Hi Adrian! Your tutorial is very good, however I get stuck in step 7, just right here:
“Then, update your ~/.profile file to include the following lines:”
I don’t know exactly where I can find my ~/.profile file. In which folder should I look for it? I would be really greatful if You answer.
Adrian Rosebrock
The “~” is short for your home directory. The full path would be “/home/pi/.profile”
go
ls -la at /home/pi for rasp pi
go
for step 9, dont need to mkdir build , else will have error. just perform cmake at opencv-2.4.10.
go
sorry forgot the .. at the back of command