Camera Module - Raspberry Pi and Python tutorials p.5
Skills:
Tool Use & Function Calling70%
Key Takeaways
This video tutorial covers the basics of using the Raspberry Pi Camera module with Python, including installation, configuration, and basic usage such as capturing images and recording video.
Full Transcript
What is going on everybody and welcome to another Raspberry Pi tutorial video. In this video, what we're going to be talking about is the Raspberry Pi camera module. Now, the camera module is probably the easiest sensor to use with the Raspberry Pi since it's just super simple plug-andplay. So, that's the first one that we're going to cover and then the next subsequent sensors are actually going to be connected to the GPI opens. Now, on the Raspberry Pi, we actually have a very specific port for the Raspberry Pi camera module. Now, that port is right here. Now, a lot of times, mine's actually up already, but a lot of times it'll be down. So, to open the port, there's these two tabs on the side. You can grab those and pull up, and that opens up the port. Now, we'll go ahead and connect the Raspberry Pi. And generally, like the back side of this pin of or of the ribbons, rather um is this like silver pins. And then on the other side, you've got the covered blue. That blue should be facing towards the the uh Ethernet port. So go ahead and take the ribbon and insert it in. It should just slide in like like this into the port. And then when it's in there, you kind of have to hold it with one hand and then use your other hand to push down the pins. Um it's kind of hard to see with this in the way, but anyways, you you hold it with this hand, you push down, and then you use your other two fingers to push down on the pins. Once that's done, that's really all there is to it. Now your camera is um connected and we're ready to actually plug in the Raspberry Pi and see the result. Okay, so now the Raspberry Pi is plugged in. What I'm going to go ahead and do is uh change directory into uh desktop and I'm going to create a new file here. You can do this via the remote desktop, but the main issue here is that um it's going to want to display on the the root act the actual Pi like when we display video. Now, you could process video and all that, but if you actually want to display video, you're not going to see the video via remote desktop, and you're certainly not going to see it on a non-geue shell. So, I'll just show the monitor when it when it comes up. But this if you want to see the actual uh preview of the video, it's got to be on the native screen. At least as far as I know. Uh so what we're going to go ahead and do now is come over um you know go into the desktop and first we have to actually enable the camera. So pseudo raspy-config and this is going to require a reboot actually. But come down to interfacing options, hit enter there. Uh, camera is the first option. And go ahead and hit yes to enable the camera. And you're done. And then hit finish. And mine's already been enabled, so I don't need to reboot. But chances are you're going to need to reboot. So go ahead and reboot. And then once you do, log back in. And then once you log back in, don't forget to cd desktop. Des desk. Well, I'm already there, but anyway, desktop. Okay. So now what we're going to do is we're going to create a new file. I'm going to call this um nano camera example.py. And in here, we're going to do some imports. Uh we're going to import pi camera. Pi camera. And then we're going to import time. And just to be 100% certain, I'm actually going to control x. Yes. To save. Yes. Um it should be pseudoapp get install python-py camera possibly. Let's see if that works. Okay. Yeah. Python-py camera. Alternatively, it could be also Python 3-pi camera, but we have both. Anyway, getting back into camera example.py na. Let's see. I'm getting lost. Nano camera. Yes. Okay. Now, we're going to define the camera object, which will just be pi camera.py camera. And then, uh, we can do camera. First, let's take a quick picture. So, camera.capture and then let's just save it as example.jpeg. Um, and let's go ahead and in fact I kind of want to go into let me pause this for a moment. I guess we'll go we actually will log into the remote desktop because I'm the picture we should be able to see. It's just going to be the video feed that's not going to work for us remotely. Um, I'll hit okay. And I'll just kind of have both of these up. We I could go to that computer over there. I just there's no way real good way for me to record that screen. So, I just don't like to. Anyway, I'll move this over. And let's actually just run this real quick. So, yes. Uh, Python camera example.py. And we should now have, yes, example.jpeg. We'll come up to the remote desktop. We can click on it. And there I am giving you this lovely lovely tutorial. Okay. So now let's go ahead and close that. And this time we can see that well the the the image was actually flipped upside down. So we can go back camera example. And what we can say instead is um we'll just do it above here. Camera.vlip equals true. So that will actually flip the camera vertically. You can also do a horizontal flip if you wanted. So yes, and let's run that again. And then come back to the remote desktop. Click on the image. And there we go. We're right side up. Fantastic. All right. Next, what we're going to do is um we can uh do a record. So, we could go Python or nano camera example. We don't need a capture again. Uh, this time let's do a camera dot start recording. And then we'll just save this as example vid.h264. Uh, we'll do a time. Five. And then let's do camera.stop recording. And that will um save the file. So, we'll get a 5-second video. So, we'll go ahead and um start that recording process. And then when we're done, uh we're going to use the OMX player. You should already have this in your um on your Pi. So, let's come over here. Uh let me open the terminal. And we're not in desktop. So, let's change directory to the desktop. And now what we can do is just call OMX player. OMX player. Uh, what did we call that? Video. I already forgot. I think it's example vid or something. Example vid. Yep, there it is. Hit enter. And it's playing I think on the other I didn't see it pop up here. Yeah. So, you should see it on your own. But um let me just full screen this and then we can uh play that one more time. And there we go. So there's the the video that we recorded. So for whatever reason it just won't show on the remote desktop. Okay. So um that's just some quick basics. You can also get um just a camera feed like uh the actual um preview. So for example, we could just run Python real quick. Um from PI camera, we're going to import pi camera. Um we're going to say camera equals pi camera and then camera start preview. This may or may not work. My camera is still showing that it's on for some reason. We'll see. Nope, it looks like it's gone. We do need the vertical flip, but uh regardless, it's actually still [Music] Hello. Anyway, okay, that should be enough for the camera module. You can do all kinds of stuff with it. You can do [Music] um Let me pull up the Let's see uh the OpenCV. Oh, no, the robotics one. Yes, yes, yes, yes. So, what you can do with this, all kinds of stuff, of course, but you can program a robot to shoot um missiles at you when it sees your face. So, that's always fun. Anyway, um hopefully get your camera working. If you have any problems, questions, comments, concerns, whatever, feel free to leave them below. Otherwise, in the next few tutorials, what we're going to be doing is talking about the actual GPIO pins on the Raspberry Pi and doing some pretty cool stuff with that. So that's what you guys have to look forward to. I will see you in another tutorial.
Original Description
Welcome to part 5 of the Raspberry Pi tutorial series, in this tutorial and the next few, we'll be introducing some of the sensors that are available. Probably the most popular sensor is the Raspberry Pi Camera module, which is what we'll be covering here.
Text-based version of this series: https://pythonprogramming.net/introduction-raspberry-pi-tutorials/
https://twitter.com/sentdex
https://www.facebook.com/pythonprogramming.net/
https://plus.google.com/+sentdex
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
More on: Tool Use & Function Calling
View skill →
🎓
Tutor Explanation
DeepCamp AI