Skip to content

Commit a475250

Browse files
authored
Merge pull request #281 from bug-is-zhang/master
add AIObjectDetect sdk and demo
2 parents 8f00a5d + 2f453ad commit a475250

File tree

12 files changed

+2629
-70
lines changed

12 files changed

+2629
-70
lines changed

demo/ai_recognition_demo.py

Lines changed: 584 additions & 0 deletions
Large diffs are not rendered by default.

demo/ci_media.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -78,39 +78,6 @@ def ci_get_ai_bucket():
7878
return response
7979

8080

81-
def ci_get_ai_queue():
82-
# 查询ai处理队列信息
83-
response = client.ci_get_ai_queue(
84-
Bucket=bucket_name,
85-
)
86-
print(response)
87-
return response
88-
89-
90-
def ci_put_ai_queue():
91-
# 更新ai队列信息
92-
body = {
93-
'Name': 'ai-queue',
94-
'QueueID': 'pa2c2afbe68xxxxxxxxxxxxxxxxxxxxxx',
95-
'State': 'Active',
96-
'NotifyConfig': {
97-
'Type': 'Url',
98-
'Url': 'http://www.demo.callback.com',
99-
'Event': 'TaskFinish',
100-
'State': 'On',
101-
'ResultFormat': 'JSON',
102-
}
103-
}
104-
response = client.ci_update_ai_queue(
105-
Bucket=bucket_name,
106-
QueueId='pa2c2afbe68c44xxxxxxxxxxxxxxxxxxxx',
107-
Request=body,
108-
ContentType='application/xml'
109-
)
110-
print(response)
111-
return response
112-
113-
11481
def ci_get_media_pic_queue():
11582
# 查询图片处理队列信息
11683
response = client.ci_get_media_pic_queue(

demo/ci_speech_recognition.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727
bucket_name = 'examplebucket-1250000000'
2828

2929

30+
def ci_open_asr_bucket():
31+
# 开通智能语音服务
32+
response, data = client.ci_open_asr_bucket(
33+
Bucket=bucket_name
34+
)
35+
print(response)
36+
print(data)
37+
return response, data
38+
39+
3040
def ci_get_asr_bucket():
3141
# 查询语音识别开通状态
3242
response = client.ci_get_asr_bucket(
@@ -39,6 +49,16 @@ def ci_get_asr_bucket():
3949
return response
4050

4151

52+
def ci_close_asr_bucket():
53+
# 关闭智能语音服务
54+
response, data = client.ci_close_asr_bucket(
55+
Bucket=bucket_name
56+
)
57+
print(response)
58+
print(data)
59+
return response, data
60+
61+
4262
def ci_get_asr_queue():
4363
# 查询语音识别队列信息
4464
response = client.ci_get_asr_queue(
@@ -166,10 +186,13 @@ def ci_delete_asr_template():
166186
# ci_get_asr_bucket()
167187
# ci_get_asr_queue()
168188
# ci_put_asr_queue()
169-
ci_create_asr_template()
189+
# ci_create_asr_template()
170190
# ci_get_asr_template()
171191
# ci_update_asr_template()
172192
# ci_delete_asr_template()
173-
ci_create_asr_jobs()
193+
# ci_create_asr_jobs()
174194
# ci_get_asr_jobs()
175195
# ci_list_asr_jobs()
196+
# ci_close_asr_bucket()
197+
# ci_open_asr_bucket()
198+
ci_get_asr_bucket()

demo/ci_template.py

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1730,10 +1730,95 @@ def ci_update_smart_cover_template():
17301730
return response
17311731

17321732

1733+
noise_reduction_template_config = {
1734+
# 固定值:NoiseReduction
1735+
# 是否必传:是
1736+
'Tag': "NoiseReduction",
1737+
# 模板名称,仅支持中文、英文、数字、_、-和*,长度不超过 64。
1738+
# 是否必传:是
1739+
'Name': "noise_reduction_test",
1740+
# 降噪参数
1741+
# 是否必传:是
1742+
'NoiseReduction': {
1743+
# 封装格式,支持 mp3、m4a、wav
1744+
# 是否必传:否
1745+
'Format': "wav",
1746+
# 采样率单位:Hz可选 8000、12000、16000、24000、32000、44100、48000
1747+
# 是否必传:否
1748+
'Samplerate': "8000",
1749+
},
1750+
}
1751+
1752+
1753+
def ci_create_noise_reduction_template():
1754+
# 创建音频降噪模板
1755+
response = client.ci_create_template(
1756+
Bucket=bucket_name,
1757+
Template=noise_reduction_template_config,
1758+
)
1759+
print(response)
1760+
return response
1761+
1762+
1763+
def ci_update_noise_reduction_template():
1764+
# 更新音频降噪模板
1765+
response = client.ci_update_template(
1766+
Bucket=bucket_name,
1767+
TemplateId='t1ec6c1xxxxxxxxxxxxxxxxxxxxxx',
1768+
Template=noise_reduction_template_config,
1769+
)
1770+
print(response)
1771+
return response
1772+
1773+
1774+
video_target_rec_template_config = {
1775+
# 模板类型:VideoTargetRec
1776+
# 是否必传:是
1777+
'Tag': "VideoTargetRec",
1778+
# 模板名称,仅支持中文、英文、数字、_、-和*,长度不超过 64
1779+
# 是否必传:是
1780+
'Name': "video_target_rec_test",
1781+
# 视频目标检测 参数
1782+
# 是否必传:是
1783+
'VideoTargetRec': {
1784+
# 是否开启人体检测,取值 true/false
1785+
# 是否必传:否
1786+
'Body': "true",
1787+
# 是否开启宠物检测,取值 true/false
1788+
# 是否必传:否
1789+
'Pet': "true",
1790+
# 是否开启车辆检测,取值 true/false
1791+
# 是否必传:否
1792+
'Car': "false",
1793+
},
1794+
}
1795+
1796+
1797+
def ci_create_video_target_template():
1798+
# 创建视频目标检测模板
1799+
response = client.ci_create_template(
1800+
Bucket=bucket_name,
1801+
Template=video_target_rec_template_config,
1802+
)
1803+
print(response)
1804+
return response
1805+
1806+
1807+
def ci_update_video_target_template():
1808+
# 更新视频目标检测模板
1809+
response = client.ci_update_template(
1810+
Bucket=bucket_name,
1811+
TemplateId='t17de5xxxxxxxxxxxxxxxxxxxxxxx',
1812+
Template=video_target_rec_template_config,
1813+
)
1814+
print(response)
1815+
return response
1816+
1817+
17331818
if __name__ == "__main__":
17341819
# ci_create_snapshot_template()
17351820
# ci_update_snapshot_template()
1736-
ci_create_transcode_template()
1821+
# ci_create_transcode_template()
17371822
# ci_update_transcode_template()
17381823
# ci_create_high_speed_hd_template()
17391824
# ci_update_high_speed_hd_template()
@@ -1756,4 +1841,8 @@ def ci_update_smart_cover_template():
17561841
# ci_update_tts_template()
17571842
# ci_create_smart_cover_template()
17581843
# ci_update_smart_cover_template()
1844+
# ci_create_noise_reduction_template()
1845+
# ci_update_noise_reduction_template()
1846+
# ci_create_video_target_template()
1847+
ci_update_video_target_template()
17591848

demo/hls_decrypt_token.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# -*- coding=utf-8
2+
import base64
3+
import jwt
4+
from urllib.parse import quote, quote_plus
5+
from qcloud_cos import CosConfig
6+
from qcloud_cos import CosS3Client
7+
from datetime import datetime, timedelta
8+
9+
import sys
10+
import logging
11+
import os
12+
13+
# 腾讯云COSV5Python SDK, 目前可以支持Python2.6与Python2.7以及Python3.x
14+
15+
# 媒体处理相关API请参考 https://cloud.tencent.com/document/product/460/84790
16+
17+
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
18+
19+
# 设置用户属性, 包括secret_id, secret_key, region
20+
# appid已在配置中移除,请在参数Bucket中带上appid。Bucket由bucketname-appid组成
21+
# 这里秘钥是从环境变量取得,如自己测试可改成自己对应的秘钥
22+
secret_id = os.environ["SECRETID"] # 替换为用户的 SecretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
23+
secret_key = os.environ["SECRETKEY"] # 替换为用户的 SecretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
24+
region = 'ap-chongqing' # 替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
25+
# COS支持的所有region列表参见https://www.qcloud.com/document/product/436/6224
26+
token = None # 如果使用永久密钥不需要填入token,如果使用临时密钥需要填入,临时密钥生成和使用指引参见https://cloud.tencent.com/document/product/436/14048
27+
28+
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Scheme='https') # 获取配置对象
29+
client = CosS3Client(config)
30+
31+
32+
bucket_name = 'demo-1250000000'
33+
play_key = 'play_key'
34+
object_name = 'test.m3u8'
35+
36+
37+
def generate_token():
38+
now = datetime.now()
39+
expire_time = now + timedelta(minutes=30)
40+
path_encoded = quote(object_name)
41+
object = quote_plus(path_encoded)
42+
43+
headers = {
44+
# 加密的算法,固定为 HS256
45+
"alg": "HS256",
46+
# 类型,固定为 JWT
47+
"typ": "JWT"
48+
}
49+
token_info = {
50+
# 固定为 CosCiToken, 必填参数
51+
'Type': 'CosCiToken',
52+
# app id,必填参数
53+
'AppId': '1250000000',
54+
# 播放文件所在的BucketId, 必填参数
55+
'BucketId': bucket_name,
56+
# 播放文件名
57+
'Object': object,
58+
# 固定为client,必填参数
59+
'Issuer': 'client',
60+
# token颁发时间戳,必填参数
61+
'IssuedTimeStamp': now.timestamp(),
62+
# token过期时间戳,非必填参数,默认1天过期
63+
'ExpireTimeStamp': expire_time.timestamp(),
64+
# token使用次数限制,非必填参数,默认限制100000次
65+
'UsageLimit': 20,
66+
# 是否加密解密密钥(播放时解密ts视频流的密钥),1表示对解密密钥加密,0表示不对解密密钥加密。
67+
'ProtectContentKey': 1,
68+
}
69+
if token_info['ProtectContentKey'] == 1:
70+
public_key = """-----BEGIN PUBLIC KEY-----
71+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxBgQCj9GNktf2yA0Mp8aCzxxxxxxxx
72+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx54Jl4NVNewBLPZq1WFxxxxxxxxxx
73+
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxKpSCdl9hHxFZ732ixxxxxxxxxxxx
74+
xxxxxxxxxxxxxxxxxxxx
75+
-----END PUBLIC KEY-----"""
76+
base64_public_key = base64.urlsafe_b64encode(public_key.encode('utf-8')).decode('utf-8')
77+
token_info.update({
78+
# 保护模式,填写为 rsa1024 ,则表示使用 RSA 非对称加密的方式保护,公私钥对长度为 1024 bit
79+
'ProtectSchema': "rsa1024",
80+
# 公钥。1024 bit 的 RSA 公钥,需使用 Base64 进行编码
81+
'PublicKey': base64_public_key,
82+
})
83+
return jwt.encode(token_info, play_key, algorithm="HS256", headers=headers)
84+
85+
86+
def get_url():
87+
url = client.get_presigned_download_url(
88+
Bucket=bucket_name, # 存储桶名称
89+
Key="/" + object_name,
90+
Expired=3600, # 预签名超时时间
91+
)
92+
if token is not None:
93+
url = url + "&x-cos-security-token=" + token
94+
url = url + "&tokenType=JwtToken&expires=3600&ci-process=pm3u8&token=" + generate_token()
95+
return url
96+
97+
98+
if __name__ == '__main__':
99+
print(generate_token())
100+
print(get_url())

demo/meta_insight_demo.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def ci_describe_dataset():
248248
# 查询数据集
249249

250250
response, data = client.ci_describe_dataset(
251-
Datasetname="数据集名称",
251+
DatasetName="数据集名称",
252252
Statistics="",
253253
ContentType="application/json"
254254
)
@@ -261,7 +261,7 @@ def ci_describe_dataset_binding():
261261
# 查询数据集与存储桶的绑定关系
262262

263263
response, data = client.ci_describe_dataset_binding(
264-
Datasetname="数据集名称",
264+
DatasetName="数据集名称",
265265
Uri="uri",
266266
ContentType="application/json"
267267
)
@@ -274,9 +274,9 @@ def ci_describe_dataset_bindings():
274274
# 查询绑定关系列表
275275

276276
response, data = client.ci_describe_dataset_bindings(
277-
Datasetname="数据集名称",
278-
Maxresults=100,
279-
Nexttoken="下一页",
277+
DatasetName="数据集名称",
278+
MaxResults=100,
279+
NextToken="下一页",
280280
ContentType="application/json"
281281
)
282282
print(response)
@@ -288,8 +288,8 @@ def ci_describe_datasets():
288288
# 列出数据集
289289

290290
response, data = client.ci_describe_datasets(
291-
Maxresults=100,
292-
Nexttoken="下一页",
291+
MaxResults=100,
292+
NextToken="下一页",
293293
Prefix="数据集前缀",
294294
ContentType="application/json"
295295
)
@@ -302,7 +302,7 @@ def ci_describe_file_meta_index():
302302
# 查询元数据索引
303303

304304
response, data = client.ci_describe_file_meta_index(
305-
Datasetname="数据集名称",
305+
DatasetName="数据集名称",
306306
Uri="cos://facesearch-12500000000",
307307
ContentType="application/json"
308308
)
@@ -369,7 +369,7 @@ def ci_update_file_meta_index():
369369
'DatasetName': "test001",
370370
# 用于建立索引的文件信息。
371371
# 是否必传:是
372-
'UpdateMetaFile': {
372+
'File': {
373373
# 自定义ID。该文件索引到数据集后,作为该行元数据的属性存储,用于和您的业务系统进行关联、对应。您可以根据业务需求传入该值,例如将某个URI关联到您系统内的某个ID。推荐传入全局唯一的值。在查询时,该字段支持前缀查询和排序,详情请见[字段和操作符的支持列表](https://cloud.tencent.com/document/product/460/106154)。
374374
# 是否必传:否
375375
'CustomId': "001",

qcloud_cos/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .cos_auth import CosS3Auth
66
from .cos_comm import get_date
77
from .meta_insight import MetaInsightClient
8+
from .ai_recognition import AIRecognitionClient
89

910
import logging
1011

0 commit comments

Comments
 (0)