Topview Logo
  • Create viral videos with
    GPT-4o + Ads library
    Use GPT-4o to edit video empowered by Youtube & Tiktok & Facebook ads library. Turns your links or media assets into viral videos in one click.
    Try it free
    gpt video

    How I made an Image Recognition Bot using Python with ChatGPT...

    blog thumbnail

    How I Made an Image Recognition Bot Using Python with ChatGPT

    I hate the Piano Tiles game. It's just so fast and stressful, and I can never get past level five. But then I had an epiphany—what if I could use AI to do the work for me? And that’s exactly what I did.

    The first thing I did was ask ChatGPT, an AI language model, to write a script for me. Initially, the AI printed out a script that played Twinkle Twinkle Little Star on the piano, and let me tell you, it was a disaster.

    Anyway, I was able to clarify with the AI that I meant the Piano Tiles game, where you click on four tiles as they slide across the screen. It then gave me a script that clicks on four points on the screen, which was basically exactly what I needed. However, I couldn't stop the script from running, so I asked it to modify the script to have a way to stop it. It added this one line, which basically stops the code when I press Q on my keyboard.

    Next, I wanted to improve the script so it only clicks when it recognizes a black tile. To do this, I needed to define the exact X and Y coordinates on my screen where the tiles were. I asked the AI to print the coordinates of my mouse. I then positioned my mouse where I wanted it to detect the tiles, and the code would then print my coordinates out. I also needed the RGB value of the black tile so I could give it to the script to check if the pixel matches the color of the black tile. RGB stands for red, green, and blue, and it is a way of representing colors on a computer screen. Essentially, every color you see on your screen is made up of a combination of these three colors. I stumbled upon the right value of the tile, which was black, and then refined the code a little bit, and it worked! The script was able to click on the black tiles as they slid across the screen.

    So I just realized I should probably explain the code just a little bit. This part up here sets the coordinates of the points to check, so since there are four tiles, I want to check four different points. Next, we need the target color that we will be looking for, which is black (so that’s 0,0,0). Next, we'll create a loop. Essentially, a loop is a part of the code that will continuously run until it is stopped. While true, it will basically get the pixel colors of these four points up here, and then it will check if any of these pixels match the target color. So if pixel one matches the target color, then it will click; if it matches pixel two, then it will click as well. I can stop the code by pressing Q on the keyboard, which will break the code and stop the script. And this part here basically waits for a short time before checking again; this is essentially to add some delay to prevent errors from happening.

    Now, back to the video. However, eventually, the script stopped working because it couldn't keep up with the tiles. It was like a game of cat and mouse. The tiles would slide across the screen, and the script would try to click on them, but it just couldn't keep up.

    To fix this, I asked ChatGPT for advice, but I kind of knew what the answer was for this, and that was to remove the time delay. And that's exactly what I did, and it worked. The script was able to keep up with the tiles, and I was able to beat the game. Now, I know what you're thinking: "Wow, this guy is really smart. He must be some kind of genius to be able to beat a simple game like Piano Tiles." But let me tell you, I am a genius, but it was all thanks to ChatGPT.

    So that's how I used AI to beat the Piano Tiles game. It was a long and difficult process, but in the end, I'd rate the whole experience an 8 out of 10. The script was simple to make and effective, although not perfect, it got the job done. Thank you so much for reading, and see you guys in the next article.


    Keywords

    1. Piano Tiles
    2. AI
    3. ChatGPT
    4. Script
    5. Python
    6. RGB
    7. Coordinates
    8. Pixel Detection
    9. Automation
    10. Game Bot

    FAQ

    Q: What is the Piano Tiles game?
    A: Piano Tiles is a game where players must click on black tiles as they slide across the screen. The game increases in speed as levels progress, making it challenging.

    Q: Why did you use ChatGPT to write the script?
    A: I used ChatGPT to generate the script because it’s an advanced AI language model capable of writing code and offering programming suggestions, which sped up the development process significantly.

    Q: How does the script know where to click?
    A: The script defines the X and Y coordinates on the screen where the tiles appear. It then checks the color of those coordinates to see if they match the target color (black).

    Q: What are RGB values?
    A: RGB stands for Red, Green, Blue. It’s a way of representing colors on a computer screen. Each color is made up of a combination of these three primary colors.

    Q: How did you stop the script from running?
    A: I modified the script to stop when I pressed the Q key on my keyboard. This was done by adding a simple line of code to break the loop.

    Q: Why did the script eventually stop working?
    A: The script stopped working because it couldn't keep up with the increasing speed of the tiles. To fix it, I removed the time delay, which helped the script keep up with the game's pace.

    One more thing

    In addition to the incredible tools mentioned above, for those looking to elevate their video creation process even further, Topview.ai stands out as a revolutionary online AI video editor.

    TopView.ai provides two powerful tools to help you make ads video in one click.

    Materials to Video: you can upload your raw footage or pictures, TopView.ai will edit video based on media you uploaded for you.

    Link to Video: you can paste an E-Commerce product link, TopView.ai will generate a video for you.

    You may also like