Image Recognition and Python Part 2
Key Takeaways
Develops the image recognition basics series with Python
Full Transcript
hello and welcome to part two of our image recognition and image manipulation tutorial Series where we left off we were basically just downloading everything that we needed and now we're ready to start programming if you don't know how to get to this window uh so like if this is really your introduction to even python uh once you've downloaded and installed python if you go to your start bar and search for I d as in dog l e uh you should find idle and then in parentheses python GUI or guey click on that and that should bring up this window here and you could program in here but I I don't prefer it so you can go file new window and that'll bring up an empty window and then you can subsequently close out of this window then you should have something called like Untitled right so it's like an Untitled text document you can type stuff in here and it's cool subsequently the next thing you'll want to do is you want to file save as you'll save it in the same directory I'm going to close out of this cuz I don't need this but you'll save it in the same directory as that image folder so if I was to save this one which is what we'll be coding in um it brings up in here and so I've got the image file folder here that you could extract from tutorial images so if you double click to this what's in here is that numbers file and all that I'll go back make sure you save uh this video like the program that we're going to be typing in save that file right here in the same directory as IM images and when you do save the file make sure at the end of the file you put py otherwise it just saves it as a regular file and it's kind of annoying so anyway once you've done that you should be here at this empty screen and you're ready to go so the first thing that we need to do is bring in all the other uh Imports that we are going to be working with so basically the stuff that we downloaded if you didn't already have it so like I said in the previous video if you're operating on a 32bit version of python then you will you will do this you will import Capital IM M AG G now I'm on 64bit and I'm not using pil so we're just going to leave that out but it I'll just comment this if you are on 32bit OS then you will do that otherwise if you're going to be working with us with the same things that we've used you're going to do from pis which actually is from pillow not python Imaging Library import capital i m a g e so besides this change right here in in the first line of our script nothing else will be different from what we code so uh no matter what you're using you should be able to follow along no problem so next thing we want is to import numpy so we're going to do import numpy as NP now that way when we call numpy we can just type NP instead of full numpy cuz we're lazy now let's talk about how to work with an image so if we bring up um in our directory you can double click on images and that should look like this so what I'd like to do is let's just open up a simple very simple image and we'll open up this dot image so let me just bring that up it is you probably can't even see it in the video but it's a really I'll just zoom in it's just a dot in the corner all right so uh that's the image that we're going to look at real quick just for basic uh reasons so we'll say I for shorthand image equals capital i m a. openen and then you're going to want to specify the path to that image so if you put this uh script in the same directory as that images folder all you'll have to do is images.png but if you put it somewhere else you'll need to give the full path um or you could do like some tricks with this stuff but uh if you if you're not comfortable you should just make sure the script is in the same directory and if it says it can't find it then either you've made a typo or just try to give the exact full file path next uh we're going to say I a and what i a r is standing for is just we're just making it up it's a variable but I a in my mind is image right for the I and then AR will be the array and then that's going to equal np. asarray and then what do we want to convert to an array or an NPI array rather we're going to use I right so what this is going to do is going to spit out an array that corresponds to our image and the image array is going to come out as a threedimensional threedimensional array so this means there's an array within an array within an array or if you use a list it would be a list within a list within a list depending on how we're reading it in Python that's what it's going to it's going to be different things right and that entire list you know so the outside Dimension is the whole image the second dimension in is going to correspond to each row and the third dimension in corresponds to each pixel in that row and the items within that list of the pixel is your red green blue or RGB and then you've got Alpha and that's for each pixel so let's go ahead and and look at an example since that might sound really confusing so we're going to print out I and just print it uh to the console now you'll just need to make sure you go file save or you can do contrl s and then to run the script you either hit uh run and then run module or you can hit F5 so that should bring it up and it will print out this array here so as we can see uh we've got let me see I I can't really scroll this out but uh on yours you should see you know like a box of numbers right and then another box and another box and all the boxes pretty much should be 255 within them except for the first one it's got a z0 0 and a 255 so this entire uh array right right that is let me just fit everything into this window that is the image right now each one of these arrays here actually let me get it right like this uh each one of these and actually it's more like this anyway uh each one of these right uh is the row within the image and our image is an 8 by8 so let me go ahead and bring that image back up again let's edit it so it comes up in paint and I'll just drag it over and zoom in so as you can see you know there's 1 2 3 4 5 6 7 8 by 1 2 3 4 5 6 7 8 you'll have to take my word for it or you can look at it but uh anyway yeah if we went to resize right 8 by8 anyway so that's our image and so we have eight of these rows 1 2 3 4 five 6 7 and eight and then also within that row we've got our pixels and like this is a pixel in that row this is another pixel and we since it's an 8 by8 we're going to have eight pixels right so you can almost see is like the pixel is like part of the column and then this entire list of pixels is a row so anyway that's just some Basics we'll get into more detail in the next video if you're having any trouble up to this point feel free to use the comment box uh most of the comments go to my email and I do respond to the comments so if you're having any problems just feel free to uh post your question or your problem and I'll do my best to help you out anyway as as always thanks for watching thanks for the support and subscriptions and until next time
Original Description
This is the second video to my image recognition basics series. Image recognition can be used for all sorts of things like facial recognition, identifying what is in pictures, character recognition, and more.
Sentdex.com
Facebook.com/sentdex
Twitter.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
Related AI Lessons
⚡
⚡
⚡
⚡
When the Camera Becomes an Exam Proctor: Building an AI-Powered Exam Monitoring System with…
Medium · Python
When the Camera Becomes an Exam Proctor: Building an AI-Powered Exam Monitoring System with…
Medium · Deep Learning
When the Camera Becomes an Exam Proctor: Building an AI-Powered Exam Monitoring System with…
Medium · Cybersecurity
Your Face Is About to Become Your Phone Number
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI