Fast Window Capture - OpenCV Object Detection in Games #4
Why Stack Overflow recommends it
Stack Overflow users link it as the source of their win32gui/win32ui window-capture code when asking why pywin32 imports or CreateCompatibleDC fail, or how to do the same thing on another OS.
Recommended by 0 people across 0 different months, 2021 to 2022.
What it is
A 30-minute Python tutorial from the Learn Code By Gaming OpenCV game-bot series on capturing a window as a real-time video stream. It benchmarks PyAutoGUI, Pillow ImageGrab and pywin32 for speed, then builds a reusable WindowCapture class that crops to a specific window and converts the bitmap into an OpenCV image.
What people said
Cites Ignacio · 2021-02 · Stack Overflow · on “The pywin32 libraries (win32gui, win32ui, win32con) show "unresolved-import"”
I have downloaded Python 3.7 and 3.9 (both 64 bit) as well as VS Code to replicate the following code: [this video] However, when installing "pywin32" and then importing the packages to the code, I get "unresolved-import" on the three imports: win32gui, win32ui and win32con. I have tried multiple installation methods, what is strange is that the code replicated from the link above works. Tried installing via "pip" [LINK] As well as downloading the executable program for installation from: [LINK] Including installing using the .whl files from: [LINK] (with their respective Python version and bits) and then proceeding to the "post-installation" which was explained here: Not able to use the win32gui
Cites Diasky VB · 2021-06 · Stack Overflow · on “Python win32ui.error: CreateCompatibleDC failed”
I'm trying to capture sceen using win32 for opencv but when i start it gives me an error about the CreateCompatibleDC function. That's the first time i touch this library so i don't really know how to fix this. import numpy as np import win32gui,win32ui,win32con class WindowCapture: # properties w = 0 h = 0 hwnd = None cropped_x = 0 cropped_y = 0 offset_x = 0 offset_y = 0 # constructor def __init__(self, window_name): # find the handle for the window we want to capture self.hwnd = win32gui.FindWindow(None, window_name) if not self.hwnd: raise Exception('Window not found: {}'.format(window_name)) # get the window size window_rect = win32gui.GetWindowRect(self.hwnd) self.w = window_rect[2] - w
Cites Noob · 2022-10 · Stack Overflow · on “Is there a way to take a screenshot as bytes (Fedora 35)”
I'm trying to find a way to take a screenshot and save it as bytes like in this video: [this video] where he uses win32ui in Python to do that. I've searched around and haven't found anyome who has answered this. I've done this before in windows where I've screenshot as bytes, read as numpy, pass it into opencv and basically have the viewer open refreshing the image between 30-60fps. Any leads would be great.