Raspberry Pi LESSON 44: Getting Ready to Master the Raspberry Pi Camera

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is Paul mccorter with toptechboy.com and we're here today on a very rainy day to bring you lesson number 44. in our incredible new tutorial Series where you're teaching your Raspberry Pi who's boss what I will need you to do is pour yourself a nice tall glass of ice cold coffee that is straight up black coffee poured over ice no sugar no sweeteners none needed and as you're pouring your coffee as always I want to give a shout out to our friends over at Sun founder Sun founder is actually sponsoring this most excellent series of video lessons and in this class we will be using the sun founder Raphael kit for Raspberry Pi the sun founder kit for Raspberry Pi most of you guys probably already have your gear if you don't have your gear yet look down in the description there is a link over to Amazon and you can pick this kit up and believe me your life and my life are going to be a whole lot easier if we are working on identical Hardware but enough of this Shameless self-promotion let's jump in and talk about what I am going to teach you today and what we're going to be talking about is we're going to be talking about the sort of next segment of this class now up until now in this class we've gone through most of the key components in this uh in this uh kit and what we're going to start with starting with today's lesson is we're going to start using the little camera okay and the little camera is actually the most exciting component in the Raspberry Pi kit and it's the one that I've been super super eager to get to but this is is what the issue is we at the point that we started uh this class in lesson number one at that point the main line operating system for the Raspberry Pi was the Buster operating system the Buster was a 32-bit based operating system and really we've just been going through what 44 lessons now that's 44 weeks and then the intervening time Raspberry Pi has moved from the Buster as being the mainline operating system it is now moved to Bullseye okay so there's been like an operating system upgrade while we've been making these classes well for the things that we've been doing really the old operating system was fine it was fine to be using the Legacy Buster system and even if you did those lessons on the new operating system the bullseye everything would work pretty much the same now this is where the difficulty came in when they moved from Buster to Bullseye they completely changed the way that you interact with the camera but when they went two Bullseye initially there was no support for the camera and so I found myself in a very difficult situation of knowing what to do do I just teach you how to use the camera on the Legacy system on the Buster system and then everything works as always it's easy I know everything I need to know and I can just teach you what is the problem with that very quickly you go from a legacy operating system to deprecated libraries and things that break and things that don't work the same so for a class that people might be watching not just today but a year or two years three years down the road I didn't want to build the class based on an obsolete operating system when it comes to the camera so okay then just move to the new operating system but then I had the problem that if I moved to the new operating system there was no support for the camera so for the last 44 weeks I have been trying to find a solution and I think I have a solution I'm going to kind of share it with you today and the bottom line is I'm just kind of sort of today show you where we're going in the future and so you guys that are coming in later I'm not going to really teach you how to use the camera you ought to just hop on over to lesson 45 which is next week's lesson where I'll show you how to install the libraries and put the camera on and do all that sort of stuff but for you guys that have been going through this class I'm kind of showing you where we're going next and I'm showing you why we are going there okay does that sound good I hope it sounds good it is indeed quite rainy out there and guess what this is the dry season if this is the dry season you wouldn't believe what's going on in the rainy season but anyway let me jump over and just kind of show you so what I decided was was that we were going to go ahead and upgrade to Bullseye so what you need to do for next week is you need to go ahead and download a bullseye operating system I am using the bullseye 64-bit operating system and if I'm not mistaken to Bullseye 64-bit operating system should run on either the Raspberry Pi 4 or it should run on the Raspberry Pi 3. now up until now 32-bit 64-bit I really didn't care why did I not care I really didn't care because if you're measuring temperature and humidity and making one measurement every five seconds and sending that back to your PC you know speed is not your problem speed is not the issue but at the point that we're going to start doing some really cool things with the cam camera and we're going to do some video processing and some image processing speed does matter so there will be distinct and noticeable advantages to being on the 64-bit system so tomorrow or next week the lesson that I'm going to show you in lesson number 45 is going to be built on the bullseye 64-bit operating system and so you guys have between now and next week's lesson to flash a card with that operating system get your desktop set up the way you like to have it set up if there's any old software that you kind of lack on there you know get your system up and running and configured with 64-bit now you should know how to do that because I showed you how to flash a card and do all that sort of stuff in lesson one of this if you're just coming into this lesson and haven't been through the earlier lessons you need to go back and catch up on a few of the earlier lessons so that sounds good so where I am right now is I am booted up up in on in Raspberry Pi Bullseye operating system in 64 bits one thing I notice with this is things are just a lot snappier like I noticed the desktop runs a lot better especially like firing up a browser and looking at the web everything is much snappier so yeah the 64-bit I am seeing some perceptible advantages in going to it so we've made decision number one do we move forward with Buster or do we move forward with Bullseye we move forward with Bullseye then Bullseye is available in either 32-bit or 64-bit Edition we've made decision number two we're going forward with Bullseye 64-bit okay and now we've got to make the decision of how do we operate with the camera how do we interact with the camera now there are two options in the first option that I'm going to show you is the option that we are not going to use okay but I'm just going to show you that it's there and what you can do is you can come up and if you open up a terminal and I need to make this readable for you no I don't because I'm just going to tell you guys know how to do this you're going to do a pseudo raspy config like that okay and now the raspy config comes up and you see that you can come down to interface options select that and then you can say enable or disable Legacy camera support and then you can come in and say enable Legacy camera support and then I'm going to say yes okay so that says okay and now I was already on Legacy support if you just moved to Legacy support it's going to make you want to reboot but I didn't want to sit and make you wait through a reboot so I'd already set this up and so now where we are is we are on Legacy we are on Legacy Legacy camera support now you guys that have been through my Jetson Nano class or my Judson Xavier class or my EI for everyone class you have already been introduced to opencv and how to interact with the camera in opencv okay when you enable the Legacy camera support everything works just like it did in the past and so again I haven't showed you yet on the Raspberry Pi how to install opencv I'm going to do that next week next week I'm going to show you how to plug the camera in I'm going to show you how to install the libraries and I'm going to show you how to fire up and run your camera for the first time and you can see here if I look over here you can see that the way I have it I have the I have the camera plugged into the Raspberry Pi just a heads up guys guys I have found that these little cameras are somewhat static sensitive and I found a lot of them are fairly easy to blow out and so once you take the little camera out of the static bag you want to be very careful you know you know like don't touch the leads you want to kind of ground yourself you just want to be careful with it because you can fairly easily burn these things out I've lost a few cameras along the way and then it plugs into this little CSI slot here notice that the little blue the little blue label points towards the ethernet ports and so that's how you know which direction the blue label points in here and this is a standard connector you just pop the plastic up on both ends you press this down in it and then you press the plastic the little plastic bar back down I'll show you how to do that next week and then what I like is I have this do this goofy little tripod and I just take tape the camera to the goofy little tripod so you see I already have this hooked up but I will show you more in next week's lesson how to do it and then what I did was I installed opencv which I will show you how to do next week and you see that we can operate this camera in 15 lines of code we import the CV2 Library we set the resolution I've set it at 1280 by 720 and then what I do here is I don't think I need import time I'll get rid of a few lines of code there okay what I do is I set up a camera using cv2.video capture and I show the path to the camera slash Dev slash video Zero then once I've connected to the camera I do these CV2 commands to set the display width which I said here and set the display height which I set here now I just set up a loop where I go out and from the camera I grab a frame and then I create a window I called Nano Cam and I show so I grab a frame show a frame grab a frame show a frame and if you grab frames and show them in proper sequence what do you end up with you end up with you end up with wait for it a movie okay so you see I've got live video here coming from the little Raspberry Pi camera and if you look at that wow that is like let's look you know you know that right here me down here in the corner the little me is in real time and then this is coming off the Raspberry Pi you can see one two three four five there's virtually no detectable latency at all and so we are getting a super great video stream coming from the Raspberry Pi and then I've got it set where I can just click queue and then I can leave this and so this is Legacy how we would do things for you guys who have not used the camera yet you can see that I'm going to teach you how to use it and you're going to be up and making that camera sing and dance in under 15 lines of code and it's very easy to understand and this is the way that we used to do things okay now this is the problem if I teach you how to do things you using the Legacy camera everybody is going to be moving away to the new camera and this is going to have the same problem it's going to become obsolete very very quickly so this is a way to do it but it is not the way we're going to do it all right so what I'm going to do is I'm going to kill this program and then what I'm going to need to do is I'm going to need to turn off that Legacy camera support so I will come back here again trying to get a terminal okay I'm going to do a pseudo raspy config like this and then I'm going to come down again to interface options enable camera do you want Legacy support no because when you enable Legacy support you disable the modern camera tools okay you disable the modern camera tools okay so Legacy camera support is disabled all right and this time we are going to have to reboot would you like to reboot yeah let's go ahead and reboot and we'll come over and we'll look at a beautiful view of the river here on this rainy morning uh look at a beautiful view of the river on this rainy morning as we wait for the Raspberry Pi to reboot the good news is 64 bits will will uh reboot pretty quickly so what do you guys as a reminder what is all that you need to do for next week is you need to have your 64-bit card flashed and you need to be able to boot in 64-bit and then you need to go ahead and make the adjustments that you want to make to your desktop and get everything configured the way that you want it configured in the way that you enjoy having things work okay we're now rebooted and so I'm going to come back to thawny and so I will come back to Thane and this time I'm going to come up with this program and this is still an opencv Pro program but now we interact with the camera differently in the Legacy on this operating system in the old way back on Bullseye the way that you did it is you had opencv call a method you would call a method in opencv to go out and grab the frame from the camera so you load the opencv library and then there you set up the camera and then there is a command in opencv where you go out and you grab a frame in opencv and then you show the frame in opencv and then you grab a frame in opencv with the new method of interacting with the camera you are not able to have opencv go out and grab the camera but that's okay go out and grab the frame that's okay because the 64-bit operating system gives you a command a python command that allows you to go out and grab it it's just not an opencv command so let's let's go through this so what is it this is still at its core an opencv Pro program so we're going to import opencv I don't think I need to import time I'll take that out okay now besides importing opencv we are importing a library called Pi camera 2. that is the library that talks to the camera okay and so what I do is I create an object Pi camera and now I've got to set some configurations like remember earlier we did like a cam set this a cam set that in opencv well now we're we will set those parameters not in opencv libraries but in this Pi camera 2 library and so what you can do is I set the size here of the image I do a preview configuration.main.size I set the size and then I set the format for the image I do this command called align which just says p pick the natural screen resolution the closest to the one that I ask for and that for that way if I don't ask for exactly the right camera size that it likes to use it will pop to the one that's closest to it and then what I do is I've created this preview parameter here and then what I do is I configure the camera with that preview parameters that I set up here and then what do I do I start the camera now what is happening the camera is just sitting there running but it's not going to do anything because the camera is just sitting there running the camera is operating it's grabbing frames but nothing's going anywhere well what we do here then is we create a while true I don't need that line of code and then what do I do I grab an image but I don't grab it with an opencv command I grab it with a pi cam command and the command is capture underscore array now opencv has a frame from the camera that it grabbed using the pi cam library and now I issue the CV2 command of showing the image all right and then what this is just saying is wait and if if it sees the q key then quit so this is just a clean clean way to exit the program so let's run this thing and see if it works it gives you all that red information down there but it's not boom [Music] okay so again that is a very very nice resolution and let's see let's see one two three four five no latency at all a nice big crisp but beautiful image that is showing that we can now make the Raspberry Pi camera work on the new operating system the new way now the only thing that's really different for you guys that are familiar with opencv the only thing that is really different is just setting the camera up and then how you grab the frame everything else that you know about opencv all our of our ability to do artificial intelligence all of our ability to manipulate the image all of those things we can still do mm-hmm but we just set up the camera and grabbed the frame differently also if there's some reason that you absolutely have to do it the old way all the lessons that I'm going to teach you should work on the old system let me come back over here should work on the old system it's just what would you do differently is is that how you set up the camera and how you grab the frame and so if for some reason you're in some unique situation that you're forced to proceed with either the old operating system or the old mode of interacting with the camera your code will be exactly like my code in all of these next 20 or 30 lessons except for you will be setting your camera up like this and you will be grabbing your frame like this but now once you have that frame everything else is going to be the same guys I am sorry that I have sort of taken a lesson just to get this straight but it's been this thing that has been a really really big deal and it's been this thing that I've really really wanted to be moving off into the camera portion of this class but I just couldn't find the right path now I have the right path we are on the new operating system we are interacting with the camera camera the new way excuse me uh the new operating with the camera the new way on the new operating system and so this thing that I'm showing you should be working for the next years and years and years and years all right and so I'm just trying to think that there are two groups of people that are taking the class the people that are taking it right now with me as we go along in real time like today and then there's those people who will be coming in two years from now and so I'm talking kind of like to two different points of time at this same time as I speak but what I put together here will work now today in my time but also should work for people who want to take the rest of the class in the future you guys give me feedback does this make sense what I'm saying I mean do you kind of understand why I took today to try to get you guys normalized do not install opencv do not try to get ahead of me okay I've told you the operating system install the operating system and then next week I will show you how to install opencv so that everything will work the same for us it'll work the same for me and it'll work the same for you you guys that are doing this in the future make sure that you install my version of opencv the version that I'm showing you to install make sure that you install that even if in your time in the future there's these more future versions of opencv you need to be using the same version of opencv that I am in that way everything should work okay guys I hope this was okay with you I hope that you're not frustrated that we didn't make the normal progress that we make in a in a class but this is a new point it's kind of like a new section of this class and I wanted to take one uh one class period to just sort of introduce to to you where we're going and why we're going to do it now we are going to be doing some exciting things like what's one thing that you see right now based on the last few less that we had that would be cool it would be cool that if you could incorporate this camera with your security system so that if your security system sees something if it sees motion from your PIR sensor you could go out and turn the video on and you could capture some frames or some still images of what triggered the sensor so you see right off the bat boom this thing would be really really cool to be using using with that security system that you guys are working on and so that's one thing and then the second thing is is that this is just going to open up we're going to get into you know just the basics of using the camera and then we're going to start getting into some pretty cool artificial intelligence things of things that you can do with the frames that you're grabbing that you know it's sort of like uh when you look over here let's see if this is right no that's not right this is it so what you see is is that you are grabbing a frame and then you are showing a frame but between grabbing the frame and showing the frame this is the magic spot here and we can do anything that we want here and even though we're grabbing frames at 30 frames a second what we have is a 30th of a second between those two lines of code and that is a lifetime at the speed that computers operate so there is all types of Mischief that we can do between those two lines of code and this is where we're going to be doing our artificial intelligence and all the neat and cool things are going to be between those two lines of code so that's what's going to be the next probably I would say wouldn't be surprised if we have another 20 lessons or so on this particular topic and then the cool thing with the Raspberry Pi is when you see something and then you understand something by analyzing the frame now because we have those gpio pins we can go out and do something we can move a Servo we can send a message there's all types of things that we can do based on what we see in the frame okay guys I hope give me feedback did I just make you mad was this lesson a waste of time or does it kind of help you understand where we're going and why we are going in that direction if you guys like this lesson be sure to give us a thumbs up if you haven't already subscribe to the channel when you leave a comment down below that really that really helps us a lot with the old YouTube juice and then make sure that you share this share this video with other people because the world needs more people doing coding and fewer people sitting around watching silly cat videos Paul McWhorter with dogtechboy.com I will talk to you guys later [Music]
Info
Channel: Paul McWhorter
Views: 10,703
Rating: undefined out of 5
Keywords:
Id: W_5ZVUmZucA
Channel Id: undefined
Length: 26min 34sec (1594 seconds)
Published: Thu Jan 12 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.