Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble with imagesearcharea when region x2 and y2 is less than double the size of x1 and y1? #43

Open
vil17 opened this issue Apr 20, 2021 · 3 comments

Comments

@vil17
Copy link

vil17 commented Apr 20, 2021

I've got this program with a for loop which runs through a list.
However when I put the x1 and y1 cords in at non-zero I start getting problems.

I threw together a gui where I input the region to grab, but as soon as I put in x1 and y1 as something non-zero I start getting issues, different issues depending on values.

400, 400, 400, 400 gives me:
...Programs\Python\Python39\lib\site-packages\mss\windows.py", line 285, in _grab_impl
raise ScreenShotError("gdi32.GetDIBits() failed.")
mss.exception.ScreenShotError: gdi32.GetDIBits() failed.

200, 200, 400, 400 gives me
...Programs\Python\Python39\lib\site-packages\python_imagesearch\imagesearch.py", line 73, in imagesearcharea
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
cv2.error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-wvn_it83\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

Exception: Line: 0 Callable failed || error occured in a callback

if I put in something like 200, 200, 500, 500 it does run but it doesn't seem to find the images.

def findPicOpt3(sender, data):
    t = Timer(name="random stuff")
    t.start()
    confidence = get_value("inputint4")
    print("searching with confidence level", confidence)
    # im = region_grabber((confidence[0], confidence[1], confidence[2], confidence[3]))
    for num, name in enumerate(imagelist.testImages):
        pos = imagesearcharea(
            imagelist.testImages[num],
            confidence[0],
            confidence[1],
            confidence[2],
            confidence[3],
            #    im,
        )
        if pos[0] != -1:
            print("Found", imagelist.testNames[num], "at", pos)
        else:
            print("image not found")
    t.stop()

I wonder if it has to do with the fact that when I try to debug using im.save it tells me screenshot has no attribute called save:
python_imagesearch\imagesearch.py", line 70, in imagesearcharea
im.save(
AttributeError: 'ScreenShot' object has no attribute 'save'
Exception: Line: 0 Callable failed || error occured in a callback

Might I be missing a package or an import? If so I haven't been able to spot which and what
I've seen this being reported when people have their path wrong, but it works with regular imagesearch and makes an absolute path

I have triple monitor 1920x1080 setup (one vertical) but I tried disconnecting two of them and this was still a problem.
I'm on windows.

is this a bug or should I just give up programming and become a truck driver?

edit: btw lets say I want to grap the middle 800x800 region on a (theoretical) monitor of 1200x1200, I assume I should put in 200, 200, 1000,1000? or 200,200,800,800?.. ive tried both anyway, both don't seem to work.. it's like the region_grabber is accepting widthxheight, and something else is working on topx, topy, bottomx, bottomy? is this possible?

@Scruffydrew
Copy link

you managed to figure anything out??? i've been having the same issue

@vincenthavinh
Copy link

vincenthavinh commented Dec 17, 2021

Could you give the version of imagesearch you are using ?

I got a similar error sometime ago. A bug in region_grabber() function : #45
And this function is used in imagesearcharea(), so the bug comes from there.

This bug is present in version 1.2.0 and has been patched in version 1.2.1
But version 1.2.1 has difficulties to autoinstall via pip, I don't really understand why ... see this error : #42

So a workaround is to install manually 1.2.1 as explained here, or just to patch region_grabber() function in local package code, as it is done in file python_imagesearch/imagesearch.py in patch 1.2.1

Please do note that reinstalling via pip may wipe those local changes and the problem may reappear.
Hopefully one day we'll just be able to get 1.2.1 by pip install.

@MarKhan54
Copy link

MarKhan54 commented Apr 9, 2023

However when I put the x1 and y1 cords in at non-zero I start getting problems.

Well, that is half of the answer. The other part is "once program grabs a portion of image, where does it place it on axis?" and the answer is at 0,0, so at the moment imagesearcharea returns coordinates relative to the passed region, which is probably not how it supposed to work (absolute coordinates are expected), and it is really easy to fix, just add x1 and y1 to the result that imagesearcharea returns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants