Making a Whack a Mole bot using OpenCV's Match Template

Поделиться
HTML-код
  • Опубликовано: 6 окт 2024

Комментарии • 61

  • @claywaters13
    @claywaters13 3 года назад +3

    Very cool tutorial. I was able to get a score of 3860 using a similar approach. Thanks for sharing such a great learning project.

  • @DinDin-jd9lg
    @DinDin-jd9lg 2 года назад +2

    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! 😎​😍​👍​

  • @ddtdilireba
    @ddtdilireba 3 года назад +4

    Good Tutorial! I like to create bot for game too! Waiting for your next video!!

  • @babyicegolf1610
    @babyicegolf1610 2 года назад

    Wow man thx for helping love you man

  • @elliotlyhne3390
    @elliotlyhne3390 2 года назад +1

    Very cool guide! used it to make python open cows in cow evolution
    NOW HOW DO I STOP IT!!

    • @noobcodingandgaming7312
      @noobcodingandgaming7312  2 года назад

      There are many ways! You can always just move your mouse to the upper left corner and pyautogui will stop

  • @Nikox102
    @Nikox102 2 года назад +3

    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?

    • @noobcodingandgaming7312
      @noobcodingandgaming7312  2 года назад +3

      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.

    • @Nikox102
      @Nikox102 2 года назад +1

      ​@@noobcodingandgaming7312 Wow thank you for such detailed response! Will try it in my free time :)

  • @darphaprothon20
    @darphaprothon20 2 года назад +1

    subbed and liked

  • @RobbyComstock
    @RobbyComstock 2 года назад +1

    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! :-)

    • @noobcodingandgaming7312
      @noobcodingandgaming7312  2 года назад

      Lol, their algorythm is something else. What was your high score? Mine is the one on the vid!

  • @jonathanmedina6627
    @jonathanmedina6627 2 года назад +2

    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?

    • @noobcodingandgaming7312
      @noobcodingandgaming7312  2 года назад

      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!

  • @이현빈-z5f
    @이현빈-z5f 2 года назад +1

    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
    @justinjoseph6575 Год назад +5

    bro don't save the screenshot to hard disk try doing it in main memory....i did it and it is 10 times faster :)

    • @Aru8675
      @Aru8675 Год назад +2

      @justin joseph how? Can you explain it?

    • @justinjoseph6575
      @justinjoseph6575 Год назад +1

      @@Aru8675 main memory means store it in a variable

    • @Aru8675
      @Aru8675 Год назад +2

      @@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

    • @justinjoseph6575
      @justinjoseph6575 Год назад +1

      @@Aru8675 that is different. you have to access memory and find the hidden values of each tile from the memory. I can make it👍👍

    • @Aru8675
      @Aru8675 Год назад +2

      @@justinjoseph6575 will you please make a tutorial on it that will most requested and appreciated tutorial on this topic by everyone especially by me

  • @jaaqgames1570
    @jaaqgames1570 2 года назад +1

    I need help. I downloaded the proyecto, but it doesn't work. But there ir not errors.

    • @noobcodingandgaming7312
      @noobcodingandgaming7312  2 года назад

      Sorry, no idea of what the problem might be then. You to be sure, you have Python installed, right?

  • @fpsgamesalive3917
    @fpsgamesalive3917 2 года назад +1

    thank you. apply it to a 3d game?

  • @magnumdavid6394
    @magnumdavid6394 Год назад

    In my case I don't get the library to detect nothing U.U

  • @momospadastine2457
    @momospadastine2457 2 года назад

    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

    • @noobcodingandgaming7312
      @noobcodingandgaming7312  2 года назад

      Hello! mouseDown() does not release the button, You need to use mouseUp() after it. Or You can replace mouseDown() for pyautogui.click()

  • @DerMberger
    @DerMberger 2 года назад +1

    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.

    • @noobcodingandgaming7312
      @noobcodingandgaming7312  2 года назад

      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

  • @mikeygoby6154
    @mikeygoby6154 2 года назад

    nice made, good explained but you made mistake. ad 2:16 you not mention the import "from re import template"

  • @thejasgowda9295
    @thejasgowda9295 2 года назад

    How to contact you

  • @nanabuy
    @nanabuy 2 года назад

    my program didnt detect the rectangle, how do i fix this?

    • @noobcodingandgaming7312
      @noobcodingandgaming7312  2 года назад

      Does an error appear?

    • @nanabuy
      @nanabuy 2 года назад

      @@noobcodingandgaming7312 no error, but the program didnt work, i cant see red rectangle on cv like u

    • @noobcodingandgaming7312
      @noobcodingandgaming7312  2 года назад

      @@nanabuy sorry then, no idea what might be the problem

  • @unperson37
    @unperson37 3 года назад +1

    For clash of clans please

  • @thejasgowda9295
    @thejasgowda9295 2 года назад

    I have a project for you

  • @officialonbekende9785
    @officialonbekende9785 2 года назад +2

    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'

    • @noobcodingandgaming7312
      @noobcodingandgaming7312  2 года назад

      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!

    • @officialonbekende9785
      @officialonbekende9785 2 года назад

      @@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

  • @gonzaloherrera4730
    @gonzaloherrera4730 2 года назад +1

    hi, I run the program but after moment I get error "PermissionError: [Errno 13] Permission denied: imgs/image.png"
    Any solution? thank you

    • @noobcodingandgaming7312
      @noobcodingandgaming7312  2 года назад

      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

  • @alexthealex.
    @alexthealex. Год назад +1

    Possible to contact you on discord or something?