简体   繁体   English

不能在 pycharm venv 中使用 opencv-python

[英]Can't use opencv-python in pycharm venv

I'm trying to find a specific image using PyAutoGUI and it works just fine but I can't seem to be able to use 'confidence', 'grayscale' or other OpenCV provided keywords with it.我正在尝试使用 PyAutoGUI 查找特定图像,它工作得很好,但我似乎无法使用“信心”、“灰度”或其他 OpenCV 提供的关键字。 I've tried reimporting the package/library but it still doesn't work.我已经尝试重新导入包/库,但它仍然不起作用。 Any idea what could cause this?知道是什么原因造成的吗?

import pygetwindow as gw
import pyautogui as ag
import cv2

lol = gw.getWindowsWithTitle('League Of Legends')[0]
r = 0
while True:
    try:
        while r == 0:
            if lol.isActive:
                print("lol is active")
                ag.locateOnScreen('findmatch.png', confidence=.9)
                ag.click('findmatch.png')
        break
    except:
        r = 1
        print("Image not found")
    break

图片

I cannot post a comment because of low reputation.由于声誉低,我无法发表评论。 Why do you think you are unable to use those keywords?为什么您认为您无法使用这些关键字? It is possible that findmatch.png was generated on a different display. findmatch.png 可能是在不同的显示器上生成的。 In that case, locateOnScreen will not be able to find the image even when you decrease the confidence because the sizes of the template (findmatch.png) and the portion of the screen you are trying to locate do not match.在这种情况下,即使您降低置信度,locateOnScreen 也无法找到图像,因为模板 (findmatch.png) 的大小与您尝试定位的屏幕部分不匹配。 You will need multiscale template matching if that is the problem.如果这是问题,您将需要多尺度模板匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM