FindStr(self, x1, y1, x2, y2, string_, color_format, sim)

在屏幕范围(x1,y1,x2,y2)内,查找 string(可以是任意个字符串的组合),并返回符合 color_format 的坐标位置,相似度 sim 同 Ocr 接口描述.(多色,差色查找类似于 Ocr 接口,不再重述)

Parameters:

  • x1 (int) – 区域的左上 X 坐标
  • y1 (int) – :区域的左上 Y 坐标
  • x2 (int) – 区域的右下 X 坐标
  • y2 (int) – 区域的右下 Y 坐标
  • string_ (str) – 待查找的字符串,可以是字符串组合,比如"长安|洛阳|大雁塔",中间用"|"来分割字符串
  • color_format (str) – 颜色格式串, 可以包含换行分隔符,语法是","后加分割字符串. 具体可以查看下面的示例 .注意,RGB 和 HSV 格式都支持
  • sim (float) – 双精度浮点数:相似度,取值范围 0.1-1.0

Returns:

  • tuple – (x1,y1,x2,y2,string_,color_format,sim,返回 X 坐标没找到返回-1,返回 Y 坐标没找到返回-1)

示例:

op_ret = op.FindStr(0,0,2000,2000,"长安","9f2e3f-000000",1.0,intX,intY)
If intX >= 0 and intY >= 0 Then
     op.MoveTo intX,intY
End If

op_ret = op.FindStr(0,0,2000,2000,"长安|洛阳","9f2e3f-000000",1.0,intX,intY)
If intX >= 0 and intY >= 0 Then
     op.MoveTo intX,intY
End If

// 查找时,对多行文本进行换行,换行分隔符是"|". 语法是在","后增加换行字符串.任意字符串都可以.
op_ret = op.FindStr(0,0,2000,2000,"长安|洛阳","9f2e3f-000000,|",1.0,intX,intY)
If intX >= 0 and intY >= 0 Then
     op.MoveTo intX,intY
End If
注: 此函数的原理是先Ocr识别,然后再查找。

FindStrEx(self, x1, y1, x2, y2, string_, color_format, sim)

在屏幕范围(x1,y1,x2,y2)内,查找 string(可以是任意个字符串的组合),并返回符合 color_format 的坐标位置,相似度 sim 同 Ocr 接口描述.(多色,差色查找类似于 Ocr 接口,不再重述)

Parameters:

  • x1 (int) – 区域的左上 X 坐标
  • y1 (int) – :区域的左上 Y 坐标
  • x2 (int) – 区域的右下 X 坐标
  • y2 (int) – 区域的右下 Y 坐标
  • string_ (str) – 待查找的字符串,可以是字符串组合,比如"长安|洛阳|大雁塔",中间用"|"来分割字符串
  • color_format (str) – 颜色格式串, 可以包含换行分隔符,语法是","后加分割字符串. 具体可以查看下面的示例 .注意,RGB 和 HSV 格式都支持
  • sim (float) – 双精度浮点数:相似度,取值范围 0.1-1.0

Returns:

  • 返回所有找到的坐标集合,格式如下 – "id,x0,y0|id,x1,y1|......|id,xn,yn" 比如"0,100,20|2,30,40" 表示找到了两个,第一个,对应的是序号为 0 的字符串,坐标是(100,20),第二个是序号为 2 的字符串,坐标(30,40)

示例:

op_ret = op.FindStrEx(0,0,2000,2000,"长安|洛阳","9f2e3f-000000",1.0)
If len(op_ret) > 0 Then
   ss = split(op_ret,"|")
   index = 0
   count = UBound(ss) + 1
   Do While index < count
      TracePrint ss(index)
      sss = split(ss(index),",")
      id = int(sss(0))
      x = int(sss(1))
      y = int(sss(2))
      op.MoveTo x,y
      Delay 1000
      index = index+1
   Loop
End If
注: 此函数的原理是先Ocr识别,然后再查找。

Ocr(self, x1, y1, x2, y2, color_format, sim)

识别屏幕范围(x1,y1,x2,y2)内符合 color_format 的字符串,并且相似度为 sim,sim 取值范围(0.1-1.0),这个值越大越精确,越大速度越快,越小速度越慢,请斟酌使用!

Parameters:

  • x1 (int) – 区域的左上 X 坐标
  • y1 (int) – 区域的左上 Y 坐标
  • x2 (int) – 区域的右下 X 坐标
  • y2 (int) – 区域的右下 Y 坐标
  • color_format (str) – 区域的右下 Y 坐标
  • sim (float) – 双精度浮点数:相似度,取值范围 0.1-1.0

Returns:

  • str – 返回识别到的字符串

示例:

//RGB单色识别
s = op.Ocr(0,0,2000,2000,"9f2e3f-000000",1.0)
MessageBox s

//RGB单色差色识别
s = op.Ocr(0,0,2000,2000,"9f2e3f-030303",1.0)
MessageBox s

//RGB多色识别(最多支持10种,每种颜色用"|"分割)
s = op.Ocr(0,0,2000,2000,"9f2e3f-030303|2d3f2f-000000|3f9e4d-100000",1.0)
MessageBox s

OcrEx(self, x1, y1, x2, y2, color_format, sim)

识别屏幕范围(x1,y1,x2,y2)内符合 color_format 的字符串,并且相似度为 sim,sim 取值范围(0.1-1.0),这个值越大越精确,越大速度越快,越小速度越慢,请斟酌使用!这个函数可以返回识别到的字符串,以及每个字符的坐标.

Parameters:

  • x1 (int) – 区域的左上 X 坐标
  • y1 (int) – 区域的左上 Y 坐标
  • x2 (int) – 区域的右下 X 坐标
  • y2 (int) – 区域的右下 Y 坐标
  • color_format (str) – 区域的右下 Y 坐标
  • sim (float) – 双精度浮点数:相似度,取值范围 0.1-1.0

Returns:

  • str – 返回识别到的字符串 格式如 "字符 0$x0$y0|…|字符 n$xn$yn"

SetDict(self, index, file)

设置字库文件

Parameters:

  • index (int) – 字库的序号,取值为 0-19,目前最多支持 20 个字库
  • file (str) – 字库文件名

Returns:

  • int – 0 代表失败 1 代表成功

UseDict(self, index)

表示使用哪个字库文件进行识别(index 范围:0-9)设置之后,永久生效,除非再次设定

Parameters:

  • index (int) – 字库编号(0-9)

Returns:

  • int – 0 代表失败 1 代表成功

OcrAuto(self, x1, y1, x2, y2, sim)

识别屏幕范围(x1,y1,x2,y2)内的字符串,自动二值化,而无需指定颜色,适用于字体颜色和背景相差较大的场合

Parameters:

  • x1 (int) – 区域的左上 X 坐标
  • y1 (int) – 区域的左上 Y 坐标
  • x2 (int) – 区域的右下 X 坐标
  • y2 (int) – 区域的右下 Y 坐标
  • sim (float) – 相似度,取值范围 0.1-1.0

Returns:

  • str – 返回识别到的字符串

OcrFromFile(self, file_name, color_format, sim)

Parameters:

  • file_name (str) – 文件名
  • color_format (str) – 颜色格式串
  • sim (float) – 相似度,取值范围 0.1-1.0

Returns:

  • str – 返回识别到的字符串

OcrAutoFromFile(self, file_name, sim)

Parameters:

  • file_name (str) – 文件名
  • sim (float) – 相似度,取值范围 0.1-1.0

Returns:

  • str – 返回识别到的字符串

Built with MkDocs using a theme provided by Read the Docs.