zoukankan      html  css  js  c++  java
  • MonkeyImage模块功能详解

    ●MonkeyImage模块

    图像处理相关的模块,主要是对截屏生成的图像进行一些操作。主要包括:

    ●MonkeyImage官方详细介绍

    newimage = MonkeyDevice.takeSnapshot()

    MonkeyImage是通过MonkeyDevice模块的takeSnapshot()方法来生成屏幕截图,然后生成MonkeyImage对象。

    ●MonkeyImage的方法

    •convertToBytes //将当前图像转换为字节码

    •getRawPixel //获取指定坐标位置的像素点,返回值(a,r,g,b)

    •getRawPixelInt //把上面的像素数组以整形返回出来

    •getSubImage //从MonkeyImage中获取子图像

    •sameAs //比较两个MonkeyImage对象的相似度

    •writeToFile //将图像写到文件中生成图片文件,一般是png

    ●代码演示

    monkeyrunner

    form com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage

    device=MonkeyRunner.waitForConnection()//获取MonkeyDevice对象

    image=device.takeSnapshot() //通过MonkeyDevice对象的takeSnapshot获取屏幕截图

    image.convertToBytes()

    image.getRawPixel(100,100)

    image.getRawPixelInt(100,100)

    接下来打开uiautomatorviewer获取计算器上数字6的坐标

    subimage=image.getSubImage((543,895,267,293))                         

    subimage.writeToFile('6.png','png')

    tools目录下就能看到6.png图片

    接下来获取计算器上数字9

    subimage2 = image.getSubImage((543,602,267,293))

    subimage2.writeToFile('9.png','png')

    tools目录下就能看到9.png图片

    接下来比较6.png和9.png两个子对象

    subimage.sameAs(subimage2, 0.9) //0.9表示相似度

    ture就表示两个图片相似

  • 相关阅读:
    3.这个月有几天?
    3.这个月有几天?
    3.这个月有几天?
    2.求一个整数有几位(简单字符串操作)
    Algs4-1.2.1编写一个Point2D的用例-分治法
    Algs4-1.2.1编写一个Point2D的用例
    Algs4-1.1.39随机匹配
    Algs4-1.1.38二分查找与暴力查找
    Algs4-1.1.37糟糕的打乱
    Algs4-1.1.36乱序检查
  • 原文地址:https://www.cnblogs.com/ljf-hero/p/6632843.html
Copyright © 2011-2022 走看看