Image Recognition and Python Part 10

sentdex · Beginner ·👁️ Computer Vision ·12y ago
Skills: CV Basics80%

Key Takeaways

Builds a basic image recognition system using Python to compare pixel by pixel and determine pattern matches

Full Transcript

hello everybody Welcome to the 10th and uh probably final image recognition uh tutorial video where we left off uh we were just comparing pixel by pixel to decide which pattern matched best and then obviously comparing with examples from an OCR and where we left off that's what we had done and surprisingly made it with this awesome drawing of a number three by me now what I would like to do is not only uh depict it in number form but also show it visually and then why don't we actually try it against a few other examples uh cuz surely uh we won't be perfect every time and so that'll bring up the next question of threshold where would we decide we're good or whatnot so anyway I'll put this away for now and now what we want to do is graphically represent what we just did so what we're going to do is um just basically come down here and let's make some space and now what we're going to want to do is we're going to say cuz we want to graph everything in this counter and dealing with this counter is kind of finicky uh so what we're going to do I guess what we'll do here is we'll do graph x equals an empty array and graph y equals an empty array so obviously what's going to go in here is X variables and Y variables next thing we're going to want to say is for each thing in X um just so we know what we're doing let's go ahead and print each thing just to make sure we're on the right track and what we're going to want to do is cuz X is our counter and each thing in X should because it's it's a dictionary so X will correspond to the key so in a dictionary you have a key and a value and the key is the first element and the value is the second element so X should correspond to and X is going to be our x value so on the bottom of our graph we're going to have 0 1 2 3 4 5 6 7 8 9 and then on our y- axis will be how close or like the we'll make a bar chart basically of how similar and um it'll be awesome so anyways X will be that number so we're then we're going to say is graph x. append and we're just going to append each thing subsequently let's make sure we're still on the right track and we'll say print X each thing so this is the dictionary what is the value of the key of each thing from X and that should print out the numerical how many matches had it found so then we're going to say graph y. append and we just want to pend X each thing cool and now let's see that's good for now um so now what we're going to want to do is we're going to say figure equals plot. figure figure and then we're going to say ax 1 equal plot subplot to grid and then let's just make this grid really simple we're going to make it a 4x4 uh this one will start oops at 0 0 and it's going to row span one so only take up one row and then it's going to column span uh four columns and then let me just do a nice sexy copy paste working smart not hard change it to ax2 still a 4x4 this one starts at 1 one it's going to be span three rows and that's it quick glance make sure we did that nice copy and paste job good ax1 mow I easy easy yeah sounds familiar now we're going to do a bar bar chart now a bar chart uh is something we haven't covered and actually I don't even have a video tutorial on bar charts uh it's included in a lot of my videos but I don't have just a pure Bar chart video so if you haven't seen it it's pretty simple stuff ax2 doar and then in here you just X variables uh graph y variables and then we're going to do something cool and we're going to say Al line equals Center and the only time you would ever want to do this is when your X variables are like a name or a date or uh something like that I suppose I guess date doesn't sound too crazy of a thought but um you basically so like the ticks right the the actual labels are going to be in the center of the bar so it makes it just really easy to read Because natively The Tick will be on the left hand side of the bar and the bar will pour over the right hand side and it just kind of looks funky so now the next thing that we're going to want to do is we said that we wanted to set some sort of threshold and in my opinion if it's less than 400 pixels similar it's it's highly likely to be a mistake or a very poorly drawn image so I'm pretty surprised that our three even passed that test but it did so anyways 400 we'll just say that so that basically limits the y axis to a 400 next we're going to say uh let's do ax uh let's just show it let's just see where we are right now uh so then what number is this cool so save run well anyway printed out a whole bunch of stuff here we don't really need to be printing out any of this but you've seen all of this so uh zero there were 397 matches one there was 309 2 405 3 427 and so on and then you should have also got this so oops back over so this is the number that we drew looks familiar and then these are our matches but as you can see our X variables are kind of two is correctly marked this is obviously uh the three right but we're not we don't see it so let's go ahead and fix that real quick let me move this over and we'll just come right down here and we're going to say x location and then this will oops X location equals plot. Max n locator and we're just going to put a 12 in here so that basically says like how many are the maximum values that will show on the xaxis and since we want 0 through 9 to show go up and then we also um like since the bar we said bar align Center so that means if everything is filled a bar chart in the center would pour over the uh y AIS uh if if we did this so there must be a ne1 variable to the uh right and then there's also going to be a number 10 variable to the left therefore we must say 12 not 10 moving right along long uh we're going to say ax2 dox axis. setor major locator and we're going to set that to X look and that should solve all of our problems nice so now it looks very clear to us okay so what's this number most likely well it's most likely a three so now let's close this and let's run another number shall we so all delete grab that pencil let's make a seven that should oh that's a kind of a shitty seven but excuse my language save that and let's see if if we match uh the seven run that plot it up sure enough the only number that even was recognized was a seven nice job guys let's do another one trying to think of a better one like four is a good one that like alignment would matter and then also like um if you did any blurring so there's a four save that and let's run that and I wonder if that'll match sure enough that four match but okay I'm I was thinking that uh at least this part was was poorly drawn but let me just shift this over so I'll shift over to uh the right so this is an example where you would want to have some sort of centering function because this probably won't match a four I'm going to be really surprised if it does because we're like so stringent in our matching um there we go cool cool so it matched a sort of a three four is not even shown and it really matched a nine so one of our Miss uh one of our funky looking nines apparently that we took a few examples of so one you could have a centering function two you could in your examples you could take all of your examples and then uh write a function to shift them over a little bit shift them over a little bit maybe shift them up a little bit down a little bit and so on so you could do something like that as well um and that would solve the function or you could have a centering function and stuff like that but generally a blurring is better so what I mean by a blurring function is so instead of like zero like in theory this is zero zeros and ones right so 0 0 0 1 0 0 0 0 1 zero right and instead what it should be is 0 0 25 50 1 50 25 maybe 51 and so on and so the closer you get to the to the example the better but it's like if it missed it by one pixel you're not like totally off it's just maybe we're not so certain um so you can do something like that as well so I call that blurring I'm not sure if what people call that but um that seems to work really well as well especially when you have images on like say a capture even though my goal isn't to teach you guys to read captas but what they do is they make the letters like wavy on the capture and this solves that problem so anyways close out of this and let's make another one um and we'll just for now leave them centered even though I did did want to show you guys like what where this would go wrong um it seems as though maybe I've closed out of paint I can't find it on my bar I guess I'll bring it up again so another one that U I'm probably not going to even be able to draw is a two so let's try a two so two oh my God that's a horrible to I'm G to go ahead and redo that guys um okay that's good enough I guess so let's save that and we'll put it over here let's run this this and wow i' actually got that too cool so anyway you guys get the get the point you can play around with this all you want on your own and try out new numbers and stuff uh it actually works pretty well uh given the extreme Simplicity nine examples um and all of that it works pretty darn well and I wonder I wonder actually I'm curious we can do this test together let's see if this two matches we shifted it over one um oh matched even better this time around look at that awesome anyway so um so anyway what I'll leave you guys with is kind of what I was saying before and I actually I think what I'm trying to say is represented really well by this m plot lib image of the number two right that two is what you want to match against right so a perfect black versus kind of like a grayish and you want to superimpose that onto the image right this might be the image but then you want to later on blur that image a little bit so it looks like this and then store it and then you want to do a percent similarity between the numbers and that'll give you a little bit of help and you want to do all of that after thresholding right you want you don't want to be dealing with like blues and greens and stuff like threshold it first then blur it then uh compared to examples and that's actually got a really high accuracy rate it's it's um about like 88% or something I mean and and that's off something I made like in my free time so it's pretty accurate and as you can see this is actually already pretty accurate um and then as long as you like if you keep building up your examples and stuff um you'll only continue to to increase in accuracy so in that way it's kind of like a neural network and you could add in some some more uh machine learning principles uh to better this but really uh as you can see you just need examples and you can fairly well recognize characters so uh with that I'm going to conclude this series there might be future videos I add alongside here but that covers pretty much all the stuff I really wanted to cover in this series so hopefully you guys enjoyed um as always thanks for watching thanks for the support of the subscriptions and until next time

Original Description

This is the tenth 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 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
20 Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

Related AI Lessons

Cloud-Optimized OpenCV + A Special Surprise Announcement on OpenCV Live
Learn about Cloud-Optimized OpenCV for faster computer vision computations and a special announcement on OpenCV Live
OpenCV Blog
When the Camera Becomes an Exam Proctor: Building an AI-Powered Exam Monitoring System with…
Learn how to build an AI-powered exam monitoring system using Computer Vision and DeepFace to assist professional certification exams
Medium · Python
When the Camera Becomes an Exam Proctor: Building an AI-Powered Exam Monitoring System with…
Build an AI-powered exam monitoring system using Computer Vision and Deep Learning to enhance professional certification exams
Medium · Deep Learning
When the Camera Becomes an Exam Proctor: Building an AI-Powered Exam Monitoring System with…
Build an AI-powered exam monitoring system using Computer Vision and Deep Learning to enhance exam security and integrity
Medium · Cybersecurity
Up next
Marketing management for ugc net| Important topics of marketing management ugc net commerce dec 2023
Bhoomi Learning Centre~Dr. Muskan
Watch →