Duration 14:4

Raspberry pi Video stream image manipulation with openCV and TKinter

2 078 watched
0
14
Published 29 Jul 2020

cartoon like video stream, no problem using tkinter and openCV now let’s dive in Use sd card formatter for formatting the SD if any previse installation was present Download the OS from https://www.raspberrypi.org/downloads/raspberry-pi-os/ I download the Raspberry Pi OS (32-bit) with desktop and recommended software version. Extract the .img file out of the zip file. open etcher and flash the img to the SD. one etcher is done it will dismount the SD, so take SD out and plug it again. This will pop up a drive. In this drive add the following 2 files wpa_supplicant.conf – and set the info in it to match your WIFI info ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=IL network={ ssid="Tal" psk="**********" key_mgmt=WPA-PSK } And also add an empty file name SSH, with no type or point. You might have to setup your PC to show you the type and allow you to edit it. Connect to your router and find the IP of the rpi. Open putty and past that IP to the connection window. Press connect. The first time you log in you will be prompted to approve the connection. Then the default used is “pi” and password is “raspberry” It is recommended that you change does on first log in. Do that by typing is “passwd” and following the instructions. we now want to update the system use sudo apt update and then sudo apt full-upgrade This might take a while. now let’s activate the camera. Type sudo raspi-config Choose the interfacing Options – then camera and enable the interface. You will need to restart the rpi at this stage. To restart the session of the putty, right click on the session window and choose restart session. https://picamera.readthedocs.io/en/release-1.13/install.html After you log in again, now let’s check that the picamera is installed by running this command python3 -c "import picamera" if you get no error, you’ve already got picamera installed! Now for the openCV part, I found this great pip install instruction and will follow it https://www.pyimagesearch.com/2018/09/19/pip-install-opencv/ as you can see in this paragraph this are unofficial pre-built OpenCV packages that can be installed via pip — they are not official OpenCV packages released by OpenCV.org. they have a few limitation, but for my needs today, its more than enough, I will be installing the opencv-contrib-python as you can see I ran into issue, which ended up in my finding a new guide for the rpi 4 https://www.pyimagesearch.com/2019/09/16/install-opencv-4-on-raspberry-pi-4-and-raspbian-buster/ The tutorial was working well, till I got to the point of trying to create the virtual environment, and I got an error there. A bit of googling and I found and tested this solution. https://raspberrypi.stackexchange.com/questions/108740/error-environment-home-pi-virtualenvs-cv-does-not-contain-an-activate-scrip I uninstalled sudo pip3 uninstall virtualenv virtualenvwrapper. and then reinstalled a specific version sudo pip3 install virtualenv virtualenvwrapper=='4.8.4' and added this change to the ~/.bashrc file use workon cv to activate the virtual environment and deactivate to exit it. Now that we got a little bit more installing to do We first have this tutorial that talks about tkinter and CV https://www.pyimagesearch.com/2016/05/23/opencv-with-tkinter/ from this we can take the following needed libraries : sudo apt-get install python-tk python3-tk python-imaging-tk pip install Pillow and then following this tutorial from the same site to get the video feed from the camera to the tkinter https://www.pyimagesearch.com/2016/05/30/displaying-a-video-feed-with-opencv-and-tkinter/ You will need to install pip install imutils I used this https://somtips.com/how-to-record-desktop-screen-of-raspberry-pi-3b-raspbian/ To run the program you need to type python test.py –o output lets first talk about the file that runs the show, test.py It does 2 important things, one is to set a video stream using the imutils video stream object and then launces the application passing that stream as an object. I made one change to this file from the original tutorial and this is adding resolution=(640, 480) since the default is half of that and it gets very pixilated. The photoboothapp.py file contains the logic of the process. I made 2 changes in the init section which is to add biding for keyboard strikes and adding self.effect to index the wanted effect. Pressing any key will change the effect index . in the video loop we read from the stream and according to the effect index we apply the needed image manipulation. then we resize the image and turn it into the frame image in tkinter. I’m still not 100% sure what I’m going to do with this, but will defiantly start by adding some more cool effects, if you have any suggestions or code to share I will be more than happy to hear from you.

Category

Show more

Comments - 3