1 Star 0 Fork 0

tlq-github/TFT_assistant

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
hash1.py 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
TLQ 提交于 1年前 . 第一次提交
from PIL import ImageGrab
import hashlib
import time
def capture_and_hash_screen(x1=100, y1=100, x2=1000, y2=500, num_slices=5, slice_offset=10):
start = time.time()
screenshot = ImageGrab.grab(bbox=(x1, y1, x2, y2))
# 二值化图片
binary_image = screenshot.convert("L").point(lambda p: 0 if p < 150 else 255)
binary_image.show()
# 获取大截图的宽度和高度
screenshot_width, screenshot_height = screenshot.size
# 计算小图片的宽度(除以 num_slices 后再减去 slice_offset)
small_image_width = (screenshot_width // num_slices) - slice_offset
# 切割图片并计算哈希值
hashes = []
for i in range(num_slices):
left = i * (small_image_width + slice_offset)
right = left + small_image_width
small_image = binary_image.crop((left, 0, right, screenshot_height))
small_image.show()
image_byte_array = small_image.tobytes()
md5_hash = hashlib.md5(image_byte_array).hexdigest()
hashes.append(md5_hash)
print('截图并处理hash消耗了:%s 的时间' % (time.time() - start))
return hashes
if __name__ == "__main__":
captured_hashes = capture_and_hash_screen()
for i, hash_val in enumerate(captured_hashes, start=1):
print(f"Hash {i}: {hash_val}")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tlq-github/TFT_assistant.git
git@gitee.com:tlq-github/TFT_assistant.git
tlq-github
TFT_assistant
TFT_assistant
master

搜索帮助