Raspberry Pi 3 Tutorial | Raspberry Pi 3 Projects | IoT Projects | IoT Tutorial | Edureka



hello everyone this is Nev from Eureka and welcome to this Raspberry Pi tutorial session now this session is going to be slightly long in comparison to most tutorial sessions that you see out there on YouTube but this will give you a complete understanding as well as an in detail with respect to Grass Valley pi3 now looking at the agenda for today we will talk about what is raspberry pi and the radius hardware configuration of raspberry pi which has changed over the years we'll also be comparing them with respect to the different models that has come out after that we'll be looking at how to install an operating system on raspberry pi and then we'll be looking at a tutorial using one of the major additional components to raspberry pi with a sensor following which at the end of the session we will be looking at a demo using raspberry pi which is going to be a motion detection camera now in our science hat tutorial section as well we'll be looking at five different demos thereby giving you a complete understanding as well as a good learning experience from this session now I hope you guys are definitely interested for the session let's move forward to the first topic which is basically the need for raspberry pi now raspberry pi today has become so common that you can find it across most households as well today it has become one of the most cheapest and common computing device that can be found almost everywhere but let's actually go back to understand the ideology which bought raspberry pi into development itself now raspberry pi basically was bought by the Raspberry Pi foundation to introduce or to bring in the information technology back to the schools wherein students can learn how to program from scratch the growth of technology today has grown to such a level that everyone today has easy access to do anything on a computer but back in the early and late 90s and 2000's for using a computer you needed to know how to program and how to work around with respect to it so this in turn helped to build a very strong foundation for programming knowledge and with the growth of UI everything has become so easy that today you don't need to learn programming to do much but at the same time this has made it harder for people to identify and understand good programmers from those who are not so in order to build a generation which starts with a very strong programming foundation and fundamentals the main ideology was to introduce or take back IT to the basics and make it accessible across every school as well now again as I said it was introduced by the Raspberry Pi foundation in 2012 as much now moving forward what exactly is Raspberry Pi now this is one of the questions most of you would have across your mind as well because you might have heard about Raspberry Pi but you might still not have a clarity so let me help you clarify that right away now as per the definition Raspberry Pi basically is a series of various small single board computers which actually have additional features as bluetooth Wi-Fi USB capabilities general input/output ports and so forth now it basically is a very small low-cost credit card computer which actually can be plugged into any monitor as well as you can include a keyboard and mouse and it increases the opportunity for people to explore learn and understand how to program as well now the latest version of Raspberry Pi is Raspberry Pi 3 which was released in February 2016 as well now Raspberry Pi basically is a combination of Raspberry operating system and Pi who is basically stands for Python programming language but before we move forward let me just show you a very simple video which Raspberry Pi has put up so that you can understand the ideology of Raspberry Pi foundation as well this is a Raspberry Pi it's a credit card size computer that costs around 25 pounds designed to teach young people's program and is capable of doing all kinds wonderful things back in the 80s kids had to learn how to code computers to use them and as a result these kids grew up with an inbuilt understanding of how computers work now we need more programmers than ever before so to deal with this problem some clever people came up with the bathroom pie to reignite this bar it trans linens a free operating system from an SD card just like the one in your digital camera and it's powered by a USB phone charger you just plug in a mouse and the keyboard connect it to a TV or monitor and you're ready to go in schools not only is that very pack a great way to learn programming skills as part of ICT there are also dozens of cross-curricular applications next science a music and all over the world people are experimenting with raspberry PI's and attending raspberry jam events where people of all ages are learning what can be done with a Raspberry Pi since the first Barbary pirate ship we've seen examples of people using the PI in a variety of amazingly interesting projects taking advantage of its size portability cost program ability and connect ability so whether you want to learn to make in the robot or even teach about pear-shaped with Raspberry Pi in the sky's the limit great so I hope you guys had a great learning experience with respect to that that was basically the ideology of the Raspberry Pi foundation on introducing Raspberry Pi into the market as well moving on some of the capabilities that Raspberry Pi enables you to do is that it helps you to browse the Internet as well as what complete HD videos on the same device as well so all you need to have is a HD supported display as such apart from that even basic operations like making spreadsheets creating words presentations all these can be done on Raspberry Pi and you have a huge set of games that are available which can be played on Raspberry Pi making it quite interesting and easy as well for people to enjoy the component as well then you have various add-on capabilities like infrared cameras and security system which can be built keeping Raspberry Pi as the core hardware as well then you can also use many music machines as well as detection of weather stations which we actually had done in a previous session as well now these are just some of the top capabilities that I have picked up from the list Raspberry Pi today has become one of the biggest component that has enabled users to achieve and create a lot as ba 3 the capability of Raspberry Pi is restricted just to your imagination whatever you can imagine can be done using Raspberry Pi given the amount of effort put into that now moving on let's look at the Raspberry Pi hardware as well before that let me show you and I would be using a Raspberry Pi as part of this tutorial session so let me just give you a simple overview of the component as such now what you basically see is that the Raspberry Pi hardware so let me just switch over the camera and let me show you the last free path now here what you're seeing is the Raspberry Pi 3 hardware as such and this is your processor and system-on-chip which is an Arduino a 53 processor now two important ports here is the CSI port which is the camera serial interface where you can connect camera directly to the Raspberry Pi and the DSi port which is the display serial input port okay now let me just flip this over slightly and if you see this is a 2.5 mm microUSB connector so your standard mobile charger can be used to charge the Raspberry Pi and this is a standard HDMI port for display so your standard TVs and monitors which have an HDMI support can be used to become a video interface for that then you have an audio jack which is used to connect your audio input now let me just flip the slightly over and let me the zoom out a bit now if you see we have an Ethernet connector following which there are four USB slots as well so when you see here there's a flippin general input output pin present here so this is something that's quite interesting and configurable from your Raspberry Pi a software well you can configure for what each purpose pins can be used which we'll be seeing a little ahead now the final thing that I want to show you is behind here when you flip back sides there is a microUSB slot present here this is mainly to insert your memory card and when I say memory card I would generally recommend at least a 16gb memory card this is mainly because the operating system in itself is about 4gb and if you use an e 8gb then what happens is there's very less storage space for your operating system to work on as well so a 16 GB memory card would be really helpful and one thing that you won't see is this is an Evo class which is something similar to a class 2 memory card so if you're getting a memory card make sure it's at least a class 8 or class 10 memory card so that you can have high disk read and write processing now coming back now moving ahead let's just came through the various changes that has happened over the hardware of raspberry pi now we are not going to devote too much time into this because this is a completely in detail session how I would be stopping at these slides for 10 seconds so if you wish to know more you can pause the video and get a complete look as well now talking about the processor the first generation of Raspberry Pi initially came with a Broadcom BCM – 835 SOC and it basically was similar to the first generation smartphone chips and the architecture that was used also was an AR m v6 architecture now over the years raspberry pi 3 has grown a lot and today it has a capability of 1.2 gigahertz which basically is because of the AR m cortex a53 64-bit processor and is considered to be 10 times faster in comparison to Raspberry Pi Wow now talking about the change in Raspberry Pi over the years as you can see here the various models have been listed and the architecture change has also been mentioned here as well so in case if you are interested to know more you can pause the video and take a look at this now when you come to the memory the first model of Raspberry Pi came with a 256 mb ram and which basically were shared by the GPU but today with raspberry pi version 2 and 3 you have four times that you have about 1 gb of ram which again is shared by the GPU as well now the default split was at 192 mb ram for the CPU basically which was more than enough to play a full HD that is a thousand ATP video or performed simple 3d operations but again not to complicated operations as well now going forward when you look at the networking capabilities now in terms of networking capabilities the model a of Raspberry Pi did not have any such features but from model B of version 1 itself you had an Ethernet port which was introduced here and from version 3 you also have Wi-Fi and Bluetooth capabilities introduced here as well now talking about the peripherals in Raspberry Pi there are basically 4 USB ports now this has been introduced in model B version 1 plus onwards and today you have a lot more that you can do with respect to that even audio input ports and audio output ports have not changed over the years but the onboard storage has changed a lot with respect now again when you look at the video capabilities video controllers basically here you can wash complete hesti videos but Raspberry Pi does not have a 2:56 decoding hardware but the cpu in itself is very capable and helps you in decoding the H 256 encoded videos through software operations now in terms of GPU the GPU in Raspberry Pi 3 runs at a higher clock frequency which is about 300 or 400 in comparison to the previous versions which was at about 2/3 six megahertz now in terms of video input you have a 15 put CSI connector that has always been present with the Raspberry Pi and video output has have changed over the years you have a HDMI port you have a DSi port and now you also have a 3.5 mm trrs jack as well now now in terms of the connector capabilities there are 17 pins of the GPIO port which can be configured as per your requirements as well now moving forward these are the various details with respect to the general input output pin this data has been taken from Wikipedia so in case if you are looking for more information you can definitely check out wiki space or the official Raspberry Pi documentation as well now coming down let's begin the Raspberry Pi installation process hum parts first let me help you understand the different operating systems that are available at present ok Raspberry Pi in itself supports multiple operating systems are such but will mainly be working on raspbian ok so these are some of the most for applo operating systems supported on Raspberry Pi so you have RISC OS you have FreeBSD operating system you have net BSD operating system plan 9 is again from Bell Labs as well as Windows has its own Windows 10 off IOT version okay so for this session we are not going to go into the Windows 10 we stick to the core Raspberry Pi operating system now for downloading the operating system you can go on to the original site that is Raspberry Pi dot o-r-g and there in the Downloads tab you can download the operating system let me just show it okay so this is the Raspberry Pi homepage and here if you go on to the download section you can download the operating system now if you are starting off with raspberry Pi an Internet of Things trust me this is the best place that you can find a lot of informations with respect to it okay most people actually publish their details with respect to the projects that they are working many of your projects are also available you can find a lot of help as well as good information here okay so this is definitely the place to go to if you go onto the download section here okay this will either show you two options you have noobs or you have raspbian I would recommend that you go with notes because this is a complete package with respect to the different operating systems as such so here again you have noobs and noobs like so my recommendation would be you download notes and make sure you using a 32 GB memory card but if this would be really helpful because it gives a lot of memory for your operating system so in case if you're going for a 60 GB or below I would recommend you go with the noobs line but make sure you keep the bare minimum of 16 GB in case if you are working with Raspberry Pi but do not mistake me when I say use a 16 GB memory card you can install it on an 8 GB s1 but again the operating system has less memory to work so at least go for 16 or higher 32 is what I would recommend so once you download this zip file or you can even download it by a torrent ok but I would recommend download it as a zip file let me show you the file so this is the noobs file let me extract this ok it may take some time it gets about a 1.5 GB file okay the Lites version is slightly lower in comparison but this is something that I would recommend in case if you're working with Raspberry Pi ok so I have my noobs folder here so what you need to do is that you need to copy everything inside the noob folders and then paste it inside the SD card ok make sure you are not directly copy pasting the folder that you have extract so what happens is if you do that it does not actually recognize the operating system as part of the Raspberry Pi so copy everything that you've extracted and then directly paste it inside the SD card now again this is why I recommend that you use a high-speed memory card because in case if you are not using it then what happens is that it takes a lot of time with respect to fetching the data ok now as I had mentioned if you're going for a memory card for your Raspberry Pi you can use something like a 16gb at least and make sure it has a high transfer speed so this in turn will give you a lot of memory area to work around with as well as I would recommend you take something like a class 10 memory card that is available in the market today so these have a very good read and write speed ratio so definitely this is something that you should consider while you're getting a memory card for your operating system ok now once you are done copying with this let's go on to install this memory card on to a Raspberry Pi and let's begin the installation process okay so now we've successfully copied all that is needed for our operating system so safely remove this make sure you're ejecting it safely but then sometimes what happens is if we do not safely eject it the files get corrupted before you load it into your Raspberry Pi this is certain issue with respect to the memory card so just eject this ok so this is my Raspberry Pi and if you actually flip it over this is the slot where you have to insert the memory card now we've copied the noobs folder into this memory card again let me just insert this into this and let's begin with respect to the installation process let's begin installing this memory card on to my Raspberry Pi and start with the setup so let me just turn though on my Raspberry Pi okay so this is a screen I'm getting by default now what happens is the installation steps initializes so the Raspberry Pi is getting loaded now there are two operating systems that are present here by default and we want a raspy and so let me just select raspbian and click on install option present here now if you see here it basically is telling me that it requires 4.5 GB so this is why I was recommending you to get at least 16 GB or more because if I have an 8 GB memory card a 4.5 GB goes off with the operating system itself then there's not much memory left for me to work around with now let me just click on install that incase if you are using a different language or if you want to use a different keyboard as well you make sure you are specifying that okay so there are in languages present here so choose the corresponding language as per your requirement once you selected that this click on install and this is just basically going to ask you whether you want to format your data and install the operating system on top of this so click on yes and the installation process has begun now it may take some time so I request you to be a bit patient because this is an operating system installation process so please be a bit patient and hope you have fun meanwhile so now as you can see the operating system installation has completed successfully once you hit on ok it's going to ask me whether I want to reboot or it would automatically reboot as per ok so yeah it's automatically rebooting at this point you okay now as you can see the Raspberry Pi operating system has successfully been installed okay so this is what your Raspberry Pi operating system would be looking like okay so this is raspbian as such so there are different operating systems that are available today for you to install that we have discussed already now that we've installed her as being on our system let's look at some of the accessories which can be used with raspberry pi now one of the most popular and interesting accessory to Raspberry Pi is the sense hat okay so that basically is a hardware attached on top there are various hats that are available but Censored is the most popular because you have various onboard sensors present here you have a temperature humidity and pressure sensor present here as well as a gyroscope and a joystick also present here apart from this the reason that it is quite popular is because it has an 8 cross 8 LED matrix display that is present to it so let me just switch over and show you the sense hat component as well and ok so here you can see the sensor now how it is slightly different from the other accessories is because it's got an 8 cross 8 LED matrix present here which can be used for displaying various things and we will also be seeing how you can display this as well now coming on to the other components here now if you see here it's already got multiple sensors here it's got an axle ohmmeter our gyroscope meter present here it's also got which is this part the axle and gyro meter present here so you can see it's got a labeling asma then you have a humidity pressure and temperature sensor onboard with respect to this and it's quite interesting and useful as well now one of the easiest things with respect to this is that it can directly be placed on top of the raspberry PI's GPIO pins and thereby making it quite easy to assemble it as well so it directly sits on top of the GPIO pins as well so this is something which makes the entire Raspberry Pi eco system quite easy and effect one other interesting key point or factor that makes the sensor quite interesting is that it's got an on-board joystick as well so in case if you are a gamer and you want to try out the games on Raspberry Pi he didn't use this joystick as such now another additional component that most people use with Raspberry Pi is the camera now in 2013 itself one year after Raspberry Pi 1 was launched it had introduced a Raspberry Pi camera along with the we're update as well now the respite camp is basically an 8 megapixel camera and can directly be connected to the CSI port present on the Raspberry Pi itself now it's also very interesting and can record up to thousand ATP videos as well so moving forward let's also look at the infrared camera so this is a very interesting thing so this was something that helps you capture video in infrared mode and it's called pine oil ok so again these components can be bought online and is one of the most easily bible now the final accessory and one of the most interesting and essential accessory to the Raspberry Pi is the GERD port now basically it is used for educational purpose and it helps you expand the operations done using the general input/output pins here so using this you can connect to various LEDs which is analog devices sensors and much more this also helps you connect to Audrina which is also another dy I hardware device which has gained a lot of popularity but in comparison to raspberry pack original is still growing stitch moving on let's begin with our sensor tutorial and what we'll be doing is we'll be exploring five different demos to understand how the sense heart component can be used effectively now the first thing that we'll be doing is we'll be implementing a very simple code and we'll be trying to display a certain letter on top of the sensor ok so I'm going to display E and D but the value of that color is going to be generated by random ok so let me just run you through the code that's present here so the first line is from censored import cells so what it basically is doing is that it's helping you import sensor and establish a connection to the sense hat component we're going to use time for mainly sleep function and random for generating a random integer now what I'm doing is that I am initializing the sensor which is sense equal to sense that basically initializes it then what I'm doing is that I am generating a random integer between the range of 0 to 255 now for those of you who would have guessed why I'm doing this definitely this is because the RGB value lies in this range so it's somewhere between 0 to 255 then what I'm using is that I'm using a censored function which is show and then I'm specifying which letter it needs to show and I'm going to specify the color combination so this is the RGB values present here okay so it's going to show the letter E and it's going to create a random input with respect to that same okay then it's going to sleep for one second again generate a new random integer and then it is going to show D okay so again it will sleep and then it's gonna clear so let me just show you this do you practically so now what I'm going to do is that I'm going to connect to my raspberry pi using VNC Network so it's a virtual network which I'm connecting it to because it's not quite easy for me to record the video on the Raspberry Pi so I'm going to use VNC server for that and I'll just give you a simple idea of how you can connect to VNC server to your Raspberry Pi as well now one essential thing that if you are connecting to the VNC server then you both need to be on the same network okay so what I've done is that I have used a hotspot connected both my raspberry pi and my laptop to the same network so in case you are wondering how to connect to your raspberry pi wire remote server this is how you do it just go to your settings go to preferences you have raspberry pi configuration here now in your interfaces make sure that V and C is enable once you've done this then VNC server gets enable and on to your system just download VNC server and we and C viewer and you can connect your raspberry pi quite easily okay so let me just show you the code which we're going to be executing now it's the same that we have seen earlier so let me just make a small modification to this so this is our code again as we have seen we are first initializing the sense ID with sense equal to censored then we are generating a random integer and then we're showing a letter e on that so let me just change this let me just set it to zero and let me just copy this once more and I'll also show a third combination here as well so I'm just generating a random value between 0 to 255 and I'm displaying based on that color letter II D and F okay so let me just save this once so let me show you the output that is going to be displayed on the sense hat as well so so let me just execute the program okay now let me just switch over to the sense art so that you can see the output it's a red e a green D and a blue F as well so this is what so based on the inputs that I have given it has displayed a certain letter on the censored LED display as well so let's go back to our presentation and look at the next program that is involved here so the next program basically is going to display an image now what it does here is that it basically is going to display an image that gives you a complete idea of the various color combinations possible on the sense at as well so what I've basically done is that I've identified the RGB colors red orange yellow green blue indigo violet and E stands for empty which is not OK and based on this I have created a random matrix here but each of these values defines for a pixel of the sensor now as I have mentioned to you earlier this is an 8 cross 8 LED matrix so each of these values is for one of the individual pixels themselves and with respect to how they start the numbering starts from left top position so accordingly it goes in a row by row manner okay so let me just show you the output for this as ba so this is our program and let me execute this I'm sure and now let me just switch over to the Raspberry Pi so here you can see the different color combinations that are present on the Raspberry Pi sensor the first row was left completely empty the next row has two R values present here so this is how it has been defined if you notice the code here there are two R's following by three empty spaces and before that also if you can consider three empty spaces that is one row so every specific value is pertaining to one specific row as such now coming back to our presentation so the third one is quite interesting what we're basically going to do here is that we are going to rotate a letter based on the different orientation of the screen so let me show you how this is done rather than just tell it you so what we're basically going to do here is that we're going to rotate a letter J on different angles as well so we've defined the different angles 0 90 180 270 and these are the various angles which is going to rotate for okay I'm going to run a for loop where it rotates the same on different angles as well so let me show you that so just let me add some start here here now the reason I'm doing that is mainly to ensure that the sense hat is cleared after the rotation process so let's execute this let me switch over to the raspberry pi and if you see here a J has been displayed and it's rotating okay it has stopped so let me just rerun this once again so what is happening here is that I am rotating the letter J by 90 degrees and it's completing two complete circles on the raspberry pi okay so it's a very simple thing but it's important that you understand how this is done because what we're basically doing is that we are setting the rotation using this sensor okay and then we're sleeping at point zero five milliseconds as well now I did you can increase the delay here you can change the letter here you can even change the angle to understand how it works as well so this is something that you should definitely explore about and get a better understanding with coming down the next and most basic thing that you can do using sensor is that you can measure the temperature pressure and humidity so we've already tried to do this in our previous session as well where we've measured the temperature the pressure and the humidity now here I'm just rounding it off and based on a specific value I am going to ensure whether the display is going to be red or green as well so let me come back to my sense at let me just open the code and we will modify this on the go to get a better understanding let me explain the code once again so first I'm establishing a connection to the sensor then I'm running an infinite loop where I'm getting the temperature the pressure the humidity I'm rounding it off and if the temperature is about 36 so this is just a value that I have set then the background color should be green and the color of the text should be complete white ok so this is a simple modification I have made else in normal situation if it is less than 36 degrees then what it should be is that it should have a background color of blue and the text color should be yellow so this is basically to help me identify the different radius then I'm creating a message variable which is storing the following format where temperature is equal to temperature value pressure is equal to pressure value and humidity is equal to the humidity back finally I'm going to show this message on my censored LED display screen so let's just see how this works and execute the program so let me just execute the program and let me also switch over to the Raspberry Pi so here let's begin with the execution of the code so now you can see by default it is having a blue background and the text is actually in yellow ok so if you would have noticed the temperature is about 34 degrees centigrade so to this letter or scroll once more let's just validate the value of temperature you can also print this into the screen you can also send it by an API and much more so if you can see it's thirty four point two degree centigrade now to this what I'm going to do basically is that I'm just going to introduced a hot water source okay so I'm just trying to raise the temperature here so let me just shift a little bit and please keep a note on the temperature value so the temperature has started rising you so it is taking some time I think the water has cooled down a bit I all right so it's started now the color background color has changed from blue to green and the text color has changed from yellow to white as well now these can be used in critical measure environments as well so let's say you are in a situation or in an environment where you need to have a constant monitor and constantly be aware with respect to the environment change in example like space or any other environment that you're working with definitely these are certain things that can really be important and helpful as well so coming back lets us look at the last program of the sense ash tutorial which is basically detecting the motion of the sense at now what I'm basically going to do here is that I am going to rotate my sensor and I'm going to identify the value of pitch rule and Jana basically these are the orientation with respect to the x axis y axis and z axis and this is just from the orientation of the sensor as well now this is mainly done using the gyroscope but to get a better understanding and more precise value will also try to include and incorporate the accelerometer as well so let me come here let me just show you the program so this is the program as well so let me just stop the execution here so as I had mentioned this is going to run infinite number of times because the while statement here is indefinite so let me just stop this and let me just run the orientation program and let's just see the default values of pitch yaw and roll first so now by default if you see pitch is about zero rule is about 96 and yawn is about zero itself now let me just switch over to the sense at and what I'm going to do parallely is that let me try radiating the value of the sensor as well or let me try rotating the sensor to give you a better understanding of how it works simultaneously you can also see the change in pitch yaw and roll so if you see here I am slightly lifting it and the value of which has risen from 0 to 6 roll also has changed John also has change I'm going to try elting it see him pitch roll and yaw also has changed so I'm just tilting it with respect to various accesses and you can see the change here do you notice the changes I definitely hope you do okay so now let us actually stop the execution of this program because this is also an infinite loop and to same orientation program let us actually try to incorporate the axial ohmmeter and understand how more precise we can make now instead of just taking the pitch roll and yaw on I'm here going to directly take the value of acceleration here we had taken the value of orientation and here we want to take the value of acceleration okay how basically the first is with respect to the gravitational force that acts on us so now let me just show you the code here now again what you need to understand the difference between gyro measure and axelrod measure is just that it senses both the static as well as dynamic change with respect to that but your gyroscope mainly measures the rotation of a specific device as such okay so let me just execute this program as wha so let me just first begin by clearing the screen and then we'll execute the code once again so let's just execute the acceleration code to get a better understanding and simultaneously what I'll do is that I'll just show you how the change with respect to the accesses or how you if you change the raspberrypi how the value will also change so by default if you can see the value of x is 0 the value of y is also 0 and z is 1 so now what I'm going to do is that let me begin by slightly rotating the raspberry pi now if I change the raspberry pi into a vertical position like this okay so it's a perfectly vertical position but if you notice the value of x it has become minus 1 okay Y has become 0 and Z has become 0 same time if I rotate it in such a manner I'm just keeping it on different axis the value of x becomes plus 1 instead of minus 1 same with respect to Y if I change it in such a horizontal way it is minus 1 and if I change it in such a manner then it becomes plus 1 ok if you flip it completely over then the value of Z becomes minus one as well so if this is the vertical err position then the value of Z remains one I hope this is clear for you guys so again these are all different parameters today what I have done as part of this is that I have just helped you understand how you can explore the various parameters and various components that are associated to the raspberry pi sin site as well now how you use it and what you use it for is completely left to you these are just some of the basic things that you can do using raspberry pi the limitation of raspberry pi stops where your imagination stops now moving forward let's look at the most important part and the interesting part of today's session which is basically the demo using raspberry pi so what we're going to do here is that we're going to try to create a motion detection system so we're going to build a security camera system which detects the motion in front of it and it captures an event based on this so how it does is that first you're going to store an initial frame so this is going to be my reference so here image is going to get converted to the option blur image so this is going to be a grayscale image actually hadn't going to get converted to Gaussian blur and simultaneously it's going to take a frame with object once the initial frame is set then what it's going to do is that it's going to take the frame with any changes and then it's going to convert it to Gaussian blur image so this is going to be my reference so once I do that then I'm going to take the difference between the initial frame and the converted Gaussian blur image and if there is a difference detected I'm going to save this image if not I'm just going to keep checking for any change with respect to that so let me just show you the code here now for this we are going to use Android IP cam web application okay so this can be downloaded from the Google store let me just show you so this is the application that we are going to be using for this demo it's IP webcam so you can check it out on the Play Store and I'll show you how you can identify and connect with this so let me come back here so here what you're going to do this is the program that we are going to use for motion detection now firstly you're going to use import user live this is basically to connect to the Android device now like I had mentioned if you want to know the IP address just launch the application click on start server and you'll be seeing the IP for address which I have specified here ok then you're going to use CB 2 and time which is most important libraries as part of it see we do this what we're going to use for the image processing and I'm also using numpy so all the images that we are going to be storing are going to be processed by numpy this is basically to help us create a pixel image with respect to the initial image taken now as specified the URL of my IP cam and what I'm doing here is that I am connecting to that then what I'm going to do is that I am going to convert it to an umpire array and then speak in my CV 2 dot image decode so I'm going to begin the decoding so this is just for your reference you can also remove this and it will still work the same ok now what I have done here is that I have initialized my value of I to be 0 now this is something that is quite interesting and important to remember then I'm going to run an infinite wire loop now here I'm just doing the same thing I'm just connecting to my IP camp I am going to take the image into an umpire format and I am going to decode and then what I'm going to do is that I'm going to convert the initial color image to grayscale now before I create a Gaussian blur I need to create a grayscale image so that's why I'm going to first convert the color image to a gray image then what I'm going to do is that I'm going to create a Gaussian blur image where it I'm going to specify the grayscale image then 2121 is basically the frame size and 0 is just a parameter then what I'm going to see is that I'm going to first check if there is a first frame define if there isn't then the Gaussian blur image is going to become my first frame and then I am going to go back into the loop to take the next image if not then I'm going to execute the following code now once I have identified this then what I'm going to do is that I'm going to find the difference between the same okay so if I have not defined the first frame then I'll assign the greyscale image I have this taken asked the first image if not then what I do is that I'll identify the difference between the first frame and the greyscale image that I have taken then what I will do is that I will define a threshold here now the idea of defining a threshold is that if an object does not occupy a minimum of 30 pixels okay then it's not worth capturing in camera so what I am drilling is that if it is less than 30 pixels then make it white that's what this function does here okay so if it is less than 30 pixels ignore it and change it to white color okay and then what I'm going to do is that I'm going to dilate the image using the C v2 dot dilate and what I'm doing here is that I'm just making the image a slightly more sharper and precise image with respect to that now the function C v2 dot fine contour is what it does basically is that it helps you make your image sharper basically it creates a curve that joins all the continuous points or the boundaries and make it a sharper image with respect to that same so I've dilated the image now I need to sharpen it with respect to that and then what is happening is that it's going to show me the frame of the image as well so I'm just going to define a condition where if it is less than 1 lakh then I am NOT going to take the picture but if it is then I'm going to define a boundary okay and then I am going to capture it with respect to an image ok so let me just run this and first let's establish the first frame and it will show me the frame as well okay so the first frame is getting initialized here let's just have a look at the first frame all right so what it is doing at this moment is that it's actually initializing the first frame so that it can have a reference with respect to that say okay so I have a friend who is just opening the door and we are trying to capture the detection from that and let's just see how this I said now we've defined cue to exit from this frame so let's just come back to this and let me just try to close it okay this certain times does happen that it gets stuck because sometimes what happens is the reference frame slightly becomes different but let's just look at the images and it has started capturing the images okay so let me just show you a simple idea of how it has captured the images okay so as you can see it has captured all the motion that was beyond the frame as well and it is also created a frame in respect to the motion wherever it has detected so this can be further modified for any future references wherein you can also improve this for a face detection system and so forth as well so let's go back and with this let's come to a conclusion of this session hope you had a great learning experience thank you and good bye I hope you enjoyed listening to this video please be kind enough to like it and you can comment any of your doubts and queries and we will reply to them at the earliest do look out for more videos in our playlist and subscribe to our at Eureka channel to learn more happy learning

19 Comments

  1. edureka! said:

    Got a question on the topic? Please share it in the comment section below and our experts will answer it for you. For Edureka IoT Course curriculum, Visit our Website: http://bit.ly/2Qlej4v

    June 28, 2019
    Reply
  2. Gokul Krish said:

    I can't connect raspberry pi with display using HDMI can u Please help me

    June 28, 2019
    Reply
  3. Arpit Verma said:

    I learned a lot of things from your videos
    Hats off to your efforts making these edu videos.keep posting such videos๐Ÿ˜Š๐Ÿ˜Š

    June 28, 2019
    Reply
  4. mychael mukesh said:

    Thank you for this excellent tutorial. Can you please make a video on face detecting using Rasberry pi and any camera module

    June 28, 2019
    Reply
  5. YASH PARIHAR said:

    nice man

    June 28, 2019
    Reply
  6. Pdp said:

    I liked the video "as well" ๐Ÿ˜๐Ÿ˜

    June 28, 2019
    Reply
  7. Partha Jana said:

    Please post some video on home automation using arduino uno and iot

    June 28, 2019
    Reply
  8. shanu2x said:

    Absolutely fantastic tutorial, you really hit all the points that are vital to explaining why Raspberry Pi is limitless. Thank you for this video. ^_^

    June 28, 2019
    Reply
  9. H K said:

    Nice video bro

    June 28, 2019
    Reply
  10. niranjana umashankar said:

    Pls upload videos on aurdino

    June 28, 2019
    Reply
  11. Rashed Shawl said:

    Good Explaination

    June 28, 2019
    Reply
  12. Devprasad Sahoo said:

    Plss post some videos on Arduino…..and Kudos to the tutorials……

    June 28, 2019
    Reply
  13. Rushikesh Zanwar said:

    I like edureka. This is one stop shop for all tutorials please upload more tutorials on raspberry like how to program it to do complicated tasks and many more

    June 28, 2019
    Reply
  14. Dalli sai suresh said:

    It was great tutorial on raspberry pi . Please do some tutorials on Arduino.

    June 28, 2019
    Reply
  15. Susanth T P said:

    Do you have certification course on IOT

    June 28, 2019
    Reply
  16. Mohammed Innat said:

    When your streaming video pause , it pauses me too ๐Ÿ˜› However , nicely explained. Please , do some tutorial on using FFMPEG and REST PI on Raspberry PI.

    June 28, 2019
    Reply
  17. okechukwu anya said:

    like it!

    June 28, 2019
    Reply
  18. Vaibhav Pokale said:

    Gr8…. Please post more videos of IOT sessions

    June 28, 2019
    Reply
  19. Ashish bindra said:

    Wooow

    June 28, 2019
    Reply

Leave a Reply

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