因此,我试图基于两次单击(即左上角和右下角)来获取图像,但是当我将ImgGrab函数的宽度和高度赋予我与原始值不同的值时,该如何解决呢?
我认为,当我将显示器的左上角设置为(0,0)时,我会得到正确的值,但是在其他任何地方,我都会得到错误的值。
// FILE * fp; // not needed
if (fgets(str, 1000, stdin)) {
// Success
}
我希望img变量的值与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()