Easy Opencv deployment on raspberry pi

What we need in this deployment is a raspberry pi, a pi camera, if you have a screen for raspberry pi it will be better. We also need an internet connection for modules!

Set up our raspbian in raspberry pi. It is very easy to write an image in your sd card, by using “raspberry pi imager“. This is much more convenient than downloading the image by yourself and write using other software.

if you don’t have a screen or ethernet connection for our raspberry pi, it is necessary to set up a wifi connection before we start up the system. Go to the boot direction in this raspbian SD card, create a file named as “wpa_supplicant.conf“, copy the code below into this .conf file:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid=”WiFi SSID”
psk=”WiFi PASSWORD”
}

Replace Wifi SSID and Wifi password in the code, then you are good to go.

Boot up the raspberry pi and connect the pi camera to it, find the IP address of raspberry pi on your computer. Using ssh to connect Raspberry pi. For the first time startup on pi, the username should be pi, and the password should be raspberry.

SSH on windows has the various options, shell and putty are both great software and easy to setup. On Linux is easier, the command will just be:

ssh 192.168.xx.xx@pi

Now we are ready to move on installing OpenCV! Don’t forget to run these two commands every time!

sudo apt-get update

sudo apt-get upgrade

remove the software we don’t need, but it’s optional:

$ sudo apt-get purge wolfram-engine
$ sudo apt-get purge libreoffice*
$ sudo apt-get clean
$ sudo apt-get autoremove

Then we can setup our camera and expand file system on this command: sudo raspi-config Camera option is in 5Interfacing options, expand file system is in 7Advance options.

We can take a reboot right now by :sudo reboot. After rebooting, we can use the command: df -h to check the system size.

Usually, in the raspbian system, the python2 and python3 is preinstalled. But we need the module pip in our system. Command: wget https://bootstrap.pypa.io/get-pip.py

Then open this py file: sudo python3 get-pip.py

We want to use python3 instead of python2. After this command, pip3 should be a command in the shell.

Finally, it is time to install our OpenCV module! There are two ways to install, we will take an easy way by using pip. We can also use source code to build, but it will take over 2 hours to finish. Using pip will be much faster. Commands are below:

pip install opencv-python

pip install opencv-contrib-python

Haha, if there is no error message show, Opencv is now installed in our raspberry pi! But don’t get excited too soon my brother, let’s using python3 to check again.

Type python3 in console, then type “import cv2“, hit enter. If still no error message, type “cv2.__version__“. When you see your OpenCV version, congratulations! You finally installed your OpenCV successfully!

Follow these steps, we can also install OpenCV on our Linux and Windows computers, they are basically the same.

Now enjoy and have some random fun!

Leave a Reply

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