Learn Code By Gaming How To Bot with OpenCV - OpenCV Object Detection in Games #9
🎯 Загружено автоматически через бота:
🚫 Оригинал видео:
📺 Данное видео принадлежит каналу «Learn Code By Gaming» (@LearnCodeByGaming). Оно представлено в нашем сообществе исключительно в информационных, научных, образовательных или культурных целях. Наше сообщество не утверждает никаких прав на данное видео. Пожалуйста, поддержите автора, посетив его оригинальный канал.
✉️ Если у вас есть претензии к авторским правам на данное видео, пожалуйста, свяжитесь с нами по почте support@, и мы немедленно удалим его.
📃 Оригинальное описание:
Learn how to combine OpenCV object detection with PyAutoGUI and Threading to build a custom Python video game bot. Using the OpenCV image recognition techniques discussed earlier in this tutorial, we can now use that data to perform mouse clicks automatically. We’ll use Python threads so that our bot actions can happen independently of our object detection.
Full tutorial playlist:
Grab the code on GitHub:
PyAutoGUI:
PyDirectInput:
Automating mouse clicks
Basic threading
Advanced threading
Botting logic
Enum data structure
Stack data structure
Bot demo
Email me: ben@
Full written tutorial:
My gear:
Building a bot with OpenCV is a matter of combining the object detection techniques that we’ve discussed (in the last 8 parts of this tutorial series) with some GUI automation. Now that you know how to find an object using OpenCV, you just need to use something like PyAutoGUI or PyDirectInput to click on the objects you find. But there are a few architectural decisions that can make it kind of difficult to know where to get started. So I’ll walk you through one way to approach this that should be pretty flexible and act as a good foundation for building a more capable bot.
The most straightforward way to add automated mouse clicks to our bot script is to do it inline. By that I mean we can take a screenshot, process it to find the objects we want, and then perform any actions we want our bot to take. So we can do that sequentially, and just loop back around when our bot is done with its actions. So let me show you what that would look like, and then I’ll point out some of the limitations with that method.
[see the code samples on ]
In this code, once we have the detected objects in the form of a list of rectangles, we first convert those into click positions using the get_click_points() and get_screen_position() functions we wrote previously. Then it’s taking the very first screen position in that list, moves the mouse to that position using (), and then we use PyAutoGUI again to do the mouse click. Hopefully this has resulted in clicking on our target (a limestone deposit in Albion Online), and we pause our script for 5 seconds using sleep() to give our character time to do that mining.
So one of the problems this code has is it’s going to take at least 5 seconds between each update of our debug output. That isn’t great for seeing how well our object detection is working, compared to the continuous video stream we had before. But writing a bot this way will still work, and it keeps things simple if you don’t mind doing the object detection only when you need it.
If you want to get more advanced, you can fix this problem by using threading.
Threading, or multithreading, is the ability that all modern computers have to run multiple processes or threads in parallel at the same time. This is what allows you to have multiple programs running at once. Right now our bot script runs as just a single thread, but by using the Python threading library we can make it branch out and do multiple things at once (run in multiple threads).
In our case, what it’d be great to do, is to have our main script running in the main thread, and then branch off our bot actions into a separate thread. That way the bot can go off and do the things it needs to do without blocking the execution of our main thread where the object detection is happening.
In the main loop we call Thread() to create a new thread object in our program. We tell it what code to execute by giving it a function name as the target, and then passing in the parameters needed by the function as a tuple. We can then run that function in a separ
16 views
0
0
3 days ago 00:21:02 1
[CGDive (Blender Rigging Tuts)] Auto-Rig Pro: Custom rigs from Scratch
3 days ago 00:16:20 2
[How to Beast] 7 Attractive Hobbies All Guys Should Learn
3 days ago 00:12:33 1
[Sean Foo] BLOODBATH; Global Markets Crash As U.S. Fed Cancels 2025 Rate Cuts - What’s Next?
3 days ago 00:01:44 2
[Conor3D] [PROMO CODES] How to get the NGUYEN BOI & NGUYEN GON BUNDLES | Roblox
4 days ago 00:01:34 2
How to make more money online
4 days ago 00:09:11 1
[Ponte Ryuurui] Want to DOMINATE Plasticity Booleans in 9 minutes? Watch This Now!
4 days ago 00:19:17 10
[Sliinky 2] High Elimination Solo Zero Builds (Fortnite Chapter 6)
4 days ago 00:19:34 9
[Kyle McDougall] 4x5 Large Format Photography using Paper... instead of Film
4 days ago 04:59:06 1
[] Elasticsearch Course for Beginners
4 days ago 04:32:43 1
[] Spring AI Full Course with Projects – Build Smarter Spring Boot Applications
4 days ago 00:23:01 1
[CGDive (Blender Rigging Tuts)] [Blender 2.8/2.9] Rigify Face Rig (Rigify Series, Part #9)
4 days ago 00:12:36 2
[CGDive (Blender Rigging Tuts)] [Blender 2.8~3.6] Rig ANYTHING with Rigify #4 - FRANKENSTEIN Meta Rigs
4 days ago 00:13:42 3
[CGDive (Blender Rigging Tuts)] [Blender 2.8~3.6] Rig ANYTHING with Rigify #3.1 - Prebuilt Meta Rigs (Human)
4 days ago 00:15:20 2
[CGDive (Blender Rigging Tuts)] [Blender 2.8~3.6] Rig ANYTHING with Rigify #2 - the Rigify Workflow
4 days ago 00:13:03 6
[English with Lucy] 12 Confusing English Verbs
4 days ago 00:20:49 19
[English with Lucy] Learn 100+ Common Foods & Dishes in English in 20 Minutes | Food Vocabulary
4 days ago 00:28:12 1
[ArjanCodes] NEVER Worry About Data Science Projects Configs Again
5 days ago 00:15:45 1
[Proko] Boost Your Creativity with Daily Sketching
5 days ago 00:09:27 1
UPDATE Develop a Full-Stack App Without Writing ANY Code! (Auth, Database, Etc!)
5 days ago 00:16:13 17
[Sliinky 2] High Elimination Unreal Ranked Reload Zero Builds (Fortnite Chapter 6)
5 days ago 00:12:38 3
[Sean Foo] As This Major G7 Currency Collapses, Spain Defies The EU For Big China Investment
6 days ago 00:08:09 1
Devin AI Software Engineer - Generate and Deploy Apps End-to-End! (UPDATE)
6 days ago 00:07:48 6
[Slant 3D] Design Better Holes | Improve Tolerances | Reduce Sagging | Design for Mass Production 3D Printing
6 days ago 00:12:42 1K
[Sean Foo] Canada’s DONE With The U.S. Economy As Trump Mocks “Great State of Canada“