An explaination of PrintWindowW
Right After this line in your code
compatible_dc.BitBlt((0, 0), (width, height), dc_object, (0, 0), win32con.SRCCOPY)
add
ctypes.windll.user32.PrintWindow(hwnd, compatible_dc.GetSafeHdc(), 2)
instead of win32gui.GetClientRect(hwnd)
, use win32gui.GetWindowRect(hwnd)
This will cleanup the image that you are converting to a numpy array for OpenCV. As far as the offset, you're going to end up with a boarder around the window itself because of shadowing around the window that is actually part of the window as you can see there isn't any spacing along the top of the images below.