如何使用Python/Tkinter读取特定的显示屏区域?

huangapple go评论78阅读模式
英文:

How to read out a certain display screen area using Python/Tkinter?

问题

假设您正在使用专有程序从摄像机获取到计算机的实时视频数据,该程序将一张1024x1024像素的视频显示在屏幕上。是否可能使用Python/Tkinter编写一个小型GUI程序,其中包含一个可调整大小的窗口,该窗口具有一个透明区域,该区域可以“捕获”放置在其上的背景?

假设您没有直接访问摄像机,我认为这个问题可以归结为以下两个问题:1.) 如何使用Python读取由GPU提供的视频数据,并针对特定屏幕区域进行操作;2.) 是否可以通过透明的Tkinter窗口动态调整读取区域。

一旦弄清楚如何从GPU获取特定屏幕区域,我可能可以解决第2个问题。

请注意,我不想每隔50毫秒拍摄一张屏幕截图,而是真正获取特定显示区域的GPU流,以系统设置的刷新率为准。然后,该流应存储到循环RAM缓冲区以进行实时图像分析。

英文:

Suppose that you are getting a live feed from a camera to your computer using a proprietary program, which is displaying e.g. a 1024x1024 pixel video to your screen. Would it be possible to write a small GUI program using Python/Tkinter, featuring a resizable window with a transparent area which "grabs" the background of whatever the transparent area is placed on top?

Assuming that you don't have direct access to the camera, I suppose this questions comes down to 1.) how one can read the video data provided by your GPU to a certain screen area using Python and 2.) if it is possible to dynamically adjust the readout area via a transparent Tkinter window.

I can probably figure out 2.), once it is clear how to grab a certain screen area from the GPU.

Note that I do not want to take a screenshot every 50 ms or so, but really get the GPU stream for a specific display area, at whatever system refresh rate is set. The stream should then be stored into a circular RAM buffer for live image analysis.

答案1

得分: 1

虽然这似乎并没有直接回答问题,但 PillowImageGrab 类提供了屏幕截图功能,并提供定义感兴趣区域的选项:

https://www.simplifiedpython.net/python-screenshot/

然而,它基本上是根据命令进行屏幕截图,而不是利用 GPU 的实际视频流。

英文:

While this does not seem to answer the exact question, pillow's ImageGrabclass provides a screen capturing functionality with the option to define a region of interest:

https://www.simplifiedpython.net/python-screenshot/

However, it basically takes screenshots on command rather than tapping into the actual video stream of the GPU.

huangapple
  • 本文由 发表于 2023年6月2日 00:40:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76384039.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定