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

Why only primary screen is supported? #14

Open
skazichris opened this issue Nov 29, 2019 · 8 comments
Open

Why only primary screen is supported? #14

skazichris opened this issue Nov 29, 2019 · 8 comments

Comments

@skazichris
Copy link

Why only primary screen is supported?

@drov0
Copy link
Owner

drov0 commented Nov 29, 2019

If I remember well, this is a limitation from opencv. But I might wrong, I'm open to PR's if you want to add this feature :)

@skazichris
Copy link
Author

Actually I have 4 screens. I was really enthusiastic when I found your imagesearch class, but then... it does not work on multi screen.

There might be some workarounds according to this:
https://stackoverflow.com/questions/43015077/how-to-display-different-windows-in-different-monitors-with-opencv?noredirect=1&lq=1
and this:
https://stackoverflow.com/questions/24540091/opencv-fullscreen-windows-on-multiple-monitors

@drov0
Copy link
Owner

drov0 commented Jan 4, 2020

Mmmh actually I just ran a test and multiple screens are supported on linux at least. which os are you using ?

@skazichris
Copy link
Author

skazichris commented Jan 5, 2020 via email

@drov0
Copy link
Owner

drov0 commented Jan 5, 2020

Can you try to do an image search while uncommenting the im.save in the imagesearch function see how the captured area is ? It should be all of your screens.


def imagesearch(image, precision=0.8):
    im = pyautogui.screenshot()
    if is_retina:
        im.thumbnail((round(im.size[0] * 0.5), round(im.size[1] * 0.5)))
    im.save('testarea.png') # useful for debugging purposes, this will save the captured region as "testarea.png"
    img_rgb = np.array(im)
    img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
    template = cv2.imread(image, 0)
    template.shape[::-1]

    res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
    min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
    if max_val < precision:
        return [-1, -1]
    return max_loc

@martinnaj
Copy link

martinnaj commented Apr 10, 2020

Hi, I tried the above but it doesn't work, just returns [-1, -1]

Edit: the screenshot only contains the primary montor

@martinnaj
Copy link

The issue actually lies within pyautogui:
asweigart/pyautogui#9

Solution:
asweigart/pyautogui#9 (comment)

@martinnaj
Copy link

martinnaj commented Apr 10, 2020

Here is my solution

Install the following:

``` pip install desktopmagic pip install pywin32 ```

Add the following to the start of imagesearch.py

from __future__ import print_function

Add the following after import subprocess in imagesearch.py

from desktopmagic.screengrab_win32 import getScreenAsImage

Now, change the imagesearch function to:

def imagesearch(image, precision=0.8):
    im = getScreenAsImage()
    if is_retina:
        im.thumbnail((round(im.size[0] * 0.5), round(im.size[1] * 0.5)))
    #im.save('testarea.png') # useful for debugging purposes, this will save the captured region as "testarea.png"
    img_rgb = np.array(im)
    img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
    template = cv2.imread(image, cv2.IMREAD_COLOR)
    template.shape[::-1]
    res = cv2.matchTemplate(img_rgb, template, cv2.TM_CCOEFF_NORMED)
    min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
    if max_val < precision:
        return [-1, -1]
    return max_loc

You can now find images on other monitors

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

3 participants