seekImage: Seek image
Function Description:
Find the specified picture in the full screen or in the specified area of the screen, support similar looking for pictures. If the target image is found, it returns the center coordinates of the found image.
Corresponding JS API:
seekImage(imageName)
seekImage(imageName, sim)
seekImage(imageName, sim)
seekImage(topLeftX, topLeftY, bottomRightX, bottomRightY, imageName)
seekImage(topLeftX, topLeftY, bottomRightX, bottomRightY, imageName, sim)
seekImage(topLeftX, topLeftY, bottomRightX, bottomRightY, imageName, sim, beGray)
seekImage(imageName, sim, beGray)
Whether to support multiple devices:
Yes
Resource Information:
Method | GET |
---|---|
URL | .../devices/:device/screen/images?name=:name&rect=:rect&same=:same&sim=:sim |
Requires authentication? | Yes |
Method Parameters:
Parameter | Type | Required | Description |
---|---|---|---|
device | String | Yes | ID value of the device |
name | String | Yes | Picture path |
sim | Float | No | Similarity, the similarity range is [0.0, 1.0] |
rect | String | No | Coordinate value, the coordinate format is "[topLeftX, topLeftY, bottomRightX, bottomRightY]". topLeftX: X coordinate of the upper left corner of the screen topLeftY: Y coordinate of the upper left corner of the screen bottomRightX: X coordinate of the lower right corner of the screen bottomRightY: Y coordinate of the lower left corner of the screen |
same | String | No | When this value is true, it means that the thumbnail and the large image to be searched are taken from the same mobile phone, so there is no need to zoom the image and no similarity search when looking for the image. |
beGray | String | No | When this value is true (the default is true), it means that the image should be grayscaled first, then look for the image. When this value is false, it means that the picture is not processed before the picture is found. It is faster to first grayscale the image and then find it. It can be used after Total Control 6.8.0. |
Response Parameters:
A JSON string representing an array of objects with the following fields:
Field | Type | Description |
---|---|---|
status | Boolean | Return true for success and null for failure |
value | Array/String | Array, if the value of status is true,it returns the coordinates of the center point of the found image; String, if the value of status is a null object, an error message or empty string is returned. |
Request Example:
http://localhost:8090/TotalControl/v1/devices/device@1116106541/screen/images?token=270eq7lXQK8bXYsJ&name=C:/Users/S/Desktop/360.bmp
http://localhost:8090/TotalControl/v1/devices/device@1116106541/screen/images?token=270eq7lXQK8bXYsJ&name=C:/Users/S/Desktop/360.bmp&sim=0.1
http://localhost:8090/TotalControl/v1/devices/device@1116106541/screen/images?token=270eq7lXQK8bXYsJ&name=C:/Users/S/Desktop/360.bmp&rect=[0,0,600,600]
http://localhost:8090/TotalControl/v1/devices/device@1116106541/screen/images?token=270eq7lXQK8bXYsJ&name=C:/Users/S/Desktop/360.bmp&rect=[0,0,600,600]&sim=0.5
http://localhost:8090/TotalControl/v1/devices/device@1116106541/screen/images?token=270eq7lXQK8bXYsJ&name=C:/Users/S/Desktop/360.bmp&rect=[0,0,600,600]&same=true&sim=0.5
http://localhost:8090/TotalControl/v1/devices/device@1116106541/screen/images?token=270eq7lXQK8bXYsJ&name=C:/Users/S/Desktop/360.bmp&same=true&sim=0.5
Response Example:
If this API executes successfully, it returns:
{
"status": true,
"value": [272,371]
}
If the value of HTTP status code is 200, but the value of status is a null object, it returns:
{
"status": null,
"value": "<Error message>"
}
Example:
Warm tip:
Get the token needed for Total Control script development,see here.
Get the id value of the master device, see here.
RingoJS Example:
// Import the packages
var {request} = require("ringo/httpclient");
var base64 = require("ringo/base64");
// The username and password are separated by a single : and sent on the wire base64 encoded
var userpass = base64.encode("sigma:3D391497");
// First step: Get the API token
var gettoken = request({
method: "GET",
url: "http://localhost:8090/TotalControl/v1/login",
headers: {
"Authorization": userpass
}
});
var ret_token = JSON.parse(gettoken.content);
var token = ret_token.value.token;
print("//The value of token is:" + token);
// Second step: Get the device id value of the master device
var getdevice = request({
method: "GET",
url: "http://localhost:8090/TotalControl/v1/devices/main?token=" + token
});
var device = JSON.parse(getdevice.content).id;
print("//The value of device ID is:"+ device);
// Third step: Execute this REST API
var resp = request({
method: "GET",
url: "http://localhost:8090/TotalControl/v1/devices/" + device + "/screen/images",
data: {
"name": "E:/File/img/image1080.bmp",
"rect": "[0,0,700,900]",
"same": true,
"beGray": true,
"sim": 0.8,
"token": token
}
});
var obj = JSON.parse(resp.content);
var ret = obj.status;
if (ret == true) {
print("//Executed successfully,Return value: \n"+resp.content);
} else if (ret != true & resp.status == 200){
print("An error message is returned: "+resp.content);
} else {
print("This API failed to execute.");
}
The running result of the RingoJS:
If it executes successfully, it will return:
//The value of token is:39D3DX3sRfak7Dls
//The value of device ID is:device@33254183
//Executed successfully,Return value:
{"value":[620,520],"status":true}
Python Example:
#!/user/bin/python
#-*- coding:utf-8 -*-
import base64
import requests
# The username and password are separated by a single : and sent on the wire base64 encoded
user_pass = 'sigma:3D391497'
encodeStr = base64.b64encode(user_pass.encode("UTF-8"))
# First step: Get the API token
LoginUrl = "http://localhost:8090/TotalControl/v1/login"
response = requests.get(LoginUrl, headers={'Authorization':encodeStr})
print("Get the token,Return value: ",response.json())
token = response.json()['value']['token']
print("The value of token is: ",token)
# Second step: Get the device id value of the master device
if token is not None:
GetDeviceUrl = "http://localhost:8090/TotalControl/v1/devices/main?token=" + token
response = requests.get(url=GetDeviceUrl)
print("Get the device id,Return value: ", response.json())
device = response.json()['id']
print("The value of device id is: ", device)
if device is not None:
# Third step: Execute this REST API
APIUrl = "http://localhost:8090/TotalControl/v1/devices/" + device + "/screen/images"
data = {
"name": "E:/File/img/image1080.bmp",
"rect": "[0,0,700,900]",
"same": True,
"beGray": True,
"sim": 0.8,
"token": token
}
response = requests.get(url=APIUrl, params=data)
ret = response.json()['status']
# Determine if this REST API is executed successfully
if ret is True:
print("Executed successfully,Return value: ", response.json())
elif response.status_code == 200 and ret is not True:
print("An error message is returned: ",response.json())
else:
print("This API failed to execute.")
else:
print("Failed to get device id.")
else:
print("Failed to get token.")
The running result of the python:
If it executes successfully, it will return:
Get the token,Return value: {'status': True, 'value': {'token': '236NY20EUZF0cYQr'}}
The value of token is: 236NY20EUZF0cYQr
Get the device id,Return value: {'id': 'device@33254183'}
The value of device id is: device@33254183
Executed successfully,Return value: {'value': [94, 520], 'status': True}