Closed Coding-man12435676543 closed 3 years ago
*Result: Using HWND returns a black screen
Making an instance of the class and use the screenshot function in a loop
`def get_screenshot(self):
wDC = win32gui.GetWindowDC(self.hwnd) dcObj = win32ui.CreateDCFromHandle(wDC) cDC = dcObj.CreateCompatibleDC() dataBitMap = win32ui.CreateBitmap() dataBitMap.CreateCompatibleBitmap(dcObj, self.w, self.h) cDC.SelectObject(dataBitMap) cDC.BitBlt((0, 0), (self.w, self.h), dcObj, (0, 0), win32con.SRCCOPY)
signedIntsArray = dataBitMap.GetBitmapBits(True) img = np.fromstring(signedIntsArray, dtype='uint8') img.shape = (self.h, self.w, 4)
dcObj.DeleteDC() cDC.DeleteDC() win32gui.ReleaseDC(self.hwnd, wDC) win32gui.DeleteObject(dataBitMap.GetHandle())
img = img[...,:3]
img = np.ascontiguousarray(img)
return img`
`wincap = WindowCapture('Albion Online Client')
loop_time = time() while(True):
screenshot = wincap.get_screenshot() cv.imshow('Computer Vision', screenshot) # debug the loop rate print('FPS {}'.format(1 / (time() - loop_time))) loop_time = time() # press 'q' with the output window focused to exit. # waits 1 ms every loop to procress key presses if cv.waitKey(1) == ord('q'): cv.destroyAllWindows() break
print('Done')`
This sounds like a support request - please see https://github.com/mhammond/pywin32/blob/master/README.md#support
Taking multiple screenshots of a certain window using HWND to simulate a video returns a black screen in cv.imshow()
*Result: Using HWND returns a black screen
Making an instance of the class and use the screenshot function in a loop
Screenshot Function
`def get_screenshot(self):
get the window image data
wDC = win32gui.GetWindowDC(self.hwnd) dcObj = win32ui.CreateDCFromHandle(wDC) cDC = dcObj.CreateCompatibleDC() dataBitMap = win32ui.CreateBitmap() dataBitMap.CreateCompatibleBitmap(dcObj, self.w, self.h) cDC.SelectObject(dataBitMap) cDC.BitBlt((0, 0), (self.w, self.h), dcObj, (0, 0), win32con.SRCCOPY)
save the screenshot
dataBitMap.SaveBitmapFile(cDC, 'debug.bmp')
signedIntsArray = dataBitMap.GetBitmapBits(True) img = np.fromstring(signedIntsArray, dtype='uint8') img.shape = (self.h, self.w, 4)
Free Resources
dcObj.DeleteDC() cDC.DeleteDC() win32gui.ReleaseDC(self.hwnd, wDC) win32gui.DeleteObject(dataBitMap.GetHandle())
img = img[...,:3]
img = np.ascontiguousarray(img)
return img`
Creating Instance and using screenshot function in loop
`wincap = WindowCapture('Albion Online Client')
loop_time = time() while(True):
print('Done')`