Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
dTub
Скачать

Real-time Object Detection - OpenCV Object Detection in Games #5

Автор: Learn Code By Gaming

Загружено: 2020-06-22

Просмотров: 105812

Описание:

Learn how to detect objects inside a game window in real-time using OpenCV.

Full tutorial playlist:    • OpenCV Object Detection in Games  

Grab the code on GitHub: https://github.com/learncodebygaming/...

0:37 WindowCapture updates
3:28 Integrating findClickPositions()
5:18 Updating main
7:20 Demonstration of real-time detection working!
7:59 Creating a Vision class
14:12 Browser game demonstration
15:56 Shortcomings of this object detection

Read the full written tutorial with code samples here: https://learncodebygaming.com/blog/re...

In the first three parts of this tutorial series, we learned how to use OpenCV's matchTemplate() to detect objects inside an image. Then in part #4, we learned how to quickly capture screenshots and display them as a video stream inside of an OpenCV window. Now we're ready to combine together everything we've learned so far in order to detect objects in real-time.

We could reuse our WindowCapture class completely unchanged from the last tutorial, but I want to make a few improvements to it. First let's save this class to its own file if you haven't done so already: windowcapture.py.

I'd like to convert the list_window_names() member function into a static method. This is done by adding the @staticmethod decorator above the method definition, and removing self from the parameters. The reason you might want to do this is that it allows us to call this function at any time without first instantiating an object, like this: WindowCapture.list_window_names(). You'll find this to be more convenient. Note that we can only do this because list_window_names() does not reference any class properties.

I've also changed the constructor to accept None for the window_name. When given no window name, we'll have WindowCapture just capture the entire screen. I've found that certain applications return a black screen (Chrome), or do not update after the initial image capture (Firefox), and capturing the entire screen can be a suitable fallback plan in those cases.

Let's also save our findClickPositions() function to its own file. I've called mine vision.py.

A few alterations need to be made to findClickPositions(). This function will now be processing an OpenCV image returned by WindowCapture instead of reading an image from a file. To account for this, we'll change the second parameter from haystack_img_path to just haystack_img, and we'll remove the cv.imread() call. In the debugger portion of this function, we'll also want to remove cv.waitKey(), as this is now handled in our main loop (as covered in part #4). That same block of code should also no longer fall under the if needle found conditional, because we want to update the image stream with cv.imshow() even when no matches are found.

Our main.py file will also pick up from where we left off in part #4. We simply need to swap out our cv.imshow() call with a call to findClickPositions() instead.

The first parameter in findClickPositions() is the needle image we want to search for. You'll want to manually take a screenshot and crop out the item you want to match (like we did in part #1). For the second parameter we'll pass in the screenshot returned by WindowCapture's get_screenshot(). Then set your threshold, and enable one of the debug modes.

Now when you run main.py with your game client open, you can see your object being detected in the OpenCV window in real-time! Move your character around a bit to test the effectiveness of this detection.

Before we discuss some of the limitations and shortfalls of our object detection, let's first make some improvements to our vision.py code. I want to convert this into a class, to keep everything more organized as we improve upon what we have.

We'll call our new class Vision, and let's read in the needle image in the constructor so that we don't need to repeat that step during every iteration of our main loop. We can also assign our matchTemplate() comparison method here. This will allow us to use different methods for different visions.

We'll want to make findClickPositions() a method inside of the Vision class. To do that, get your tabs right, and remember to add self as the first parameter. We also no longer need the needle_img_path parameter in this function, nor the other steps that are now handled by the construtor. Remember to update all usages of those variables that are now class properties to use self.. I'm also going to take this opportunity to change this function name to simply find().

Now we need to update our main.py to work with our new Vision class. Update the import, and then we can initialize our vision object before starting the main loop. Inside the main loop, we can now call find() on that vision object, passing in the latest screenshot from WindowCapture.

Continue with the written tutorial here: https://learncodebygaming.com/blog/re...

Real-time Object Detection - OpenCV Object Detection in Games #5

Поделиться в:

Доступные форматы для скачивания:

Скачать видео mp4

  • Информация по загрузке:

Скачать аудио mp3

Похожие видео

HSV Color Range Thresholding - OpenCV Object Detection in Games #6

HSV Color Range Thresholding - OpenCV Object Detection in Games #6

Быстрый захват окна — обнаружение объектов OpenCV в играх №4

Быстрый захват окна — обнаружение объектов OpenCV в играх №4

How To Send Inputs to Multiple Windows / Minimized Windows with Python. Or Die Trying

How To Send Inputs to Multiple Windows / Minimized Windows with Python. Or Die Trying

Dominating an Online Game with Object Detection Using OpenCV - Template Matching.

Dominating an Online Game with Object Detection Using OpenCV - Template Matching.

OpenCV Object Detection in Games

OpenCV Object Detection in Games

Training a Cascade Classifier - OpenCV Object Detection in Games #8

Training a Cascade Classifier - OpenCV Object Detection in Games #8

Canny Edge Detection? ORB Feature Matching? - OpenCV Object Detection in Games #7

Canny Edge Detection? ORB Feature Matching? - OpenCV Object Detection in Games #7

ml5.js: Object Detection with COCO-SSD

ml5.js: Object Detection with COCO-SSD

Измерение размера любого объекта с помощью веб-камеры | Учебное пособие по Python и OpenCV

Измерение размера любого объекта с помощью веб-камеры | Учебное пособие по Python и OpenCV

Dominating an Online Multiplayer Game using Python and OpenCV.

Dominating an Online Multiplayer Game using Python and OpenCV.

How To Code a RuneScape Bot with RobotJS - Learn JavaScript by playing RuneScape 1/4

How To Code a RuneScape Bot with RobotJS - Learn JavaScript by playing RuneScape 1/4

Build an Object Detector for Any Game Using YOLO

Build an Object Detector for Any Game Using YOLO

Негативный портал - как он объясняет карманное пространство?

Негативный портал - как он объясняет карманное пространство?

Группировка прямоугольников в точки щелчка — обнаружение объектов OpenCV в играх №3

Группировка прямоугольников в точки щелчка — обнаружение объектов OpenCV в играх №3

Master Python by making 5 games [the new ultimate introduction to pygame]

Master Python by making 5 games [the new ultimate introduction to pygame]

Training AI to Play Pokemon with Reinforcement Learning

Training AI to Play Pokemon with Reinforcement Learning

How to make advanced image recognition bots using python

How to make advanced image recognition bots using python

Thresholding with Match Template - OpenCV Object Detection in Games #2

Thresholding with Match Template - OpenCV Object Detection in Games #2

Saving FPS Games - AI Anti-Cheat

Saving FPS Games - AI Anti-Cheat

Как использовать бот с OpenCV — обнаружение объектов OpenCV в играх #9

Как использовать бот с OpenCV — обнаружение объектов OpenCV в играх #9

© 2025 dtub. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: infodtube@gmail.com