Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Win7上的Python:匹配来自两台不同PC的屏幕截图?_Python_Windows_Screenshot_Pillow - Fatal编程技术网

Win7上的Python:匹配来自两台不同PC的屏幕截图?

Win7上的Python:匹配来自两台不同PC的屏幕截图?,python,windows,screenshot,pillow,Python,Windows,Screenshot,Pillow,我使用桌面魔术 使用以下代码使用python拍摄50px×50px的小屏幕快照: from desktopmagic.screengrab_win32 import ( getDisplayRects, saveScreenToBmp, saveRectToBmp, getScreenAsImage, getRectAsImage, getDisplaysAsImages) def snap_shot(left_offset, top_offset, width, height

我使用桌面魔术 使用以下代码使用python拍摄50px×50px的小屏幕快照:

from desktopmagic.screengrab_win32 import (
    getDisplayRects, saveScreenToBmp, saveRectToBmp, getScreenAsImage,
    getRectAsImage, getDisplaysAsImages)

def snap_shot(left_offset, top_offset, width, height, file_name):
    right=left_offset+width
    bottom=top_offset+height

    saveRectToBmp(file_name, rect=(left_offset, top_offset, right, bottom))
我还使用枕头将截图与参考图像进行比较

from PIL import Image

def compare_images(f1,f2):
    h1 = Image.open(f1).histogram()
    h2 = Image.open(f2).histogram()

    rms = math.sqrt(functools.reduce(operator.add,map(lambda a,b: (a-b)**2, h1, h2))/len(h1))

    return rms
在我尝试将代码和参考图像迁移到新电脑之前,一切都很顺利。 对于人眼来说,在PC1和PC2上拍摄的屏幕截图之间没有区别,但是我的compare_images函数看到了区别

当在PC1上拍摄的参考图像和PC2的屏幕截图之间寻找精确匹配时,测试失败

那么…两台Windows计算机需要什么才能完全相同地呈现桌面窗口呢? 我假设如果它们是相同的硬件,屏幕截图将100%匹配。但关键因素是什么?两个人拥有相同的显卡就足够了吗?你认为哪些因素会起作用


提前感谢

如果不是系列,两台不同的机器可能有不同的操作系统版本及其GUI元素窗口边框、窗口图标、窗口顶框着色模式、桌面动机、光标图标、墙纸图像/瓷砖/比例因子等

如果所有相同/相同设置的颜色深度设置不同,则产生的像素值彼此不匹配。这种情况可以用最简单的方法检查-只需比较BMP文件的调色板内容的32位颜色深度与f1和f2文件中减少的16位颜色深度