python颜色识别原理_电脑控制手机 Python实现颜色识别功能
原標題:電腦控制手機 Python實現(xiàn)顏色識別功能
用電腦控制手機好幾年了,Total Control作為安卓手機的多控系統(tǒng),是我用過各方面都比較穩(wěn)定的一款軟件了。通過腳本實現(xiàn)識別顏色是其強大功能之一,之前分享了多點顏色比較的腳本示例,今天來說說如何用Total Control 提供的REST API 實現(xiàn)多點比較顏色,支持多色,顏色范圍,相似度比較顏色。
Total Control 提供的REST API:
請求參數(shù):
請求示例:
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示例:
#!/user/bin/python
#-*- coding:utf-8 -*-
import
import requests
# The username and password are separated by a single : and sent on the wire encoded
user_pass = 'sigma:3D391497'
encodeStr = .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.")
運行結(jié)果:
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呢?官網(wǎng)直接下載就可以了,專業(yè)版還提供免費試用哦,快點下載一個試試吧!
責任編輯:
總結(jié)
以上是生活随笔為你收集整理的python颜色识别原理_电脑控制手机 Python实现颜色识别功能的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 买基金的正确方法和技巧 考虑这些方面就
- 下一篇: logback-spring.xml 文