OpenCV Python Tutorial #7 - Template Matching (Object Detection)

  Рет қаралды 92,668

Tech With Tim

Tech With Tim

Күн бұрын

Welcome to another OpenCV tutorial! We'll be talking about template matching (object detection). In this video, we'll use an image of a soccer practice and use OpenCV to detect the soccer ball and find it's exact location. For example, the image of the ball will be our template, and we'll use OpenCV to match it.
💻 AlgoExpert is the coding interview prep platform that I used to ace my Microsoft and Shopify interviews. Check it out and get a discount on the platform using the code "techwithtim" algoexpert.io/techwithtim
📄 Relevant Documentation: opencv-python-tutroals.readth...
📝 Code For This Series: github.com/techwithtim/OpenCV...
🔍 Playlist: • OpenCV Python Tutorials
⭐️ Timestamps ⭐️
00:00 | Setup & Images
02:35 | Loading Template & Base Images
04:55 | Template Matching Methods
07:00 | Theory Behind Template Matching
14:10 | Displaying Matches
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
💰 Courses & Merch 💰
💻 The Fundamentals of Programming w/ Python: tech-with-tim.teachable.com/p...
👕 Merchandise: teespring.com/stores/tech-wit...
🔗 Social Medias 🔗
📸 Instagram: / tech_with_tim
📱 Twitter: / techwithtimm
⭐ Discord: / discord
📝 LinkedIn: / tim-ruscica-82631b179
🌎 Website: techwithtim.net
📂 GitHub: github.com/techwithtim
🔊 Podcast: anchor.fm/tech-with-tim
🎬 My KZbin Gear 🎬
🎥 Main Camera (EOS Canon 90D): amzn.to/3cY23y9
🎥 Secondary Camera (Panasonic Lumix G7): amzn.to/3fl2iEV
📹 Main Lens (EFS 24mm f/2.8): amzn.to/2Yuol5r
🕹 Tripod: amzn.to/3hpSprv
🎤 Main Microphone (Rode NT1): amzn.to/2HrZxXc
🎤 Secondary Microphone (Synco Wireless Lapel System): amzn.to/3e07Swl
🎤 Third Microphone (Rode NTG4+): amzn.to/3oi0v8Z
☀️ Lights: amzn.to/2ApeiXr
⌨ Keyboard (Daskeyboard 4Q): amzn.to/2YpN5vm
🖱 Mouse (Logitech MX Master): amzn.to/2HsmRDN
📸 Webcam (Logitech 1080p Pro): amzn.to/2B2IXcQ
📢 Speaker (Beats Pill): amzn.to/2XYc5ef
🎧 Headphones (Bose Quiet Comfort 35): amzn.to/2MWbl3e
🌞 Lamp (BenQ E-reading Lamp): amzn.to/3e0UCr8
🌞 Secondary Lamp (BenQ Screenbar Plus): amzn.to/30Dtafi
💻 Monitor (BenQ EX2780Q): amzn.to/2HsmUPZ
💻 Monitor (LG Ultrawide 34WN750): amzn.to/3dSD7tS
🎙 Mic Boom Arm (Rode PSA 1): amzn.to/30EZw9m
🎚 Audio Interface (Focusrite Scarlet 4i4): amzn.to/2TjXsih
💸 Donations 💸
💵 One-Time Donations: www.paypal.com/donate?hosted_...
💰 Patreon: / techwithtim
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
⭐️ Tags ⭐️
- Object detection in OpenCV
- Template matching OpenCV
- Python
- Computer vision
- Cameras and video capture
⭐️ Hashtags ⭐️
#OpenCV #Python #TemplateMatching

Пікірлер: 93
@ananthramvijayaraj4554
@ananthramvijayaraj4554 3 жыл бұрын
Tim you don't need to apologize for the lengthy explanation, that's the whole reason why we are here.
@CommonKnowledge42
@CommonKnowledge42 3 жыл бұрын
This statement right here! I wish I could like your comment at least 19 times.
@bluidguy4007
@bluidguy4007 3 жыл бұрын
I wholeheartedly agree, there are a few people I watch their videos like this for, and that's why, you do a great job at explaining things, keep up the good work!
@ACodingWoof
@ACodingWoof 2 жыл бұрын
Yup!
@joseph13313
@joseph13313 2 жыл бұрын
You're so right. Sometimes im looking to a tutorial and i need to understand this code's logic to learn perfectly. Tim is doing it so good!
@darwinkusuma6757
@darwinkusuma6757 2 жыл бұрын
i agree, don't need to be sorry for the long explanation, i really thankful you explain it on detail
@CryptoDabber710
@CryptoDabber710 2 жыл бұрын
Tim you do an amazing job no need to apologize for the lengthy explanations they are actually extremely useful. I'll usually watch your videos multiple times just so I know I'm getting the information.
@Atharva_Vashist
@Atharva_Vashist 3 жыл бұрын
I was interested in coding and chose python as my language to start, and you helped me to clear my basics, and explore many modules like opencv , kivy etc. You explain very well. Thank you for your videos. You are the best youtuber teaching python. Keep it up!!!!!!!
@DL-yu8jg
@DL-yu8jg Жыл бұрын
Gotta say, this is one of the most well explained Python-related lectures I've ever witnessed. Thank you so much for the video. Really helped me A LOT.
@Traxirage
@Traxirage 3 жыл бұрын
Great tutorial! For future reference, if you want to select a segment of two lines, you can hold Shift + Alt and drag the mouse. This way it won't select all the way to the end of row, but only to the column you move your cursor to.
@raviolismudge
@raviolismudge Жыл бұрын
FOR THE LOVE OF GOD, I SPENT MY WHOLE DAY ON THIS T-T Thank you so much. I am crying tears of joy. My professor refuse to help us with anything that have to do with programming, he only talk about the math behind visualization. Thank you so much.
@73Ferret
@73Ferret 2 жыл бұрын
Thanks for this series Tim. You have a very nice style of presenting and explaining how the code works.
@jaakkaan4784
@jaakkaan4784 Жыл бұрын
AMAZING VIDEO THANK YOU for the thoroughness. Absolutely covered all areas where confusion or curiosity could come up!
@nicolasa.bermellferrer8025
@nicolasa.bermellferrer8025 2 жыл бұрын
Your explanation was actually pretty good. Thank you!!
@mehmetsezgin2308
@mehmetsezgin2308 Жыл бұрын
Tim that is pretty straightforward tutorial. Thanks !
@alexandrevalente9994
@alexandrevalente9994 2 жыл бұрын
Great example to illustrate the use of the convolution here.
@phamminhhung3219
@phamminhhung3219 3 жыл бұрын
Actually your long explanation is useful for us, it illuminates us how things work and you should keep doing that, or maybe you can implement some drawings
@sunwukong6268
@sunwukong6268 3 жыл бұрын
Your "lengthy" explanation was great. Not as long as you might think and comprehensable.
@tsraikage
@tsraikage 2 жыл бұрын
how sad I've never found your channel before. i would be step or two higher than i am right now. your explanation methods are outstanding. great job
@endab5517
@endab5517 2 жыл бұрын
You are gifted. Thank you for the content.
@ajarivas72
@ajarivas72 Жыл бұрын
He rocks
@natomxavi
@natomxavi Ай бұрын
Grrat explanation bro, thank you so much
@hackercop
@hackercop 3 жыл бұрын
Glitch at 12:20 that he forgot to edit out lol. Great video, am trying to learn object recognition.
@TeckWill
@TeckWill 10 ай бұрын
Great job with your tutorial videos Tim! I understand that with the methods you shown we can find the exact same pixels pattern in the image. Now, I wonder, for example, how could we find all the shoes on the image from the template image without them being perfectly identical. I suppose it will be necessary to go towards artificial intelligence / deep learning? I'd like to know what you would do and see a tutorial video on it.
@RandomGuy-df1oy
@RandomGuy-df1oy 2 жыл бұрын
At the end of the video, you don't need to resize the image at every step. Just resize where you are showing the image at line 23 as cv2.imshow("Match", cv2.resize(img2, (0,0), fx=0.8, fy=0.8))
@princemajestal8100
@princemajestal8100 2 жыл бұрын
Hi! I have two questions. First, would it be possible to do this with a webcam feed instead of an image? And second, supposing I don't want to draw a rectangle but wanted to execute some code if there is a match, what condition would I use for my if statement? Thanks a lot, great video!
@zack8247
@zack8247 2 жыл бұрын
Great video!
@RasmusE
@RasmusE 3 жыл бұрын
Hi Tim, great videos about CV2. If I want to create template matching in CV2 but the template and the image are of different sizes. How do I account for that? Once in a while I get a secret message consistent of characters in different alphabets and I want a script where I can select one character and have it look through a bunch of images with all the alphabets I know and make a comparison. It could be something like the Arcadian Alphabet or Antiker code I have to match against. Any help in the right direction would be appreciated.
@peschebichsu
@peschebichsu 2 жыл бұрын
Does it also work to match similar images too (like I think it was pyautogui, where you can give it a required confidence)?
@w-e-7963
@w-e-7963 3 жыл бұрын
Great video - thanks. You might want to use the word 'assign' instead of 'is equal to' (let the math teachers have the latter one).
@boktorinator693
@boktorinator693 Жыл бұрын
Thank you :)
@vingo1998
@vingo1998 2 жыл бұрын
Great video! You are so cool
@JainmiahSk
@JainmiahSk 3 жыл бұрын
Please do series on product recommendation system
@smoothrain
@smoothrain 3 жыл бұрын
Love you tim
@addohm
@addohm 2 жыл бұрын
Tim, what about margin of error? What if there is a different pattern ball?
@Yurgen_S
@Yurgen_S 2 жыл бұрын
Tim, Id like if you could give me some tips, I'm facing a similar problem to this pattern matching thing: I have patterns, they are very simple in shape and color (triangles, squares and such), but i'm *trying to detect them in video*. And in the live feed, *unlike this one-to-one matching*, the patterns could appear bigger, smaller, maybe slightly off colored. I get that i'll be processing multiple frames as individual images, and I know there are some techniques to help me with "video variables" that may distort patterns, like applying histogram exposure equalization, noise filters, etc. What should i be looking around, in OpenCV? I'd have to classify what symbol it is, but maybe matching for each possible symbol might do it for me. What other more robust, AI-ish techniques could i apply to have more "safety" against such variables?
@jeepjr
@jeepjr 2 жыл бұрын
Teacher, first congratulations for the channel. I need your help, I have a simple image with a range of 5 placements where the quantity is identified, how do I identify the biggest color type red and say where the X,Y is, and if you can help me, and only for create an alert.
@cleancode9601
@cleancode9601 3 жыл бұрын
Sir please upload some video on curve analysis... please sir
@olekristianmller-hansen4220
@olekristianmller-hansen4220 3 ай бұрын
Hi! Can I use multiple templates of soccer balls and add up the results to better detect soccer balls?
@alexkotov2983
@alexkotov2983 3 жыл бұрын
Is there a way to increase accuracy of matching? I'm trying to detect objects on my screen but it doesnt work.
@ricard458
@ricard458 3 жыл бұрын
In the following command I multiplied by 4 to get a bigger rectange. How can I save only the image of this rectangle ? cv.rectangle(img_rgb, pt, (pt[0] +w*4, pt[1] +h*4), (0,0,255), 2)
@dreamwork69
@dreamwork69 Жыл бұрын
My question is so everytime we have to run 6 different windows like that or we just pick one method that work best? Thank u
@jollokim1948
@jollokim1948 3 жыл бұрын
How come i was not notified about this video. Damm you YT 🤦‍♂️
@spook2387
@spook2387 3 жыл бұрын
He accidentally released it instead of ep. 6 and then set it to private so you've received the notification for that time. At least that's what I understood that happened.
@py_tok5589
@py_tok5589 3 жыл бұрын
lovely quite cool TIM, THE MASTER. can you detect /extract dimensions? can you extract the diameter of the ball roughly? may be you do a tutorial extracting dimensions from images. Thank you Tim
@chrismckinley3110
@chrismckinley3110 3 жыл бұрын
Wouldn't the rough diameter of the ball be the width of the square cv2 draws around it?
@alessiopierdominici4240
@alessiopierdominici4240 3 жыл бұрын
Which chair are you using?
@aimanyounis8387
@aimanyounis8387 2 жыл бұрын
template mathcing is not convolution it's correlation, which means that you don't flip the kernel before you pass it on the whole image : another defintion of correlation is convolution withour flipping.
@user-pn8rh7fb4q
@user-pn8rh7fb4q Жыл бұрын
nice
@alexmboutchouang8281
@alexmboutchouang8281 3 жыл бұрын
hallo Tim i did not get the tutorial 5 i don't know why is it normal or did i missed something
@vsdsas
@vsdsas 9 ай бұрын
result = cv2.matchTemplate(img2, template, method) cv2.error: OpenCV(4.8.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\templmatch.cpp:1175: error: (-215:Assertion failed) _img.size().height
@bharathc7033
@bharathc7033 5 ай бұрын
i will run in open cv template matching and my rectangle line shoe multiple line why?
@ShubhamTure
@ShubhamTure 3 жыл бұрын
image assertion failed (-215) . Even after image is being loaded properly. Any help?
@shreyasvedpathak5579
@shreyasvedpathak5579 3 жыл бұрын
I tried this tutorial on another image which is from another sport involving a ball i.e. cricket, and coincidently, the third model plotted a bounding box on the player's chest. Is this the model's issue or are we misinterpreting the output for that model?
@ajarivas72
@ajarivas72 Жыл бұрын
Perhaps you need a neural network and trained with the desired results
@nilaier1430
@nilaier1430 2 жыл бұрын
Hey, btw, how can you detect multiple different templates in the image? I'm trying to find an answer to this tricky question, but can't find it anywhere.
@ajarivas72
@ajarivas72 Жыл бұрын
Why don’t you run the code several times ? Or loop it ?
@pranaygundu
@pranaygundu 3 жыл бұрын
hey "tech with tim youtube ":) , I just started open cv course and I am really enjoying it :). but should I need to master the math behind openCV functions ???? to be a good programmer .........whatever :) ...........
@abdullahahmed7781
@abdullahahmed7781 3 жыл бұрын
if you just want to *use* openCV then you dont really need to understand the math. But yes good programmers are also good mathematicians, understanding maths is very important in CS.
@pranaygundu
@pranaygundu 3 жыл бұрын
@@abdullahahmed7781 thank you so much😭😎
@WakilSahak
@WakilSahak 3 жыл бұрын
❤️
@justwatchv
@justwatchv 3 жыл бұрын
❤️❤️❤️❤️❤️
@mohamaderfanmirkhani6202
@mohamaderfanmirkhani6202 2 жыл бұрын
how can do Template Matching on video?
@kewalshah6448
@kewalshah6448 2 жыл бұрын
Can someone tell me the name of software he's using for this code I am using PyCharm but it is giving me some difficulties
@ther3negade273
@ther3negade273 2 жыл бұрын
sublime text editor, but sublime by default does not have a compiler so you can use the command prompt to run the code
@kewalshah6448
@kewalshah6448 2 жыл бұрын
@@ther3negade273 thanks man 👍
@domillima
@domillima 3 ай бұрын
Everything is clear other than the explanation of using TM_SQDIFF and TM_SQDIFFNORMED. What is this line doing?
@VShopov
@VShopov 3 ай бұрын
thats the image recognition method that is being used
@vrtheking
@vrtheking 3 жыл бұрын
You streamed Chess in Discord just now...
@komalgupta2226
@komalgupta2226 3 жыл бұрын
You were literally fast posting videos lol
@VictorPerez-od7zh
@VictorPerez-od7zh 3 жыл бұрын
Weird I didn't see tutorial #7 2 days ago or yesterday
@ananthramvijayaraj4554
@ananthramvijayaraj4554 3 жыл бұрын
Me too
@mickon7404
@mickon7404 3 жыл бұрын
My opencv doesn't work :((
@jagermeister1888
@jagermeister1888 3 жыл бұрын
Hey, i'm looking for collaboration into any python projects (my skill is somewhere at intermediate level ), let me know if you need help or if u just want to share your code with someone :)
@ananthramvijayaraj4554
@ananthramvijayaraj4554 3 жыл бұрын
Why are there only 470 views on this video or is it that my phone is glitched out
@faneeshmunjal3308
@faneeshmunjal3308 3 жыл бұрын
First!!
@dangus5326
@dangus5326 2 жыл бұрын
DUDE Wut 1:00
@malhardharmadhikari5831
@malhardharmadhikari5831 3 жыл бұрын
Ig I will never be able to do big project
@nelsonchika
@nelsonchika 3 жыл бұрын
Second
@MegaLenrique
@MegaLenrique Жыл бұрын
muchas gracias por compartir, comprendo como funciona pero no me funciona jeje..... [WinError 2] El sistema no puede encontrar el archivo especificado [cmd: ['py', '-u', 'C:\\Users\\Luis\\Desktop\\AGROLUIS =)\\practica lll\\template matching\\OpenCV-Tutorials-main\\tutorial1.py']] [dir: C:\Users\Luis\Desktop\AGROLUIS =)\practica lll\template matching\OpenCV-Tutorials-main] [path: C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\Luis\miniconda3;C:\Users\Luis\miniconda3\Library\mingw-w64\bin;C:\Users\Luis\miniconda3\Library\usr\bin;C:\Users\Luis\miniconda3\Library\bin;C:\Users\Luis\miniconda3\Scripts;C:\miniconda;C:\miniconda\Library\mingw-w64\bin;C:\miniconda\Library\usr\bin;C:\miniconda\Library\bin;C:\miniconda\Scripts;C:\Users\Luis\AppData\Local\Microsoft\WindowsApps;C:\Users\Luis\AppData\Local\Programs\Microsoft VS Code\bin] [Finished]
@krishnamenon5566
@krishnamenon5566 3 жыл бұрын
First
@rayaanibrahim4808
@rayaanibrahim4808 3 жыл бұрын
4th
@saulaxo
@saulaxo 2 жыл бұрын
no fun playing "where's waldo" afther this
@infernozayed9559
@infernozayed9559 Жыл бұрын
It's not soccer, It's Football!!
@tcgvsocg1458
@tcgvsocg1458 3 жыл бұрын
Your really good your soft really bad
@Eswar.
@Eswar. 3 жыл бұрын
How to completely learn one language make a roadmap please And also smile in videos Dont be like a robot
@ananthramvijayaraj4554
@ananthramvijayaraj4554 3 жыл бұрын
True there isn’t much humour in the vids but the quality of the content is amazing
@Eswar.
@Eswar. 3 жыл бұрын
@@ananthramvijayaraj4554 yes i know
@shahriarhajiabbasi830
@shahriarhajiabbasi830 3 жыл бұрын
I HATE that shirt ....
@Dg2020
@Dg2020 2 жыл бұрын
who cares?
@sohannikumbh4802
@sohannikumbh4802 3 жыл бұрын
Second
OpenCV Python Tutorial #8 - Face and Eye Detection
16:08
Tech With Tim
Рет қаралды 82 М.
OpenCV Python Tutorial #6 - Corner Detection
21:43
Tech With Tim
Рет қаралды 66 М.
Useful Gadget for Smart Parents 🌟
00:29
Meow-some! Reacts
Рет қаралды 10 МЛН
路飞关冰箱怎么关不上#海贼王 #路飞
00:12
路飞与唐舞桐
Рет қаралды 4,9 МЛН
Normal vs Smokers !! 😱😱😱
00:12
Tibo InShape
Рет қаралды 35 МЛН
OpenCV Python Tutorial #5 - Colors and Color Detection
14:06
Tech With Tim
Рет қаралды 105 М.
OpenCV Object Detection in Games Python Tutorial #1
14:30
Learn Code By Gaming
Рет қаралды 252 М.
REAL TIME OBJECT MEASUREMENT | OpenCV Python (2020)
53:25
Murtaza's Workshop - Robotics and AI
Рет қаралды 235 М.
Template Matching by Correlation | Image Processing I
7:01
First Principles of Computer Vision
Рет қаралды 43 М.
Build an Object Detector for Any Game Using YOLO
22:40
Moises de Paulo Dias
Рет қаралды 29 М.
10 Python Comprehensions You SHOULD Be Using
21:35
Tech With Tim
Рет қаралды 90 М.
PLEASE Use These 5 Python Decorators
20:12
Tech With Tim
Рет қаралды 83 М.
Python Object Oriented Programming (OOP) - For Beginners
53:06
Tech With Tim
Рет қаралды 3,2 МЛН
Useful Gadget for Smart Parents 🌟
00:29
Meow-some! Reacts
Рет қаралды 10 МЛН