python-3.x - 在 ImgGrab 中没有得到正确的宽度和高度
问题描述
因此,我试图通过两次单击(左上角和右下角)来获取图像,但是当我将宽度和高度赋予 ImgGrab 函数时,我会收到与原始值不同的值,我该如何解决?
我认为,当我将显示器的左上角设置为 (0, 0) 时,我得到了正确的值,但在任何其他地方我得到了错误的值。
def get_pos():
input('Place the mouse on the top left corner of your game screen and
press enter ')
topleft = mouse.position
input('Do the same, but in the lower right corner')
lowerright = mouse.position
print('to start/stop running the program press "M", to exit the
program press "ESC"')
ref = (lowerright[0] - topleft[0], lowerright[1] - topleft[1])
pos_click = [(ref[0]*0.83 + topleft[0], ref[1]*0.37 + topleft[1]),
(ref[0]*0.42 + topleft[0], ref[1]*0.45 + topleft[1]),
(ref[0]*0.84 + topleft[0], ref[1]*0.79 + topleft[1]),
(ref[0]*0.50 + topleft[0], ref[1]*0.75 + topleft[1]),
(topleft), (ref)]
return pos_click
pos_click = get_pos()
img = ImageGrab.grab(bbox=(pos_click[4][0], pos_click[4][1], pos_click[5]
[0],
pos_click[5][1])) #x, y, w, h
img_np = np.array(img)
print('tamanho de img',img, 'tamanho ref', pos_click[5])
frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2RGB)
cv2.imshow("frame", frame)
cv2.waitKey(0)
cv2.destroyAllWindows()
我希望 img 变量的值与pos_click[5]
解决方案
推荐阅读
- node.js - 错误:{“invalid_client”} 在 Nodejs 中使用 Apple 登录
- python - 当类别中只有一行时,category_encoders.TargetEncoder 的奇怪输出(python)
- continuous-integration - 坚持为两个存储库配置 GitHub Actions
- keycloak - JBPM 中不向用户显示人工任务(使用 Keycloak 适配器)
- sql - 如何使用两个表正确生成日期列序列?
- python - 不在 API 中的数据的 Django GET 请求结果
- docker - 在自定义桥接网络中访问具有名称的容器
- firebase - Firebase 关系实体
- math - 乘以 256 有什么作用
- fossil - 使用 Fossil SCM 提供静态文件