Skip to content

Commit 3a8bb75

Browse files
dt3310321tiedu
andauthored
add detect (#169)
Co-authored-by: tiedu <tiedu@tencent.com>
1 parent ef9495c commit 3a8bb75

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

qcloud_cos/cos_client.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,20 +406,23 @@ def get_object(self, Bucket, Key, **kwargs):
406406

407407
return response
408408

409-
def get_object_sensitive_content_recognition(self, Bucket, Key, DetectType, **kwargs):
409+
def get_object_sensitive_content_recognition(self, Bucket, Key, DetectType, Interval=None, MaxFrames=None, BizType=None, **kwargs):
410410
"""文件内容识别接口 https://cloud.tencent.com/document/product/460/37318
411411
412412
:param Bucket(string): 存储桶名称.
413413
:param Key(string): COS路径.
414414
:param DetectType(int): 内容识别标志,位计算 1:porn, 2:terrorist, 4:politics, 8:ads
415+
:param Interval(int): 截帧频率,GIF图/长图检测专用,默认值为0,表示只会检测GIF图/长图的第一帧.
416+
:param MaxFrames(int): 最大截帧数量,GIF图/长图检测专用,默认值为1,表示只取GIF的第1帧图片进行审核,或长图不做切分识别.
417+
:param BizType(string): 审核策略的唯一标识,由后台自动生成,在控制台中对应为Biztype值.
415418
:param kwargs(dict): 设置下载的headers.
416419
:return(dict): 下载成功返回的结果,dict类型.
417420
418421
.. code-block:: python
419422
420423
config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token) # 获取配置对象
421424
client = CosS3Client(config)
422-
# 下载cos上的文件到本地
425+
# 识别cos上的图片
423426
response = client.get_object_sensitive_content_recognition(
424427
Bucket='bucket',
425428
DetectType=CiDetectType.PORN | CiDetectType.POLITICS,
@@ -458,6 +461,12 @@ def get_object_sensitive_content_recognition(self, Bucket, Key, DetectType, **kw
458461
detect_type += 'ads'
459462

460463
params['detect-type'] = detect_type
464+
if Interval:
465+
params['interval'] = Interval
466+
if MaxFrames:
467+
params['max-frames'] = MaxFrames
468+
if BizType:
469+
params['biz-type'] = BizType
461470
params = format_values(params)
462471

463472
url = self._conf.uri(bucket=Bucket, path=Key)

qcloud_cos/cos_threadpool.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,14 @@ def get_result(self):
8484

8585
pool = SimpleThreadPool(2)
8686

87-
8887
def task_sleep(x):
8988
from time import sleep
9089
sleep(x)
9190
return 'hello, sleep %d seconds' % x
9291

93-
9492
def raise_exception():
9593
raise ValueError("Pa! Exception!")
9694

97-
9895
for i in range(1000):
9996
pool.add_task(task_sleep, 0.001)
10097
print(i)

ut/test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ def print_error_msg(e):
9696

9797
def percentage(consumed_bytes, total_bytes):
9898
"""进度条回调函数,计算当前完成的百分比
99-
10099
:param consumed_bytes: 已经上传/下载的数据量
101100
:param total_bytes: 总数据量
102101
"""
@@ -1541,6 +1540,7 @@ def test_live_channel():
15411540
response = client.delete_live_channel(Bucket=test_bucket, ChannelName=channel_name)
15421541
assert (response)
15431542

1543+
15441544
def test_get_object_url():
15451545
"""测试获取对象访问URL"""
15461546
response = client.get_object_url(
@@ -1549,7 +1549,8 @@ def test_get_object_url():
15491549
)
15501550
print(response)
15511551

1552-
def test_qrcode():
1552+
1553+
def _test_qrcode():
15531554
"""二维码图片上传时识别"""
15541555
file_name = 'test_object_sdk_qrcode.file'
15551556
with open(file_name, 'rb') as fp:

0 commit comments

Comments
 (0)