电脑控制手机 Python实现颜色识别功能

用电脑控制手机好几年了,Total Control作为安卓手机的多控系统,是我用过各方面都比较稳定的一款软件了。通过脚本实现识别颜色是其强大功能之一,之前分享了多点颜色比较的脚本示例,今天来说说如何用Total Control 提供的REST API 实现多点比较颜色,支持多色,颜色范围,相似度比较颜色。

电脑控制手机 Python实现颜色识别功能_第1张图片

 

Total Control 提供的REST API:

电脑控制手机 Python实现颜色识别功能_第2张图片

 

请求参数:

电脑控制手机 Python实现颜色识别功能_第3张图片

 

请求示例:

http://localhost:8090/TotalControl/v1/devices/device@1116106541/screen/colors/color?token=270eq7lXQK8bXYsJ&color=[[3,5,"0x000000"], [4,6,"0x000f00"], [9,225,"0xffffff"]]&sim=0.3

响应示例:

{

"value":"",

"status":true

}

电脑控制手机 Python实现颜色识别功能

 

Python示例:

#!/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/colors/color"

data = {

"color": "[[200,500,'0xffffff|0xaabbcc-0x000000'], [200,400,'0x000f00'], [200,225,'0xffffff']]",

"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.")

运行结果:

Get the token,Return value: {'status': True, 'value': {'token': 'lo7ssQ12KgkM6ik7'}}

The value of token is: lo7ssQ12KgkM6ik7

Get the device id,Return value: {'id': 'device@33254183'}

The value of device id is: device@33254183

Executed successfully,Return value: {'status': True, 'value': ''}

要怎样拥有Total Control呢?官网直接下载就可以了,专业版还提供免费试用哦,快点下载一个试试吧!

电脑控制手机 Python实现颜色识别功能_第4张图片

你可能感兴趣的:(电脑控制手机 Python实现颜色识别功能)