Edge Detection and Gradients - OpenCV with Python for Image and Video Analysis 10
Skills:
CV Basics90%
Key Takeaways
Implements edge detection and gradients using OpenCV with Python for image and video analysis
Full Transcript
what's going on everybody welcome to another open CV with Python tutorial in this tutorial we're going to be talking about gradients as well as Edge detection so uh let's go ahead and get started we are already have um basically some stuff going on in in here that we really don't actually need anymore so I'm going to go ahead and remove all of this basically to here so if you're just now following along uh go ahead and you can go to you can either copy and paste this code it's really not that much code in all honesty uh or you can um and in fact we don't even need the HSV or you can go to python program.net go to this tutorial and just copy and paste to start off now uh so we've got uh the nothingness that we don't care about in our frame and now we're going to um let's go ahead and first we'll just do a the lap so lap equals CV2 should have kept some of that image show anyway [Music] lap it's hard to spell uh we're going to apply that to the frame and use CV 2. cvore 64f that is just data type might not even have to specify that I want to be surprised if that's default and let's go ahead and CV2 mow uh and then we'll call this def I don't know original and then comma frame and then we'll go CB2 mow and then we'll do lapal and lap cool that should be good so we'll run that and there we have our lapal uh gradient that is applied here um um now uh basically this is a gradient that would go kind of both ways now a lot of times You' got an X gradient or like a y gradient basically so we can go ahead and add those as well so let me go ahead Let's uh it looks like like a really bad TV maybe you guys don't remember you know anybody remember when you had like a satellite and it would uh like the snowy channels but you could just like barely make out some people sometimes if your signal was like okay if anyway uh so we got lapal and then we're going to do soble X backing Monday we had snowy TVs anyway uh CV2 do soble and then we're going to apply that soble uh to the frame and then we're going to say CV2 do basically this exact same data type and then one Z Z and then K size will be five that's your kernel size and let's just copy this paste so this is basically X Y so then we flip these around 01 so Y and this will give you basically your directional sort of intensity with gradients so we'll take this paste paste soble x x x x y and Y so save and run those and there you have your gradients okay so one is a vertical and one is more horizontal gradient um as you can probably see or then one is just in general so with lapal actually really all these gradients especially if you convert it to grayscale first and then applied these gradients you you can kind of start to dve some information so these gradients can be used for directional intensity in some cases but there I kind of think there's better options out there uh but you canuse them and especially like this lapal one uh you can see edges really well and so you can start to Define Edge detectors based on these but you don't need to because there are already Edge detectors Edge detectors built in so let's close that out open or close that and go back to our script and what we're interested in now is an edge detector now there are multiple Edge detectors out there but we're going to use the canny Edge detector so we're going to come down here and we're going to say the edges equals CV2 do cany we apply it to the frame and we'll use a 100 by 200 here uh and then we will show edges edges and here is basically just modified one of them but this this gives you like a bunch of edges um [Music] based on a certain region basically so like what if we um what if we change this to uh let's do like 50 and 50 okay so you can see based on a much smaller uh size here we've got a lot of noise happening so we don't want that much noise so let's try maybe maybe uh let's try 100 by 100 but maybe you want that much noise you know uh like for example if I hold up my arm you can see a lot of my hair shows up uh on the edge detector um and a lot of my head hair does and my facial hair shows up um but if you want less edges and like the more important kind of edges you can do 200 by 200 or even um like 100 by 200 let me show that okay but we're still losing some of that screen up top or the um picture up there it's actually I guess we kind of this is like the reflection of my light I suppose interesting anyway um and another thing to note with uh The Edge detection as you can see that there's a dog bed in the background and it's got kind of like a a shadow coming off of it and it's it acts like that's an edge not only is it an edge but because that shadow continues it's almost like it's overlapping the dog bed that's actually I mean the shadow is overlapping it but it's obviously nothing is actually overlapping that dog bed so that's kind of interesting surprised I can't get like a decent like it's either a lot of noise or we lose some stuff whatever anyway probably 100 by 200 is the best one anyway I think that's pretty cool like that little Edge detection uh for detecting edges on stuff is actually I think that's pretty cool um anyway uh that's it for image gradients and all that in the next tutorial we're going to be talking about template matching basically if you have an image of something thing you can match it as long as you have a relatively almost identical match it's actually really quick really easy in the code to match it in a an amongst a much larger image so that's what we're going to be talking about in the next tutorial if you have questions comments concerns whatever about this tutorial leave them below otherwise as always thanks for watching thanks for all the support subscriptions and until next time
Original Description
Welcome to another OpenCV with Python tutorial. In this tutorial, we'll be covering image gradients and edge detection. Image gradients can be used to measure directional intensity, and edge detection does exactly what it sounds like: it finds edges! Bet you didn't see that one coming.
Text-based version and sample code: https://pythonprogramming.net/canny-edge-detection-gradients-python-opencv-tutorial/?completed=/morphological-transformation-python-opencv-tutorial/
https://pythonprogramming.net
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: CV Basics
View skill →Related Reads
📰
📰
📰
📰
10 AI Image Prompts Every Content Creator Can Use for Urdu/English Quotes
Medium · Machine Learning
The Best AI Course Generator in 2026? I Tested 7 to Find Out.
Dev.to AI
Automate Spotify and YouTube Playlists - Chapter 2: Setting Up Spotify
Dev.to · Tawanda Nyahuye
Use a model route manifest before Dify, Cursor, and Node.js share Vector Engine
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI