ra1nty / dxcam Goto Github PK
View Code? Open in Web Editor NEWA Python high-performance screen capture library for Windows using Desktop Duplication API
License: MIT License
A Python high-performance screen capture library for Windows using Desktop Duplication API
License: MIT License
This doesn't work
import dxcam
camera = dxcam.create(output_color="GRAY")
camera.start(video_mode=True)
frame = camera.get_latest_frame()
I got this error :
Traceback (most recent call last):
File "C:\Users\jeanp\miniconda3\envs\tm\lib\site-packages\dxcam\dxcam.py", line 179, in __capture
self.__frame_buffer[self.__head] = frame
ValueError: could not broadcast input array from shape (1080,1920) into shape (1080,1920,1)
Exception in thread DXCamera:
Traceback (most recent call last):
File "C:\Users\jeanp\miniconda3\envs\tm\lib\threading.py", line 932, in _bootstrap_inner
Easy to fix, a quick workaround is to expand the array after doing the color conversion.
BTW awesome project thank you !
I'm getting a bug where if the values of top and left are not 0 i get outputted region should be in 1920x1080
code.txt
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]
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 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)] on win32
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.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
Hi! The dxcam capture speed is unstable, between 0-10ms.The results are as follows. Why? Is it a bug?
1.1258000000000656
7.967900000000139
2.7013000000000176
2.367800000000031
3.877499999999756
0.017199999999828464
5.908699999999989
1.8077000000000787
1.7446000000003181
6.1069999999996405
1.5810000000002766
0.030100000000032878
1.7834999999997159
1.8221000000000487
0.040300000000215164
7.366799999999785
2.05870000000008
3.1911999999998386
In the game, resolution switching often leads to thread interruption. Should timeout support customization
Exception in thread DXCamera:
Traceback (most recent call last):
File "D:\Python\Python37\lib\threading.py", line 926, in _bootstrap_inner
self.run()
File "D:\Python\Python37\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "F:\IdeaProjects\yolov5\venv\lib\site-packages\dxcam\dxcam.py", line 208, in __capture
self.stop()
File "F:\IdeaProjects\yolov5\venv\lib\site-packages\dxcam\dxcam.py", line 142, in stop
self.__thread.join(timeout=10)
File "D:\Python\Python37\lib\threading.py", line 1041, in join
raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread
I'm new to programming, and i would like to save a screenshot in a directory, any way to it?
It is not really a problem considering this library is supposed to do something completely different, but I am using it for image detection program and I've come across a problem that I can't figure out how to solve. Basically I have a function that loops untill certain image is found on the screen. My problem is that since .grab() method captures the screen so fast, it often returns None and then further in the code it's used as an argument for cv2.matchTemplate method. I've tried writing some if statements and saving the last "good" screenshot if the new one would contain None in it, but doesn't seem to work. Basically what I'm asking is, is there a way to disable None return and get the screenshot even if it's the same as the last one or is there any other way to fix that problem? Sorry if it's a bit offtopic since I'm asking more for of an advice than reporting an actual problem.
Here's some code for reference:
lastImg = ''
def opencvCompareImages(fileName, confidence, method, offsetX = 0, offsetY = 0, sizeX = 0, sizeY = 0):
global lastImg
imgPath = os.path.join(os.getcwd(), 'img', str(gameResolutionWidth), fileName + str(gameResolutionWidth) + '.png')
DESIRED_IMG_CV = cv.imread(imgPath)
img = camera.grab(region=(offsetX, offsetY, sizeX, sizeY))
if(lastImg == '' or np.all(img) != None):
lastImg = img.copy()
if(np.any(img) == None):
img = lastImg.copy()
img_cv = cv.cvtColor(np.array(img), cv.COLOR_RGB2BGR)
res = cv.matchTemplate(img_cv, DESIRED_IMG_CV, method)
return (res >= confidence).any()
Pardon my code quality, I don't usually write code in python.
The output:
res = cv.matchTemplate(img_cv, DESIRED_IMG_CV, method) cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\templmatch.cpp:1175: error: (-215:Assertion failed) _img.size().height <= _templ.size().height && _img.size().width <= _templ.size().width in function 'cv::matchTemplate'
run the code,you will find the last time on the pic is earier than the print time,the delay is not stable,how can i get the exact delay?
import dxcam
import threading
import time
import cv2
global A
A = True
def pr():
while True:
if A == False:
break
print(time.time())
scr = dxcam.create()
p1 = threading.Thread(target=pr)
p1.start()
time.sleep(2)
t0 = time.time()
pic = scr.grab()
t1 = time.time()
A = False
time.sleep(0.3)
print('start_time:{},end_time:{},time gap: {}'.format(t0,t1,t1 -t0))
cv2.imwrite('speed.jpg',pic)
It said in readme.md automatic handling scaled resolution, what does it mean? Does it mean resolution like 480p
720p
is changing dynamically or what? Can you tell me detail about it.
The following code throws _ctypes.COMError:
import dxcam
# screen has 3840x2160
clip_region = (96, 176, 1793, 1050)
camera = dxcam.create()
camera.start()
for i in range(6000):
frame = camera.grab(region=clip_region)
camera.stop()
camera.release()
Traceback thrown:
Traceback (most recent call last):
File "C:\Users\user_1\AppData\Local\Programs\Python\Python310\lib\site-packages\dxcam\dxcam.py", line 176, in __captur frame = self._grab(region)
File "C:\Users\user_1\AppData\Local\Programs\Python\Python310\lib\site-packages\dxcam\dxcam.py", line 74, in _grab
if self._duplicator.update_frame():
File "C:\Users\user_1\AppData\Local\Programs\Python\Python310\lib\site-packages\dxcam\core\duplicator.py", line 37, in update_frame
raise ce
File "C:\Users\user_1\AppData\Local\Programs\Python\Python310\lib\site-packages\dxcam\core\duplicator.py", line 25, in update_frame
self.duplicator.AcquireNextFrame(
_ctypes.COMError: (-2005270527, 'The application made a call that is invalid. Either the parameters of the call or the state of some object was incorrect.\r\nEnable the D3D debug layer in order to see details via debug messages.', (None, None, None, 0, None))
Not using the region=
will not throw any errors.
dxcam.output_info():
'Device[0] Output[0]: Res:(3840, 2160) Rot:0 Primary:True\nDevice[1] Output[0]: Res:(3840, 2160) Rot:0 Primary:False\n'
dxcam.device_info():
'Device[0]:<Device Name:NVIDIA RTX A2000 Laptop GPU Dedicated VRAM:3990Mb VendorId:4318>\nDevice[1]:<Device Name:Intel(R) UHD Graphics Dedicated VRAM:128Mb VendorId:32902>\n'
dxdiag says "no problems found".
While setting screenshot image output to RGB:
cap = dxcam.create(output_idx=0, output_color="RGB")
and using opencv, I am getting error:
Given groups=1, weight of size [32, 3, 3, 3], expected input[1, 384, 640, 3] to have 3 channels, but got 384 channels instead
I am able to use BGR and convert from BGR to RGB using:
img = img[:, :, ::-1].transpose(2, 0, 1)
but switching from mss I have already saved 10ms using DXCam and without having to convert from BGR to RGB would help save alot.
i need to take a screenshot even though when there is no change in screen
dxcam seems to work faster than win32api for me but the only problem is the 'idling' feature.
it wont take a screenshot unless theres a change
so how do i get rid of it?
I switched from d3dshot to this library a few days ago. After scraping the screen for several days like this, the program keeps exiting complaining about not being able to allocate memory.
camera.start(target_fps=fps, region=region)
camera.get_latest_frame() # calling this every second
I looked at task manager and there was still 6 gb free so I don't know what could be eating up the ram. So this library might be leaking memory in kernel space related to directx or something. When python exits, the memory doesn't get freed, it will keep raising an exception at the first place that allocates a large amount of memory.
I used several other image capture packages such as mss and pillow which did not have the fps this package does (nice work), but it seems like there is a loss of image quality when using the DXcam package. I am noticing artifacts that was not present in other image capture methods, and I am wondering if it is because I am using a 4k screen.
I thought of this because I received in error when setting the region when starting the cam that said something along the lines: "area must be within 2560x1440p" which makes me think this module was designed with 1440p in mind.
Thanks!
Python 3.9.0
Wndows 10 Pro 64 bit (10.0, version 19044).
When dxcam.create(output_idx=0)
then the code works, but when dxcam.create(output_idx=1)
is black screen.
import dxcam
import time
a = 500
b = 500
print(dxcam.device_info())
print(dxcam.output_info())
cam = dxcam.create(output_idx=1)
print(cam)
time.sleep(0.1)
img = cam.grab(region=(a, b, a + 1, b + 1))
print(img)
return:
Device[0]:<Device Name:NVIDIA GeForce RTX 3070 Dedicated VRAM:8043Mb VendorId:4318>
Device[0] Output[0]: Res:(2560, 1440) Rot:0 Primary:True
Device[0] Output[1]: Res:(1080, 1920) Rot:90 Primary:False
<DXCamera:
<Device Name:NVIDIA GeForce RTX 3070 Dedicated VRAM:8043Mb VendorId:4318>,
<Output Name:\\.\DISPLAY1 Resolution:(2560, 1440) Rotation:0>,
<StageSurface Initialized:True Size:(2560, 1440) Format:DXGI_FORMAT_B8G8R8A8_UNORM>,
<Duplicator Initalized:True>
>
[[[0 0 0]]]
cam.grab()
also return black screen
Edit:
When the screen is not rotated, the code works
When we install dxcam:
pip install dxcam
We have DXCam installed, comptypes (sorry if I made a mistake) and opencv.
But this opencv does not have GPU support.
So I decided to make my build of OpenCV + CUDA .
And now I have a question how to install dxcam so that he sees my OpenCV.
I did a comparison between DXcam and d3dshot (after seeing dxcam memory usage) and while d3dshot stays at a stable ~50 MB RAM usage, DXcam uses about 750 MB.
I just ran d3dshot.create().screenshot_to_disk_every()
for d3dshot, and uses about 56MB, but dxcam.create().start()
keeps increasing in RAM usage and stops increasing at around 750MB. (Increase in RAM usage is proportional to target_fps value.). Calling get_latest_frame
or just simply time.sleep
ing doesn't affect the ram usage.
Are these values normal for DXcam?
First off, great repo, it is really coming in clutch.
I am able to typically achieve the framerate cap set ONLY if their is no movement. If I move my mouse around it causes the FPS to drop almost 50% and if I move windows around or have content moving in the background it lowers it even further (From 160 to 40ish). The performance loss only happens on movement.
Thought it may be a windows issue so I elevated the tasks run priority to realtime and their was no difference.
Thought it may be a GPU issue but still happens if games are or are not running. If the game is on a static page it will shoot up, but if there is any movement, it will drop back down again.
Not sure if this is a DXcam issue or python issue. I want to assume it's a DXcam issue internally or with the Windows API calls. It seems like the scenes are being cached which improves performance but once something changes, the cache is invalidated and the update process becomes very slow.
This is the output speed from me just moving my mouse around. I know it says CPS, but it is FPS. Code is pulled from another project and I was lazy and didn't change the output text.
CPS: 135
CPS: 136
CPS: 86
CPS: 52
CPS: 52
CPS: 129
CPS: 99
This is the code I was running. Forgive the code, it is cut out from a larger application
import time
import win32api
import dxcam
aaQuitKey = "Q"
cpsDisplay = True
count = 0
sTime = time.time()
screenshotTime = 0
imgTime = 0
modelTime = 0
formatTime = 0
region=(0, 0, 320, 320)
camera = dxcam.create(region=region)
camera.start(target_fps=160, video_mode=True)
st = time.time()
while win32api.GetAsyncKeyState(ord(aaQuitKey)) == 0:
frame = camera.get_latest_frame()
count += 1
if (time.time() - sTime) > 1:
if cpsDisplay:
print("CPS: {}".format(count))
count = 0
sTime = time.time()```
### Let me know if you need me to submit more info
dxcam.cp39-win_amd64.zip
(region shape is 640*640)
You are welcome
Hi, huge fan of the project and the absolute speed it brings to the table. I was wondering if there were any plans to add some Linux functionality. I am aware that this project is currently not intended for Linux, but I find that if this speed could be brought to Linux down the line, you can successfully put MSS out of business.
Using the following code
camera = dxcam.create(output_idx=0, output_color="GRAY")
frame = camera.grab(region=region)
creates this error
File ~\anaconda3\lib\site-packages\dxcam\processor\numpy_processor.py:54, in NumpyProcessor.process(self, rect, width, height,
region, rotation_angle)
51 image = image[:height, :, :]
53 if region[2] - region[0] != width or region[3] - region[1] != height:
---> 54 image = image[region[1] : region[3], region[0] : region[2], :]
56 return image
IndexError: too many indices for array: array is 2-dimensional, but 3 were indexed
This is because when using "GRAY" option, the output image is only in 2 dimension not 3. I was able to fix the issue by changing line 54 into the following try block.
try:
image = image[region[1] : region[3], region[0] : region[2], :]
except:
image = image[region[1] : region[3], region[0] : region[2]]
While this solves the issue, I think it would be faster if an 'if color_mode == "GRAY" ' statement is used instead of try/except block. However, I am very new to python/coding and am unsure how to pass color_mode argument into def process().
If anyone could teach me how to do that, I would appreciate it.
Hello, i've been trying to use this library but i am getting the following error:
_ctypes.COMError: (-2005270524, 'The specified device interface or feature level is not supported on this system.', (None, None, None, 0, None))
Traceback (most recent call last):
File "C:\Users\hamza\OneDrive\Documents\GitHub\obj-det\main_tensorrt_gpu.py", line 204, in <module>
main()
File "C:\Users\hamza\OneDrive\Documents\GitHub\obj-det\main_tensorrt_gpu.py", line 74, in main
camera = dxcam.create(region=region)
File "C:\Users\hamza\AppData\Roaming\Python\Python310\site-packages\dxcam\__init__.py", line 112, in create
return __factory.create(
File "C:\Users\hamza\AppData\Roaming\Python\Python310\site-packages\dxcam\__init__.py", line 71, in create
camera = DXCamera(
File "C:\Users\hamza\AppData\Roaming\Python\Python310\site-packages\dxcam\dxcam.py", line 33, in __init__
self._duplicator: Duplicator = Duplicator(
File "<string>", line 6, in __init__
File "C:\Users\hamza\AppData\Roaming\Python\Python310\site-packages\dxcam\core\duplicator.py", line 20, in __post_init__
output.output.DuplicateOutput(device.device, ctypes.byref(self.duplicator))
_ctypes.COMError: (-2005270524, 'The specified device interface or feature level is not supported on this system.', (None, None, None, 0, None))
Exception ignored in: <function DXCamera.__del__ at 0x000001E667B139A0>
Traceback (most recent call last):
File "C:\Users\hamza\AppData\Roaming\Python\Python310\site-packages\dxcam\dxcam.py", line 243, in __del__
self.release()
File "C:\Users\hamza\AppData\Roaming\Python\Python310\site-packages\dxcam\dxcam.py", line 238, in release
self.stop()
File "C:\Users\hamza\AppData\Roaming\Python\Python310\site-packages\dxcam\dxcam.py", line 138, in stop
if self.is_capturing:
AttributeError: 'DXCamera' object has no attribute 'is_capturing'
I've seen a similar issue here: #18 but it was closed?
I think it might be because i am on windows 11 so it might be some directx issue?
here is a dxdiag dump
---------------
Display Devices
---------------
Card name: AMD Radeon(TM) Graphics
Manufacturer: Advanced Micro Devices, Inc.
Chip type: AMD Radeon Graphics Processor (0x1638)
DAC type: Internal DAC(400MHz)
Device Type: Full Device (POST)
Device Key: Enum\PCI\VEN_1002&DEV_1638&SUBSYS_10FC1043&REV_C6
Device Status: 0180200A [DN_DRIVER_LOADED|DN_STARTED|DN_DISABLEABLE|DN_NT_ENUMERATOR|DN_NT_DRIVER]
Device Problem Code: No Problem
Driver Problem Code: Unknown
Display Memory: 8384 MB
Dedicated Memory: 496 MB
Shared Memory: 7888 MB
Current Mode: 1920 x 1080 (32 bit) (144Hz)
HDR Support: Not Supported
Display Topology: Internal
Display Color Space: DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709
Color Primaries: Red(0.639648,0.330078), Green(0.299805,0.599609), Blue(0.149414,0.059570), White Point(0.312500,0.329102)
Display Luminance: Min Luminance = 0.500000, Max Luminance = 270.000000, MaxFullFrameLuminance = 270.000000
Monitor Name: Generic PnP Monitor
Monitor Model: unknown
Monitor Id: AUO8294
Native Mode: 1920 x 1080(p) (144.028Hz)
Output Type: Internal
Monitor Capabilities: HDR Not Supported
Display Pixel Format: DISPLAYCONFIG_PIXELFORMAT_32BPP
Advanced Color: Not Supported
Driver Name: C:\WINDOWS\System32\DriverStore\FileRepository\u0376545.inf_amd64_87c724e1cb953643\B376543\aticfx64.dll,C:\WINDOWS\System32\DriverStore\FileRepository\u0376545.inf_amd64_87c724e1cb953643\B376543\aticfx64.dll,C:\WINDOWS\System32\DriverStore\FileRepository\u0376545.inf_amd64_87c724e1cb953643\B376543\aticfx64.dll,C:\WINDOWS\System32\DriverStore\FileRepository\u0376545.inf_amd64_87c724e1cb953643\B376543\amdxc64.dll
Driver File Version: 30.00.13002.15001 (English)
Driver Version: 30.0.13002.15001
DDI Version: 12
Feature Levels: 12_1,12_0,11_1,11_0,10_1,10_0,9_3,9_2,9_1
Driver Model: WDDM 3.0
Hardware Scheduling: DriverSupportState:AlwaysOff Enabled:False
Graphics Preemption: DMA
Compute Preemption: DMA
Miracast: Not Supported by Graphics driver
Detachable GPU: No
Hybrid Graphics GPU: Integrated
Power P-states: Not Supported
Virtualization: Paravirtualization
Block List: DISABLE_HWSCH
Catalog Attributes: Universal:False Declarative:True
Driver Attributes: Final Retail
Driver Date/Size: 2/9/2022 3:00:00 AM, 1838752 bytes
WHQL Logo'd: Yes
WHQL Date Stamp: Unknown
Device Identifier: {D7B71EE2-5578-11CF-6A49-360269C2D335}
Vendor ID: 0x1002
Device ID: 0x1638
SubSys ID: 0x10FC1043
Revision ID: 0x00C6
Driver Strong Name: oem32.inf:cb0ae4147b406b52:ati2mtag_Cezanne:30.0.13002.15001:PCI\VEN_1002&DEV_1638&SUBSYS_10FC1043&REV_C6
Rank Of Driver: 00CF0000
Video Accel: Unknown
DXVA2 Modes: DXVA2_ModeMPEG2_VLD {86695F12-340E-4F04-9FD3-9253DD327460} DXVA2_ModeH264_VLD_NoFGT {4245F676-2BBC-4166-A0BB-54E7B849C380} {6719B6FB-5CAD-4ACB-B00A-F3BFDEC38727} {9901CCD3-CA12-4B7E-867A-E2223D9255C3} DXVA2_ModeHEVC_VLD_Main {EA72396A-67EC-4781-BEDE-56F498F04EF2} {C152CA8F-738C-461B-AD89-FC292CF8F162} {514A356C-7027-4AFF-8A60-AFD2C1F672F1} DXVA2_ModeH264_VLD_Stereo_Progressive_NoFGT DXVA2_ModeH264_VLD_Stereo_NoFGT DXVA2_ModeVC1_VLD {CA15D19A-2B48-43D6-979E-7A6E9C802FF8} {D1C20509-AE7B-4E72-AE3B-49F88D58992F} {84AD67F6-4C21-419A-9F0B-24F0578906C1} {725AD240-786C-471E-AD3C-38F739936517} {95664FF5-9E03-4C74-BB4F-9178D6035E58} {5EF7D40D-5B96-49E7-B419-23342094A4CF} DXVA2_ModeHEVC_VLD_Main10 {65D1FA41-58AF-453A-9CAB-5D981156DA9F} {2DB154B6-DBB2-4079-A3FF-60D7A898A6AB} {C74A3FD0-D713-4581-A02E-8EDFB112ACE3} DXVA2_ModeVP9_VLD_Profile0 DXVA2_ModeVP9_VLD_10bit_Profile2 {603A4756-A864-4F91-BB62-2C935B7A1391} {C58B9A06-7E89-11E1-BB00-70B34824019B}
Deinterlace Caps: n/a
D3D9 Overlay: Not Supported
DXVA-HD: Not Supported
DDraw Status: Enabled
D3D Status: Enabled
AGP Status: Enabled
MPO MaxPlanes: 2
MPO Caps: ROTATION,VERTICAL_FLIP,HORIZONTAL_FLIP,YUV,BILINEAR,STRETCH_YUV,HDR (MPO3)
MPO Stretch: 16.000X - 0.250X
MPO Media Hints: rotation, resizing, colorspace Conversion
MPO Formats: NV12,420_OPAQUE,R16G16B16A16_FLOAT,R10G10B10A2_UNORM,R8G8B8A8_UNORM,B8G8R8A8_UNORM
PanelFitter Caps: ROTATION,VERTICAL_FLIP,HORIZONTAL_FLIP,YUV,BILINEAR,STRETCH_YUV,HDR (MPO3)
PanelFitter Stretch: 16.000X - 0.250X
Component Drivers:
Driver Name: Unknown
Driver Version: Unknown
Driver Date: Unknown
Driver Provider: Unknown
Catalog Attributes: N/A
Card name: NVIDIA GeForce RTX 3050 Ti Laptop GPU
Manufacturer: NVIDIA
Chip type: NVIDIA GeForce RTX 3050 Ti Laptop GPU
DAC type: Integrated RAMDAC
Device Type: Full Device
Device Key: Enum\PCI\VEN_10DE&DEV_25A0&SUBSYS_10FC1043&REV_A1
Device Status: 0180600A [DN_DRIVER_LOADED|DN_STARTED|DN_DISABLEABLE|DN_REMOVABLE|DN_NT_ENUMERATOR|DN_NT_DRIVER]
Device Problem Code: No Problem
Driver Problem Code: Unknown
Display Memory: 11864 MB
Dedicated Memory: 3976 MB
Shared Memory: 7888 MB
Current Mode: Unknown
HDR Support: Unknown
Display Topology: Unknown
Display Color Space: Unknown
Color Primaries: Unknown
Display Luminance: Unknown
Driver Name: C:\WINDOWS\System32\DriverStore\FileRepository\nvami.inf_amd64_57378df08e27c128\nvldumdx.dll,C:\WINDOWS\System32\DriverStore\FileRepository\nvami.inf_amd64_57378df08e27c128\nvldumdx.dll,C:\WINDOWS\System32\DriverStore\FileRepository\nvami.inf_amd64_57378df08e27c128\nvldumdx.dll,C:\WINDOWS\System32\DriverStore\FileRepository\nvami.inf_amd64_57378df08e27c128\nvldumdx.dll
Driver File Version: 31.00.0015.2647 (English)
Driver Version: 31.0.15.2647
DDI Version: 12
Feature Levels: 12_2,12_1,12_0,11_1,11_0,10_1,10_0,9_3,9_2,9_1
Driver Model: WDDM 3.0
Hardware Scheduling: DriverSupportState:Stable Enabled:True
Graphics Preemption: Pixel
Compute Preemption: Dispatch
Miracast: Not Supported by Graphics driver
Detachable GPU: No
Hybrid Graphics GPU: Discrete
Power P-states: Not Supported
Virtualization: Paravirtualization
Block List: No Blocks
Catalog Attributes: Universal:False Declarative:True
Driver Attributes: Final Retail
Driver Date/Size: 10/25/2022 3:00:00 AM, 772488 bytes
WHQL Logo'd: Yes
WHQL Date Stamp: Unknown
Device Identifier: Unknown
Vendor ID: 0x10DE
Device ID: 0x25A0
SubSys ID: 0x10FC1043
Revision ID: 0x00A1
Driver Strong Name: oem110.inf:0f066de3172354d9:Section192:31.0.15.2647:pci\ven_10de&dev_25a0&subsys_10fc1043
Rank Of Driver: 00CF0001
Video Accel: Unknown
DXVA2 Modes: {86695F12-340E-4F04-9FD3-9253DD327460} DXVA2_ModeMPEG2_VLD {6F3EC719-3735-42CC-8063-65CC3CB36616} DXVA2_ModeVC1_D2010 DXVA2_ModeVC1_VLD {32FCFE3F-DE46-4A49-861B-AC71110649D5} DXVA2_ModeH264_VLD_Stereo_Progressive_NoFGT DXVA2_ModeH264_VLD_Stereo_NoFGT DXVA2_ModeH264_VLD_NoFGT DXVA2_ModeHEVC_VLD_Main DXVA2_ModeHEVC_VLD_Main10 {20BB8B0A-97AA-4571-8E99-64E60606C1A6} {15DF9B21-06C4-47F1-841E-A67C97D7F312} DXVA2_ModeMPEG4pt2_VLD_Simple DXVA2_ModeMPEG4pt2_VLD_AdvSimple_NoGMC {9947EC6F-689B-11DC-A320-0019DBBC4184} {33FCFE41-DE46-4A49-861B-AC71110649D5} DXVA2_ModeVP9_VLD_Profile0 DXVA2_ModeVP9_VLD_10bit_Profile2 {DDA19DC7-93B5-49F5-A9B3-2BDA28A2CE6E} {B8BE4CCB-CF53-46BA-8D59-D6B8A6DA5D2A} {6AFFD11E-1D96-42B1-A215-93A31F09A53D} {914C84A3-4078-4FA9-984C-E2F262CB5C9C} {8A1A1031-29BC-46D0-A007-E9B092CA6767}
Deinterlace Caps: n/a
D3D9 Overlay: Unknown
DXVA-HD: Unknown
DDraw Status: Enabled
D3D Status: Enabled
AGP Status: Enabled
MPO MaxPlanes: 0
MPO Caps: Not Supported
MPO Stretch: Not Supported
MPO Media Hints: Not Supported
MPO Formats: Not Supported
PanelFitter Caps: Not Supported
PanelFitter Stretch: Not Supported
Traceback (most recent call last):
File "C:\Users\user\Downloads\Euro-Truck-Simulator-2-Lane-Assist-main\MainFile.py", line 49, in
import ets2LaneDetection as LaneDetection
File "C:\Users\user\Downloads\Euro-Truck-Simulator-2-Lane-Assist-main\ets2LaneDetection.py", line 123, in
camera = dxcam.create(region=monitor, output_color="BGR")
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\dxcam_init_.py", line 112, in create
return _factory.create(
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\dxcam_init.py", line 71, in create
camera = DXCamera(
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\dxcam\dxcam.py", line 33, in init
self._duplicator: Duplicator = Duplicator(
File "", line 6, in init
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\dxcam\core\duplicator.py", line 19, in post_init
output.output.DuplicateOutput(device.device, ctypes.byref(self.duplicator))
_ctypes.COMError: (-2005270524, 'Zadané rozhraní zařízení nebo úroveň funkce nejsou v systému podporovány.', (None, None, None, 0, None))
Exception ignored in: <function DXCamera.del at 0x000001DD0F7EE670>
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\dxcam\dxcam.py", line 243, in del
self.release()
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\dxcam\dxcam.py", line 238, in release
self.stop()
File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\dxcam\dxcam.py", line 138, in stop
if self.is_capturing:
AttributeError: 'DXCamera' object has no attribute 'is_capturing'
Hi @ra1nty, I'm working on integrating this library finally. 🍻
But I found that hardcoding opencv-python
as dependency is a very bad idea, since there are several ways to install opencv
such as from PyPi, APT, compile form source etc. And moreover there are several version of same binary such as opencv-python-headless
, opencv-contrib-python
etc. on pypi itself. So having multiple version of same library on your system will definitely break it, since installing opencv-python
won't check existence of other OpenCV libs.
Make opencv-python
optional by moving it from install_requires
to extras_require
and provide it under naming such as cv2
such that people can install it using pip install dxcam[cv2]
command when they know they don't already have OpenCV libs already installed.
Note: Make sure cv2
is not imported globally but withing a class (or more appropriately its method), so that it won't throw error directly when importing dxcam
but only when specific class or functionality is imported.
I want to send a frame by text so I could send it over the network
Any ideas for how I could make this a shere screen would be nicely accepted
I am using Win32's window handles to take screenshots almost 10 times faster than dxcam, does dxcam support window handles?
So, it was mentioned in the features that this library was able to capture screenshots of fullscreen applications, even when alt+tabbed from said applications. How would one get around to achieve this? Can't see it as an extra device, nor as an extra output, and digging around the code yielded nothing.
Some help would be greatly appreciated
Hello im trying to get screenshot but i get this error
My code looks like this:
import dxcam
camera = dxcam.create()
frame = camera.grab()
Im using python 3.8.0 32bit (don't know if it matters)
Traceback (most recent call last):
File "d:/Pulpit/Moje strony internetowe/python/keydrop/test2.py", line 1, in <module>
import dxcam
File "C:\Python\Python38-32\lib\site-packages\dxcam\__init__.py", line 100, in <module>
__factory = DXFactory()
File "C:\Python\Python38-32\lib\site-packages\dxcam\__init__.py", line 14, in __call__
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
File "C:\Python\Python38-32\lib\site-packages\dxcam\__init__.py", line 26, in __init__
p_adapters = enum_dxgi_adapters()
File "C:\Python\Python38-32\lib\site-packages\dxcam\util\io.py", line 24, in enum_dxgi_adapters
create_dxgi_factory(IDXGIFactory1._iid_, ctypes.byref(pfactory))
OSError: exception: access violation writing 0x4DBAF26F
region = (635, 1225, 1340, 210)
camera = dxcam.create()
frame = camera.grab()
camera.start(target_fps=60, region=region)
image = camera.get_latest_frame()
Problem: ValueError: Invalid Region: Region should be in 2560x1440
I get an error when trying to use dxcam on python 3.11. It does not appear on python 3.10 or python 3.9.
Im using latest version of numpy which supports python 3.11.
Any ideas on how to fix this, i will be willing to put effort to attempt to fix it myself(If dev is not available) i just need to know where to start.
Desktop Specs:
AMD Ryzen 7 5700x
32GB DDR4
NVIDA RTX 3060ti
Great work!
Any plans to release DXcam on pypi index too? Testpypi index cannot be used inside a python project.
In the README section listed below its speaks about idling. Is there a way to allow idling so that screenshot still take place even without change?
It is worth noting that .grab will return None if there is no new frame since the last time you called .grab. Usually it means there's nothing new to render since last time (E.g. You are idling).
I have been able to get around the problem of screenshots not being taken with the below code. But was wondering if there was a built in method not mention in the README?
while "Forever" == "Forever":
try:
if screenshot.size != "Anything":
break
except:
screenshot = camera.grab(region=[0, 0, 1920, 1080])
print("Screenshot Error - Rataking")
For some reason doesn't this code work.
`camera = dxcam.create()
frame = camera.grab()
Image.fromarray(frame).show()`
It returns a black picture. Have tried device_idx=0, output_idx=0
, without success, since I use two screens.
I'm using windows 10 and getting this error? Any solutions?
AttributeError: 'DXCamera' object has no attribute 'is_capturing'
Should also work when it is minimized like OBS studio.
Relevant parts of implementation.
https://github.com/obsproject/obs-studio/blob/master/plugins/win-capture/window-capture.c#L563
https://github.com/obsproject/obs-studio/blob/master/plugins/win-capture/dc-capture.c#L158
Thank you for this library. it helps me a lot
can u please support cursor rendering ?
Thanks again
Like #49 , but my OS is windows7 and python version is 3.8.16
Traceback info:
Exception ignored in: <function DXCamera.__del__ at 0x00000000121BDDC0>
Traceback (most recent call last):
File "E:\Python\DXcam\dxcam\dxcam.py", line 243, in __del__
self.release()
File "E:\Python\DXcam\dxcam\dxcam.py", line 238, in release
self.stop()
File "E:\Python\DXcam\dxcam\dxcam.py", line 138, in stop
if self.is_capturing:
AttributeError: 'DXCamera' object has no attribute 'is_capturing'
I have download the new version source code from github and install with pip install --editable .
, no help with the problem
Hi,
I tried to install DXcam using command provided in the description: pip install -i https://test.pypi.org/simple/ dxcam
but it throws this error:
PS C:\Users\Administrator\PycharmProjects\dxcam> pip install -i https://test.pypi.org/simple/ dxcam
>>
Looking in indexes: https://test.pypi.org/simple/, https://pypi.ngc.nvidia.com
Collecting dxcam
Downloading https://test-files.pythonhosted.org/packages/9e/d6/c47112d04c49175beb00bf54e4db71fe41d4f1533b0e202bdd8534ad5320/dxcam-0.0.3-py3-none-any.whl (9.5 kB)
Collecting numpy
Downloading https://test-files.pythonhosted.org/packages/d5/80/b947c574d9732e39db59203f9aa35cb4d9a5dd8a0ea2328acb89cf10d6e3/numpy-1.9.3.zip (4.5 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.5/4.5 MB 16.8 MB/s eta 0:00:00
Preparing metadata (setup.py) ... done
Collecting dxcam
Downloading https://test-files.pythonhosted.org/packages/a2/0a/5a1130ee405a08b4cb28f80393ce9dc4d85e6db7475e80b8f8663efd7154/dxcam-0.0.2-py3-none-any.whl (9.3 kB)
ERROR: Cannot install dxcam==0.0.2 and dxcam==0.0.3 because these package versions have conflicting dependencies.
The conflict is caused by:
dxcam 0.0.3 depends on comtypes
dxcam 0.0.2 depends on comtypes
To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
To fix it, I tried to install dependencies manually first using this command:
pip install opencv-python numpy comtypes
it returned:
Successfully installed comtypes-1.1.11 numpy-1.21.6 opencv-python-4.5.5.64
Then I typed:
pip install -i https://test.pypi.org/simple/ dxcam==0.0.3
PS C:\Users\Administrator\PycharmProjects\dxcam> pip install -i https://test.pypi.org/simple/ dxcam==0.0.3
Looking in indexes: https://test.pypi.org/simple/, https://pypi.ngc.nvidia.com
Collecting dxcam==0.0.3
Downloading https://test-files.pythonhosted.org/packages/9e/d6/c47112d04c49175beb00bf54e4db71fe41d4f1533b0e202bdd8534ad5320/dxcam-0.0.3-py3-none-any.whl (9.5 kB)
Requirement already satisfied: comtypes in c:\users\administrator\pycharmprojects\dxcam\venv\lib\site-packages (from dxcam==0.0.3) (1.1.11)
Requirement already satisfied: opencv-python in c:\users\administrator\pycharmprojects\dxcam\venv\lib\site-packages (from dxcam==0.0.3) (4.5.5.64)
Requirement already satisfied: numpy in c:\users\administrator\pycharmprojects\dxcam\venv\lib\site-packages (from dxcam==0.0.3) (1.21.6)
Installing collected packages: dxcam
Successfully installed dxcam-0.0.3
Output of following command says it installed successfully, but when I try to run the following code:
import dxcam
camera = dxcam.create()
camera.grab()
I get this:
C:\Users\Administrator\PycharmProjects\dxcam\venv\Scripts\python.exe C:/Users/Administrator/PycharmProjects/dxcam/test.py
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/dxcam/test.py", line 1, in <module>
import dxcam
File "C:\Users\Administrator\PycharmProjects\dxcam\venv\lib\site-packages\dxcam\__init__.py", line 2, in <module>
from dxcam.dxcam import DXCamera, Output, Device
File "C:\Users\Administrator\PycharmProjects\dxcam\venv\lib\site-packages\dxcam\dxcam.py", line 7, in <module>
from dxcam.core import Device, Output, StageSurface, Duplicator
ModuleNotFoundError: No module named 'dxcam.core'
I Tried to git-clone folder (dxcam) into venv/lib/dxcam/ but it didn't help. Now I get:
C:\Users\Administrator\PycharmProjects\dxcam\venv\Scripts\python.exe C:/Users/Administrator/PycharmProjects/dxcam/test.py
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/dxcam/test.py", line 1, in <module>
import dxcam
File "C:\Users\Administrator\PycharmProjects\dxcam\venv\lib\site-packages\dxcam\__init__.py", line 2, in <module>
from dxcam.dxcam import DXCamera, Output, Device
File "C:\Users\Administrator\PycharmProjects\dxcam\venv\lib\site-packages\dxcam\dxcam\__init__.py", line 2, in <module>
from dxcam.dxcam import DXCamera, Output, Device
ImportError: cannot import name 'DXCamera' from 'dxcam.dxcam' (C:\Users\Administrator\PycharmProjects\dxcam\venv\lib\site-packages\dxcam\dxcam\__init__.py)
Process finished with exit code 1
Btw. I tried it on Arch Linux (py3.9) and Windows 10 (using py3.7 and 3.9).
dxcam.device_info() : Device[0]:<Device Name:Intel(R) UHD Graphics 630 Dedicated VRAM:128Mb VendorId:32902> there is a problem ,it is not my NVIDIA 1050
dxcam.output_info() : Device[0] Output[0]: Res:(1920, 1080) Rot:0 Primary:True
Windows10 and python 3.8.13
When trying to install dxcam through pip it gives the error below
ERROR: Could not find a version that satisfies the requirement dxcam (from versions: none)
ERROR: No matching distribution found for dxcam
I'm on python version 3.6.7 and upgraded my pip as well.
I have tried many things however creating the camera for the screenshots is giving back errors.
I am on windows 11
Python 3.10.4
Traceback (most recent call last): File "c:\Users\PyPit\OneDrive\Documents\CODE\Valorant arduino\scripts\main.py", line 65, in <module> camera = dxcam.create() File "C:\Users\PyPit\AppData\Local\Programs\Python\Python310\lib\site-packages\dxcam\__init__.py", line 110, in create return __factory.create( File "C:\Users\PyPit\AppData\Local\Programs\Python\Python310\lib\site-packages\dxcam\__init__.py", line 70, in create camera = DXCamera( File "C:\Users\PyPit\AppData\Local\Programs\Python\Python310\lib\site-packages\dxcam\dxcam.py", line 33, in __init__ self._duplicator: Duplicator = Duplicator( File "<string>", line 6, in __init__ File "C:\Users\PyPit\AppData\Local\Programs\Python\Python310\lib\site-packages\dxcam\core\duplicator.py", line 19, in __post_init__ output.output.DuplicateOutput(device.device, ctypes.byref(self.duplicator)) _ctypes.COMError: (-2005270524, 'The specified device interface or feature level is not supported on this system.', (None, None, None, 0, None)) Exception ignored in: <function DXCamera.__del__ at 0x00000254DCCF60E0> Traceback (most recent call last): File "C:\Users\PyPit\AppData\Local\Programs\Python\Python310\lib\site-packages\dxcam\dxcam.py", line 243, in __del__ self.release() File "C:\Users\PyPit\AppData\Local\Programs\Python\Python310\lib\site-packages\dxcam\dxcam.py", line 238, in release self.stop() File "C:\Users\PyPit\AppData\Local\Programs\Python\Python310\lib\site-packages\dxcam\dxcam.py", line 138, in stop if self.is_capturing: AttributeError: 'DXCamera' object has no attribute 'is_capturing'
I run a simple code:
`import time
import dxcam
import utils.window as wnd
from threading import Thread
window = dxcam.create()
def read_window_frame(window, region=(0, 0, 967, 1047)):
image_rgb = None
while image_rgb is None:
image_rgb = window.grab(region=region)
return image_rgb
def reading():
time.sleep(1)
while True:
wnd.read_window_frame(window)
print("reading frame 2")
time.sleep(0.1)
t = Thread(target=reading)
t.start()
while True:
wnd.read_window_frame(window)
print("reading frame 1")
time.sleep(0.1)
`
it outputs:
reading frame 1
* same ... *
reading frame 1
Traceback (most recent call last):
File "G:\PycharmProjects\sky2fly-bot\test.py", line 29, in <module>
reading frame 2
wnd.read_window_frame(window)
File "G:\PycharmProjects\sky2fly-bot\utils\window.py", line 20, in read_window_frame
image_rgb = window.grab(region=region)
File "G:\PycharmProjects\sky2fly-bot\venv\lib\site-packages\dxcam\dxcam.py", line 70, in grab
frame = self._grab(region)
File "G:\PycharmProjects\sky2fly-bot\venv\lib\site-packages\dxcam\dxcam.py", line 81, in _grab
rect = self._stagesurf.map()
File "G:\PycharmProjects\sky2fly-bot\venv\lib\site-packages\dxcam\core\stagesurf.py", line 52, in map
self.texture.QueryInterface(IDXGISurface).Map(ctypes.byref(rect), 1)
_ctypes.COMError: (-2147024882, 'Недостаточно ресурсов памяти для завершения операции.', (None, None, None, 0, None))
reading frame 2
* same ... *
reading frame 2
If I run this code multiple times I get error in different parts of my code (because of using threads). How can I run the same dxcam object without getting this error?
Exception ignored in: <function compointer_base.del at 0x000001CAA34379C0>
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\comtypes_init.py", line 956, in del
self.Release()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\comtypes_init_.py", line 1211, in Release
return self._com_Release()
^^^^^^^^^^^^^^^^^^^^
OSError: exception: access violation reading 0xFFFFFFFFFFFFFFFF
Exception ignored in: <function compointer_base.del at 0x000001CAA34379C0>
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\comtypes_init.py", line 956, in del
self.Release()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\comtypes_init.py", line 1211, in Release
return self.__com_Release()
^^^^^^^^^^^^^^^^^^^^
OSError: exception: access violation reading 0xFFFFFFFFFFFFFFFF
`cv2.error: OpenCV(4.7.0) 👎 error: (-5:Bad argument) in function 'imshow'
Overload resolution failed:
- mat data type = 17 is not supported
- Expected Ptrcv::cuda::GpuMat for argument 'mat'
- Expected Ptrcv::UMat 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)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.