Steps to setup a Raspberry Pi and Install Open CV (for Python 2.7)

Steps given for friends who wanted to setup their own Raspberry Pi’s before my class.  I recorded the video, and will post it later.

All steps done starting with image: 2015-05-05-raspbian-wheezy.img

Install Raspian: and follow the install guide:
– Basically, on a mac, running sudo dd bs=1m if=2015-05-05-raspbian-wheezy.img of=/dev/disk2s1
– This will take about 20-30 minutes… 🙁 Start it and do something else for a while.
– Make sure you end with: sudo diskutil eject /dev/disk2s1
– Protip, install pv (brew install pv) and then run the above command like this: dd bs=1m if=2015-05-05-raspbian-wheezy.img | pv | sudo dd bs=1m of=/dev/disk2s1
– – This will display status as it installs: 164MiB 0:01:10 [2.42MiB/s] (Wait for it to get to ~3.5G)

raspi-config (you’ll be taken to this screen automagically. You can get there later using the raspi-config command.)
– Select Expand Filesystem
– – This will say the partition was resized and will be enlarged on the next reboot. Click ok.
– Select Internationalization Options
– – Select Change Locale (Optional)
– – – Uncheck en_GB (Great Britain English) and select en_US.UTF-8
– – – Select en_us.UTF-8 as your language.
– Advance Options
– – Hostname (Optional) – Select a new hostname for your pi
– – SSH (Optional) – Enable this to work remotely
– – SPI – Enable this. We’ll use SPI in the class. Select YES to the Load by default.
– – I2C (Optional) – Enable this if you plan on using an I2C Board. We won’t use this in the class
– – Audio (Optional) – Set to 3.5 mm jack to use the 3.5mm jack
– – Update (Optional) – Updates the tool. Never seen an issue to not do this, but doesn’t hurt
– Finish
– sudo reboot – This will update all settings we just changed and make sure we use the full disk
– Login (default: pi:raspberry) Note: You may want to SSH in at this point so you can copy/paste in terminal 🙂 ssh hostname/ip -l pi
– Update the software (Make sure you have internet access. Either wired, or setup wireless here:
– – sudo apt-get update
– – sudo apt-get upgrade
– – – select Y to update. Takes a little bit for the first time.
– – Sudo rpi-update
– Install extra software:
– – sudo apt-get install vim python-dev
– Install spi-dev
– – git clone
– Update Default Editor (Optional) – Only if you prefer vim/emacs to nano
– – sudo update-alternatives –config editor
– – – Select vim.basic or whatever you prefer
– sudo reboot – Uses new disk image and software

Test stuff:
– Login and type “python” and at the prompt “import spidev” Shouldn’t get an error. 🙂 Type “exit()” to quit

pi@raspberrypi ~ $ python
Python 2.7.3 (default, Mar 18 2014, 05:13:23)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import spidev
>>> exit()

You’re ready for the class.

If you own your own pi, create your own user. This means your device, which can be connected to the internet, isn’t open to anyone who knows the default user/password
– sudo adduser
– sudo passwd
– sudo visudo – Copy the lines with pi to the new user ( ALL=(ALL) NOPASSWD: ALL)
– logout/login as new user
– sudo userdel -r pi
– sudo visudo – remove pi enteries

Extra Stuff
Setup OpenCV (taken from

From the state after installing above:
sudo apt-get install build-essential git cmake pkg-config
sudo apt-get install libjpeg8-dev libtiff4-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install python-pip
sudo apt-get install “picamera[array]”
cd ~
git clone
git clone
cd ~/opencv
mkdir build
cd build
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
make -j4
sudo make install
sudo ldconfig

Test It:
import cv2

Python 2.7.3 (default, Mar 18 2014, 05:13:23)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__

About Matthew Jones

Writer, Programmer, Astronomer, Dreamer, Wisher, Fighter. Always striving to be better than I was.
This entry was posted in Projects, Raspberry Pi, Software. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *