How to Install OpenCV on a Raspberry Pi

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back to another raspberry pi tutorial in this one i'm showing you how to install opencv what is opencv opencv is a library of programming functions mainly aimed at real-time computer vision i have my terminal window open here and i'm going to ssh into my raspberry pi if you have your raspberry pi connected to a monitor then you can just open up a terminal so i need to run ssh pi at raspberry pi that's my hostname maybe you type in your ip there yes because it's the first time i'm going in and then my password so the first thing we're going to do is look at our file system so run the command df-h and what we want to look to see here is if we're using all of our memory if we have access to it all if your totals don't match up just right then you're going to have to do expand file system how to get there is we're going to run sudo raspy dash config to get into here go down to advanced options push enter and then this one enter again to expand file system you're gonna have to reboot your pi and then restart i don't need to do that so i'm gonna go back finish and moving on as with any tutorial i would be remiss not to tell you to sudo apt-get update and sudo apt-get upgrade okay now let's check our python version dash capital v i'm running python 3.9 if you're running python 2 then maybe try python 3 dash v we should be running python 3 for this so if you didn't get any way to find a python 3 version then i would suggest go install a python 3 version and then come back to this tutorial anyway moving on we're going to install pip and then virtual m all these commands you can follow along with time stamps and instructions in the description enter why next ctrl l to move it to the top just so it's easier to see and i'm going to create my project directory mkdir from make directory project and then i'm going to change directories into project next let's create a python virtual environment so that when we install packages through pip everything is contained just in this area and we don't get any package conflicts to do that virtual m m so i'm calling it m here and now if i do ls i have this file folder called m so if i run the command source m bin activate you'll see the little m shows up right here which means my virtual environment is activated next we need to install a bunch of system packages in order for opencv to interpret things like jpegs video files matrix operations and all of that this is just a bunch of packages so i'm going to have a big long list that you copy and paste into your raspberry pi command prompt here we go it's a bunch of them and then for an interesting fact i'm going to go to the beginning and type time before everything so we can see how long this takes all right so that took about two minutes i'm running it on the 4b if you're running this on a zero or an older model like a three it might take a little longer i just like to give credit to this website single board bytes for helping me figure out which of those packages to install okay moving on i understand that a lot of people are using the pi camera i myself use a usb webcam but if you're using the pi camera for opencv projects you need to run this command pip install in quotes pi camera square brackets array enter and now we're ready for the finale to install opencv into our python you've got two options here opencv contrib.python and then just plain opencv python and so what are the differences on this stack overflow website somebody asked that exact question and here's what they say opencv-python just has the main modules so if you're not doing as much with opencv i would install that it's going to install faster and be lighter on your machine and then the other one is the full package so it has main modules and also contrib and extra modules so you're able to do a bit more with your opencv installation i'm going to install opencv dash contrib dash python so what do i do pip install opencv dash contrib dash python let's also add the time thing at the beginning because this is going to take about two hours if you just install opencv python it's going to take significantly less time let's go enter okay two hours later a little less you can see 119 minutes and 8.784 seconds and we've installed it now let's test python to get into a python interpreter and then run import cv2 imported great no issues and now we're going to do cv2 dot double underscore version double underscore 4.5.5 and we've installed opencv successfully let me know if you have any questions this is just a tutorial for installation not a tutorial for usage so let me know if you want me to do a usage tutorial or if you have any problems give it a like if it was helpful subscribe if you want to keep seeing more of these raspberry pi tutorials happy coding
Info
Channel: Sam Westby Tech
Views: 109,673
Rating: undefined out of 5
Keywords: raspberry pi, opencv, install opencv on raspberry pi, install opencv with pip, install opencv python on raspberry pi, opencv on raspberry pi 4, opencv raspberry pi install, raspberry pi tutorials, opencv 2022, how to install opencv on raspberry pi, install opencv on raspberry pi 4
Id: QzVYnG-WaM4
Channel Id: undefined
Length: 6min 19sec (379 seconds)
Published: Fri Feb 04 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.