Thanks for making such valuable and informative video. Moreover, its fun when you choose his nose as template haha luv it. You deserve 100k++ subs and u will definitely get it soon!! Cheer u up mate! 😎😍👍
Hi, it's really great tutorial however - What if I want to match two images? For example I have one cola bottle and one perfume bottle. How do I match template, so it clicks the one that pop ups?
Hello! You need to create a for loop. Example: #Load templates: colaImg = cv2.imread("cola.png",0) perfumeImg = cv2.imread("perfume.png",0) templates_ls = [colaImg, perfumeImg] #Load screen vision pyautogui.screenshot("train.png") trainImg = cv2.imread("train.png",0) #run matchtemplate using for loop. for i in range(0,2): result = cv2.matchTemplate(templates_ls[i],cv2.TM_CCOEFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) if max_val >= 0.8: x, y = max_loc pyautogui.click(x, y) This solution will look for the colaImg and then for the perfumeImg in the same screenshot, if found, it will click on the topleft part of where such template is located.
What is your high score? Kind of funny that I wrote code to automate this game using open cv a few weeks ago and now I am targeted by RUclips to watch your video! "They" must be watching me! :-)
Nice video. But I want you to explain for me - if I use camera which include palm detection instead of mouse , I could make the game and it can match with between mole coordination and my hand coordination? I really wonder I could make it ..
@@justinjoseph6575 will you make Minesweeper bot for Android game 5×5 minesweeper game to display hidden mines or to make bot capable of playing itself, finding the golds without any mistake until game ends also include options like bot must ask user like game asks before playing with how many mines do you want to play? such as 2-25, 3 to 25, 24 mines and one left space where there will be only 1 gold out of 25 ... using x , y coordinates method with libraries openCV, pyautogui, etc and color detection for Android game
hello bro...great video...how do im pressing left button when image found in ROI and release the pressing button when image not found in ROI ...this code im modified from your coding if max_val >= 0.7: pyautogui.mouseDown() else break this code not release the press when image not found....need some advise thanks
I really can't get this to work on my iMac and I'm pretty sure it has to do with resolution of the screenshot compared to the resolution/pixels which are downsized on my retina display. Any clue how to handle? The screenshots / template is checked in completely wrong areas and when it actually finds something and clicks, it clicks on my X, Y coordinates. Or if you can tell me how to get the coordinates on mac just like paint does for you.
My very fist video is about a mouse tracking program, copy paste the source code and run it... Check the channel, it was My very first and worst vídeo lol
why do i get the message Traceback (most recent call last): File "C:\Users\BigFanOfNoobCodingAndGaming\PycharmProjects\pythonProject\Deel2.py", line 40, in if max_val >= 0.8: ^^^^^^^^^^^^^^ TypeError: '>=' not supported between instances of 'tuple' and 'float'
For some reason max_val is being returned as a tuple and python can't compare it to 0.8 because they are different data types. I would recommend for you to print max_val to the console before it enters the comparison and maybe you can pinpoint the error there. I would be happy to look at your code if you post it on stackoverflow. Cheers!
@@noobcodingandgaming7312 dammm i cant find a way to add multiple images .even if i add them , pyautogui doesnt click them .... idk where is the mistake
I think that error pops up when you have the image open using another program. Otherwise try to delete and redownload it. Edit: also if your computer is too fast, you might want to add some sleep time before opening that image using opencv
Very cool tutorial. I was able to get a score of 3860 using a similar approach. Thanks for sharing such a great learning project.
nice!
Thanks for making such valuable and informative video. Moreover, its fun when you choose his nose as template haha luv it. You deserve 100k++ subs and u will definitely get it soon!! Cheer u up mate! 😎😍👍
You motivate me, thanks!
Good Tutorial! I like to create bot for game too! Waiting for your next video!!
will be ready soon!
Wow man thx for helping love you man
Very cool guide! used it to make python open cows in cow evolution
NOW HOW DO I STOP IT!!
There are many ways! You can always just move your mouse to the upper left corner and pyautogui will stop
Hi, it's really great tutorial however - What if I want to match two images? For example I have one cola bottle and one perfume bottle. How do I match template, so it clicks the one that pop ups?
Hello!
You need to create a for loop. Example:
#Load templates:
colaImg = cv2.imread("cola.png",0)
perfumeImg = cv2.imread("perfume.png",0)
templates_ls = [colaImg, perfumeImg]
#Load screen vision
pyautogui.screenshot("train.png")
trainImg = cv2.imread("train.png",0)
#run matchtemplate using for loop.
for i in range(0,2):
result = cv2.matchTemplate(templates_ls[i],cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
if max_val >= 0.8:
x, y = max_loc
pyautogui.click(x, y)
This solution will look for the colaImg and then for the perfumeImg in the same screenshot, if found, it will click on the topleft part of where such template is located.
@@noobcodingandgaming7312 Wow thank you for such detailed response! Will try it in my free time :)
subbed and liked
thank you for your support
What is your high score? Kind of funny that I wrote code to automate this game using open cv a few weeks ago and now I am targeted by RUclips to watch your video! "They" must be watching me! :-)
Lol, their algorythm is something else. What was your high score? Mine is the one on the vid!
Nice video! My problem is trying to figure out how to use this method with mouse clicks and keyboard. How do you combine them to perform the task?
This video shows how to use with mouse clicks. For keyboard input you can try the pyautogui.press() function. You should check out the Docs!
Nice video. But I want you to explain for me - if I use camera which include palm detection instead of mouse , I could make the game and it can match with between mole coordination and my hand coordination? I really wonder I could make it ..
100% possible!
Oh really? That's using variable - coordination?
bro don't save the screenshot to hard disk try doing it in main memory....i did it and it is 10 times faster :)
@justin joseph how? Can you explain it?
@@Aru8675 main memory means store it in a variable
@@justinjoseph6575 will you make Minesweeper bot for Android game 5×5 minesweeper game to display hidden mines or to make bot capable of playing itself, finding the golds without any mistake until game ends also include options like bot must ask user like game asks before playing with how many mines do you want to play? such as 2-25, 3 to 25, 24 mines and one left space where there will be only 1 gold out of 25 ... using x , y coordinates method with libraries openCV, pyautogui, etc and color detection for Android game
@@Aru8675 that is different. you have to access memory and find the hidden values of each tile from the memory. I can make it👍👍
@@justinjoseph6575 will you please make a tutorial on it that will most requested and appreciated tutorial on this topic by everyone especially by me
I need help. I downloaded the proyecto, but it doesn't work. But there ir not errors.
Sorry, no idea of what the problem might be then. You to be sure, you have Python installed, right?
thank you. apply it to a 3d game?
I have a few videos to work on 2D, 3D Will come later on though!
In my case I don't get the library to detect nothing U.U
hello bro...great video...how do im pressing left button when image found in ROI and release the pressing button when image not found in ROI ...this code im modified from your coding
if max_val >= 0.7:
pyautogui.mouseDown()
else
break
this code not release the press when image not found....need some advise
thanks
Hello! mouseDown() does not release the button, You need to use mouseUp() after it. Or You can replace mouseDown() for pyautogui.click()
I really can't get this to work on my iMac and I'm pretty sure it has to do with resolution of the screenshot compared to the resolution/pixels which are downsized on my retina display.
Any clue how to handle? The screenshots / template is checked in completely wrong areas and when it actually finds something and clicks, it clicks on my X, Y coordinates. Or if you can tell me how to get the coordinates on mac just like paint does for you.
My very fist video is about a mouse tracking program, copy paste the source code and run it... Check the channel, it was My very first and worst vídeo lol
nice made, good explained but you made mistake. ad 2:16 you not mention the import "from re import template"
That was an auto import for vs code. You can delete that line
How to contact you
my program didnt detect the rectangle, how do i fix this?
Does an error appear?
@@noobcodingandgaming7312 no error, but the program didnt work, i cant see red rectangle on cv like u
@@nanabuy sorry then, no idea what might be the problem
For clash of clans please
in two weeks!
@@noobcodingandgaming7312 thanks
I have a project for you
why do i get the message
Traceback (most recent call last):
File "C:\Users\BigFanOfNoobCodingAndGaming\PycharmProjects\pythonProject\Deel2.py", line 40, in
if max_val >= 0.8:
^^^^^^^^^^^^^^
TypeError: '>=' not supported between instances of 'tuple' and 'float'
For some reason max_val is being returned as a tuple and python can't compare it to 0.8 because they are different data types.
I would recommend for you to print max_val to the console before it enters the comparison and maybe you can pinpoint the error there.
I would be happy to look at your code if you post it on stackoverflow. Cheers!
@@noobcodingandgaming7312 dammm i cant find a way to add multiple images .even if i add them , pyautogui doesnt click them .... idk where is the mistake
hi, I run the program but after moment I get error "PermissionError: [Errno 13] Permission denied: imgs/image.png"
Any solution? thank you
I think that error pops up when you have the image open using another program. Otherwise try to delete and redownload it.
Edit: also if your computer is too fast, you might want to add some sleep time before opening that image using opencv
Possible to contact you on discord or something?