Detecting Objects Based on RGB Colors : PyAutoGUI and OpenCV for Object Detection in Games Episode 2

preview_player
Показать описание
In this tutorial, we use PyAutoGUI to perform a pixel comparison between pixels on the screen to detect objects. We set a region to make our bot faster and implemented a cool feature for our bot to stop playing and determine the gameplay status. By coding like a real scenario and experiencing several failures, we were finally able to make this happen.

Details of Each Section of Code

1. Importing Modules: We begin by importing the necessary Python modules to empower our automation process:
PyAutoGUI: Enables us to programmatically control the mouse and keyboard, facilitating GUI automation.

time: Provides functions for time-related tasks, like introducing delays to synchronize with GUI actions.

random: Essential for generating random numbers, which we leverage in our game logic.

Pyscreeze: Empowers us to capture and manipulate screenshots for image recognition.

PIL: This module offers powerful image processing capabilities, used here to interact with images effectively.

2. Disabling Exception for Image Not Found:
We set pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = False to suppress exceptions when an image isn't found during image recognition.

3. Function Definitions:
center_finder_region(path, confidence, region): Locates the center coordinates of a specified image within a designated region of the screen.

center_finder(path, confidence): Similar to the previous function but searches the entire screen for the specified image.

preparation(): Executes initial setup tasks before the main automation, such as clicking on specific icons and buttons to prepare the environment.

click_on_RGBpixel(r_value, g_value, b_value, coords): Identifies and clicks on a pixel with predetermined RGB values within a specified region.

4. Defining Color Values:
We define RGB tuples for various colors used in our game logic, such as Bitcoin, Dogecoin, different shades of blue, and gray.

5. Main Game Logic (play() Function):
This function encapsulates the core automation logic with a unique twist to ensure smooth gameplay and efficient resource management: Capture a screenshot and extract the RGB value at a specific location.

Utilize a while loop with an innovative exit condition to cease gameplay seamlessly: Instead of relying solely on continuous pixel comparisons, we employ a clever method that monitors a specific area of the screen for changes indicative of the game's end state.

Within the loop, continuously search for specific colors on the screen and click on them using the click_on_RGBpixel() function. The innovative exit condition ensures the script stops playing when the game reaches its conclusion, enhancing performance and resource utilization.

Exercise caution to avoid being banned from this website due to your bot usage. Should any issues arise with your account, refrain from directing complaints towards me.

00:00 intro
0:57 cleaning our last code
02:26 how to set a region for our detection
05:00 using keyboard function in PyAutoGUI ( Hotkey )
23:50 how to set stop-playing method in while loop
36:00 implement the fastest function to detect RGB colors
52:00 watching how our bot is winning the game
52:50 outro

#automation #computervision#PythonAutomation
#GUIAutomation #ImageRecognition #GameScript
#BotDevelopment #PyAutoGUI #PixelDetection
#Scripting #PythonProgramming #codingjourney
#howtomakerobot #howtouseopencvforgame
#howtousepyautoguiingame #objectdetectioningames
Рекомендации по теме
Комментарии
Автор

Listening the vid to get asleep thanks to the sweet and slow voice😅😊

mrdjangofreeman
Автор

hey dude, are you available to code for me, i dont really understand any of this 😭

td
visit shbcf.ru