ra1nty / DXcam

A Python high-performance screen capture library for Windows using Desktop Duplication API
MIT License
457 stars 67 forks source link

frame can't show in imshow #60

Closed zimixvx closed 1 year ago

zimixvx commented 1 year ago

`cv2.error: OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function 'imshow'

Overload resolution failed:

  • mat data type = 17 is not supported
  • Expected Ptr for argument 'mat'
  • Expected Ptr for argument 'mat'`

code

frame = camera.grab(region=region)  # numpy.ndarray of size (640x640x3) -> (HXWXC)
npImg = np.array(frame)
cv2.imshow('DXCAM EXAMPLE', npImg)
cv2.waitKey(1)
AI-M-BOT commented 1 year ago

What is the region? Python version? Also you might not need npImg = np.array(frame)

zimixvx commented 1 year ago

640x640 py 3.8 didnt work btw

zimixvx commented 1 year ago

fixed

import cv2
import dxcam

MONITOR_WIDTH = 1920  # game res
MONITOR_HEIGHT = 1080  # game res
MONITOR_SCALE = 1  # how much the screen shot is downsized by eg. 5 would be one fifth of the monitor dimensions
region = (int(MONITOR_WIDTH / 2 - MONITOR_WIDTH / MONITOR_SCALE / 2),
          int(MONITOR_HEIGHT / 2 - MONITOR_HEIGHT / MONITOR_SCALE / 2),
          int(MONITOR_WIDTH / 2 + MONITOR_WIDTH / MONITOR_SCALE / 2),
          int(MONITOR_HEIGHT / 2 + MONITOR_HEIGHT / MONITOR_SCALE / 2))
camera = dxcam.create(output_idx=0, output_color="BGRA")
while True:
    screenshot = camera.grab(region)
    if screenshot is not None:
        cv2.imshow('1', screenshot)
        cv2.waitKey(1)