DXcam icon indicating copy to clipboard operation
DXcam copied to clipboard

Importing opencv makes screenshots black

Open potatoriver opened this issue 3 years ago • 1 comments

Hi, I have a problem with the following code

import dxcam
from PIL import Image
import cv2
    
cam = dxcam.create()
img = cam.grab()
Image.fromarray(img).show()  # Screenshots are blacked out.

If opencv is not imported, it works fine.

import dxcam
from PIL import Image
    
cam = dxcam.create()
img = cam.grab()
Image.fromarray(img).show() # good

The following code works fine.

import dxcam
import numpy as np
from PIL import Image
import cv2
    
cam = dxcam.create()

while True :
    img = cam.grab()
    print(img[0][0])
    if img is not None :
        if np.mean(img)!= 0:
            break

Image.fromarray(img).show()

In this case, the console will output the following

[0 0 0]
[60 60 60]

dxdiag

         Operating System: Windows 10 Pro 64-bit (10.0, Build 19044) (19041.vb_release.191206-1406)
                 Language: Japanese (Regional Setting: Japanese)
                Processor: Intel(R) Core(TM) i5-6600 CPU @ 3.30GHz (4 CPUs), ~3.3GHz
                   Memory: 32768MB RAM
          DirectX Version: DirectX 12
      DX Setup Parameters: Not found
          DWM DPI Scaling: Disabled
                 Miracast: Available, with HDCP
Microsoft Graphics Hybrid: Not Supported
 DirectX Database Version: 1.0.8
           DxDiag Version: 10.00.19041.1741 64bit Unicode
           
           Card name: Radeon RX 570 Series
        Manufacturer: Advanced Micro Devices, Inc.
           Chip type: AMD Radeon Graphics Processor (0x67DF)

python

Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)] on win32

pip list

Package       Version
------------- --------
comtypes      1.1.13
d3dshot       0.1.5
dxcam         0.0.4
numpy         1.23.1
opencv-python 4.6.0.66
Pillow        9.2.0
pip           22.2.2
setuptools    63.2.0

dxcam

dxcam.device_info()
Device[0]:<Device Name:Radeon RX 570 Series Dedicated VRAM:8171Mb VendorId:4098>

dxcam.output_info()
Device[0] Output[0]: Res:(1920, 1080) Rot:0 Primary:True

Thanks for the cool library. :D

potatoriver avatar Aug 08 '22 18:08 potatoriver

I also encountered the same problem, comment out opencv to restore normal

import dxcam
import cv2
from PIL import Image

dxcamera = dxcam.create(device_idx=0, output_idx=0, output_color="RGB")
left, top = (2560 - 640) // 2, (1440 - 640) // 2
right, bottom = left + 640, top + 640
dxregion = (left, top, right, bottom)
dxcamera.start(region=dxregion, video_mode=True, target_fps=120)

 

frame=dxcamera.get_latest_frame()

Image.fromarray(frame).show()
Windows 11 22000.856
RTX 3090 Driver 516.59

pip list

comtypes           1.1.13
dxcam              0.0.4
numpy              1.21.6
opencv-python      4.6.0.66
Pillow             7.1.2
torch              1.12.1
torchaudio         0.12.1
torchvision        0.13.1

PlutoNameless avatar Aug 13 '22 00:08 PlutoNameless

Trying adding time.sleep(0.1) after initializing the camera

Originally posted by @Spexivus in https://github.com/ra1nty/DXcam/issues/7#issuecomment-1186290264

p9u9y avatar Sep 02 '22 20:09 p9u9y

As stated above, the workaround now is to add time.sleep(0.1) after initializing the camera. I have added that in the upcoming release.

ra1nty avatar Sep 04 '22 19:09 ra1nty