简体   繁体   English

PIL imagegrab().grab().crop(...) 作物不是给定的坐标

[英]PIL imagegrab().grab().crop(...) crops not the given coordinates

I´m creating a canvas on which I draw a number.我正在创建一个 canvas,我在上面画了一个数字。 Then I make a screenshot via the Pillow package and crop it in a way, only the drawn number remains.然后我通过 Pillow package 截屏并以某种方式裁剪它,只剩下绘制的数字。 (Purpose is to predict the drawn number via a CNN) When cropping the screenshot done by the Pillow function imagegrab().grab().crop(...) not the given coordinates in the.crop() are being used. (目的是通过 CNN 预测绘制的数字)当裁剪由 Pillow function imagegrab().grab().crop(...) 完成的屏幕截图时,正在使用的不是 the.crop() 中的给定坐标。 For testing purposes, I tried to manually choose the part of the screenshot which should be cropped by giving crop() some coordinates.出于测试目的,我尝试通过给 crop() 一些坐标来手动选择应该裁剪的屏幕截图部分。 When doing so, it works if I choose the upper left corner, but gets more skewed and skewed when I move the part-to-be-cropped more to the right or lower.这样做时,如果我选择左上角,它会起作用,但是当我将要裁剪的部分向右或向下移动更多时,它会变得更加倾斜和倾斜。 In the attached Image you can see an example of the cropping performed by the attached code where only a part of the canvas to be cropped had been cropped, additionally with some background在所附图像中,您可以看到由所附代码执行的裁剪示例,其中仅裁剪了要裁剪的 canvas 的一部分,另外还有一些背景

Code to crop a part of the canvas-widget from the screenshot:从屏幕截图中裁剪部分画布小部件的代码:

def get_drawing():
    widget = cv
    x = root.winfo_rootx() + widget.winfo_x()
    y = root.winfo_rooty() + widget.winfo_y()
    x1 = x + widget.winfo_width()
    y1 = y + widget.winfo_height()

    ImageGrab.grab().crop((x, y, x1, y1)).save("test.png")

I just found the answer to my own question: The issue laid in the monitor I chose to display my canvas.我刚刚找到了我自己问题的答案:问题在于我选择显示我的 canvas 的显示器。 I´m working with a Microsoft Surface attached to a docking station with an external monitor.我正在使用连接到带有外接显示器的扩展坞的 Microsoft Surface。 When I change the display settings to only use the external monitor, the cropping works with the code above as intended.当我将显示设置更改为仅使用外接显示器时,裁剪可以按预期使用上面的代码。 When I use my Surface and extend the display with the external monitor, the cropping gets skewed as shown in the screenshot.当我使用我的 Surface 并通过外接显示器扩展显示时,裁剪会出现倾斜,如屏幕截图所示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PIL的.crop返回图像0x0。 指定bbox的ImageGrab.grab也是如此 - PIL's .crop returns image 0x0. So does ImageGrab.grab with specified bbox 线程中的 PIL.ImageGrab、grab() 和 load() 函数 - PIL.ImageGrab , grab() and load() functions in thread 如何使用 Python PIL 裁剪给定比例坐标的图像? - How to crop an image given proportional coordinates with Python PIL? 捕获屏幕有比PIL.ImageGrab.grab()更好的方法吗? - Is there any better way to capture the screen than PIL.ImageGrab.grab()? 有什么办法可以让 PIL 的 ImageGrab.grab() 保存小尺寸的照片? - Is there any way to make PIL's ImageGrab.grab() save photos with a small size? 屏幕截图(PIL)Win10上的ImageGrab.grab / BitBlt仅返回背景吗? - Screenshot (PIL)ImageGrab.grab / BitBlt on Win10 only return the Background? 为什么特定窗口的 PIL.ImageGrab.grab 无法正常工作? - Why does PIL.ImageGrab.grab of specific window doesn't work properly? 如何从 Python 中的 PIL.ImageGrab.grab() 获取实际像素颜色值? - How to get actual Pixel Color value from PIL.ImageGrab.grab() in Python? ImageGrab.grab() 的时序 function - Timing of ImageGrab.grab() function 给定要裁剪的四个角的坐标,如何裁剪图像 - How do I crop an image given the coordinates of the four corners to crop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM