如何将图像与机器人fram进行比较

2024-09-30 00:23:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我是机器人框架新手,尝试比较两个图像。我做了一些研究和开发,发现有一个现有的robotappees库可以帮助比较图像。在

链接1:http://navinet.github.io/Robot-AppEyes/RobotAppEyes-KeywordDocumentation.html#Compare%20Image

链接2:https://github.com/NaviNet/Robot-AppEyes

我使用同一个库来比较图像,但在比较两个图像时面临以下问题。在

** Settings ***
Library                 Selenium2Library
Library                 RobotAppEyes

*** Test Cases ***
RobotAppEyes 1.0 Test
    Open Browser    http://www.google.com.uk    gc      
    Maximize Browser Window     
    Open Eyes Session   http://www.google.com.uk    RobotAppEyes_Test   NaviNet_RobotAppEyes_Test1  JkaJK50dp1NTEhPufx08SaztsXmfBZas8z0MZVcaqcA110  
    # ${isOpen}=    Eyes Session Is Open                    
    # Log    ${isOpen}
    Compare Image        C:\\Users\\Downloads\\logo.png       C:\\Users\\user\\Downloads\\logo.png     ignore_mismatch=False    includeEyesLog=False     httpDebugLog=False
    Check Eyes Region   .//*[@id='splash']/div[1]       500     120     logo
    Run Keyword If  ${isOpen}==True Close Eyes Session
    Close Eyes Session

执行机器人脚本后的响应:

^{pr2}$

有谁能帮我比较一下机器人的图像吗?在


Tags: test图像githubcomfalsehttp链接session
2条回答

能够使用image Magic解决此问题

Compare Images
    [Arguments]      ${Reference_Image_Path}    ${Test_Image_Path}    ${Allowed_Threshold}
    ${TEMP}=         Replace String     ${IMAGE_COMPARATOR_COMMAND}    __REFERENCE__     ${Reference_Image_Path}
    ${COMMAND}=      Replace String     ${TEMP}    __TEST__     ${Test_Image_Path}
    Log              ${Allowed_Threshold}
    Log              Executing: ${COMMAND}
    ${RC}            ${OUTPUT}=     Run And Return Rc And Output    ${COMMAND}
    # ${RC}            ${OUTPUT}=     Run And Return Rc And Output    C:/"Program Files"/ImageMagick-7.0.7-Q16/convert.exe    C:/Users/user/imagecompare/Test/src/reference-screenshots/reference-1.png    C:/Users/user/imagecompare/Test/src/reference-screenshots/reference-11.png -metric RMSE -compare -format "%[distortion]" info:
    Log              Return Code: ${RC}
    Log              Return Output: ${OUTPUT}
    ${RESULT}        Evaluate    ${OUTPUT} < ${Allowed_Threshold}
    Should be True   ${RESULT}

https://blog.codecentric.de/en/2017/09/robot-framework-compare-images-screenshots/

这是我在评论中讨论后的回答。这不是迪帕克问题的完美答案,我意识到这一点,但他让我把它贴出来。在

 from robot.libraries.BuiltIn import BuiltIn
    import pyautogui as pag

class click_by_image(object):
    def __init__(self):
        self.selenium_lib = None

    def click_by_image(self, image_name):
        """
        Click the center of a rectangle on the screen given the
        image_name of the image rectangle to search for
        :param image_name: Path to image
        """
        #   If ExtendedSelenium2Library instance is undefined
        if self.selenium_lib is None:
            # Instantiate ExtendedSelenium2Library
            self.selenium_lib = BuiltIn().get_library_instance('ExtendedSelenium2Library')
        pag.click(pag.locateCenterOnScreen(str(image_name)))

这是它来自的完整关键字。对于小图片来说,它很滑(大约20px x~40px是它有问题的地方,尽管我还没有精确地测量过),但是如果屏幕上有精确的像素集,它对大图片的效果非常好。这是屏幕上的任何地方,而不仅仅是在DOM中,所以这是我用来在选项卡之间单击并与普通桌面交互的工具。在

若要使用此关键字,请将图片的本地副本作为绝对路径或相对路径馈送到click_by_image(),这两种路径都可以,并且它将按照文档的形式工作。在

我提到的具体代码是pag.locateCenterOnScreen(),它来自pyautogui。它返回一组坐标,所以如果你没有得到这些坐标,那么你的图像就不会出现在屏幕上。如果你这样做了,那么你知道a)你的形象存在,b)它在哪里。在

相关问题 更多 >

    热门问题