0

I'm trying to write some code to use screencaptures to export the position from a online-go.server. I only got a few lines in, when I got this error from this code

error

c:\Go\sgo>py ogs2kgs.py
top left position :  220 149
bottom right position :  719 650
Dimensions: (46, 47) Total pixels: 2162
Traceback (most recent call last):
  File "c:\Go\sgo\ogs2kgs.py", line 24, in <module>
    pos = imagesearcharea("BlackStone.png", x, y, 30, 30)
  File "C:\Python39\lib\site-packages\python_imagesearch\imagesearch.py", line 60, in imagesearcharea
    im = region_grabber(region=(x1, y1, x2, y2))
  File "C:\Python39\lib\site-packages\python_imagesearch\imagesearch.py", line 36, in region_grabber
    return sct.grab(region)
  File "C:\Python39\lib\site-packages\mss\base.py", line 90, in grab
    screenshot = self._grab_impl(monitor)
  File "C:\Python39\lib\site-packages\mss\windows.py", line 252, in _grab_impl
    raise ScreenShotError("gdi32.GetDIBits() failed.")
mss.exception.ScreenShotError: gdi32.GetDIBits() failed.

c:\Go\sgo>py ogs2kgs.py
top left position :  220 149
bottom right position :  719 650
Dimensions: (46, 47) Total pixels: 2162
0

code

from python_imagesearch.imagesearch import *
from PIL import Image
import os

top_left = imagesearch("top_left.png")
if top_left[0] != -1:
    print("top left position : ", top_left[0], top_left[1])
else:
    print("image not found")

bottom_right = imagesearch("bottom_right.png")
if bottom_right[0] != -1:
    print("bottom right position : ", bottom_right[0], bottom_right[1])
else:
    print("image not found")

img = Image.open("bottom_right.PNG")
width, height = img.size
print("Dimensions:", img.size, "Total pixels:", width * height)

stones = 0
for x in range(top_left[0],bottom_right[0]+30,30):
    for y in range(top_left[1],bottom_right[1]+30,30):
        try:
            pos = imagesearcharea("BlackStone.png", x, y, 30, 30)
            if pos != -1:
                print(pos)
                stones = stones + 1
        except:pass
print(stones)

What's that all about? Any ideas ...

SlightlyKosumi
  • 701
  • 2
  • 8
  • 24

0 Answers0