I am working on a project that involves automating a video game using computer vision. My next task involves separating the game's UI elements from the actual game's field of view. For instance:
We would take a screenshot of the entire client window like so:
Then we would locate the various UI elements on screen (this is accomplished with template matching, see: Template matching with transparent image templates using OpenCV Python).
Then, we would need to subtract the matched templates from the client screenshot to end up with something like this:
This allows me to perform computer vision functions on the game's field of view without the risk of the UI elements interfering.
Let's say we have the following code:
# Let's assume we have already taken a screenshot of the client window
client_window = cv2.imread('client_window.png')
# Here are the three UI areas I'd like to remove/blackout from the above image
ui_chatbox = {'left': 0, 'top': 746, 'width': 520, 'height': 167}
ui_minimap = {'left': 878, 'top': 31, 'width': 212, 'height': 207}
ui_inventory = {'left': 849, 'top': 576, 'width': 241, 'height': 337}
How can we blackout the pixels of the UI element bounding boxes from the client_window
matrix?