import json
import cv2
import requests
import numpy as np
import base64
import matplotlib.pyplot as plt
%matplotlib inline
import warnings
warnings.filterwarnings("ignore")
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.tiia.v20190529 import tiia_client
from tencentcloud.tiia.v20190529 import models as tiia_models
SecretId="xxxxxxxxx"
SecretKey="xxxxxxxxx"
"""
https://console.cloud.tencent.com/api
/explorer?Product=tiia&Version=2019-05-29&Action=DetectMisbehavior&SignVersion=
不良行为识别
"""
try:
cred = credential.Credential(SecretId, SecretKey)
httpProfile = HttpProfile()
httpProfile.endpoint = "tiia.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = tiia_client.TiiaClient(cred, "ap-beijing", clientProfile)
img_path="./images/吸毒.jpg"
with open(img_path,"rb") as file:
img=base64.b64encode(file.read())
req = tiia_models.DetectMisbehaviorRequest()
params = {
"ImageBase64": str(img, encoding='utf-8'),
}
req.from_json_string(json.dumps(params))
resp = client.DetectMisbehavior(req).to_json_string()
resp=json.loads(resp)
print(resp)
"""
Confidence Float 对于图片中包含不良行为的置信2osgDTSChwu74k9IbfSyWoOiOFG2Xlrh度,取值[0,1],一般超过0.5则表明可能包含不良行为内容;
Type String 图像中最可能包含的不良行为类别,包括赌博、打架斗殴、吸毒等。
"""
except TencentCloudSDKException as err:
print(err)
{'Confidence': 0.72, 'Type': '吸毒', 'RequestId': '0ac58e1c-dd99-4987-8399-de1ccb150a4a'}
"""
https://console.cloud.tencent.com/api
/explorer?Product=tiia&Version=2019-05-29&Action=DetectDisgust&SignVersion=
恶心检测
"""
import json
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.tiia.v20190529 import tiia_client, models
try:
cred = credential.Credential(SecretId, SecretKey)
httpProfile = HttpProfile()
httpProfile.endpoint = "tiia.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = tiia_client.TiiaClient(cred, "ap-beijing", clientProfile)
img_path="./images/虫子.jpg"
with open(img_path,"rb") as file:
img=base64.b64encode(file.read())
req = tiia_models.DetectDisgustRequest()
params = {
"ImageBase64": str(img, encoding='utf-8'),
}
req.from_json_string(json.dumps(params))
resp = client.DetectDisgust(req).to_json_string()
resp=json.loads(resp)
print(resp)
"""
Confidence Float 对于图片中包含恶心内容的置信度,取值[0,1],一般超过0.5则表明可能是恶心图片。
Type String 与图像内容最相似的恶心内容的类别,包含腐烂、密集、畸形、血腥、蛇、虫子、牙齿等。
"""
except TencentCloudSDKException as err:
print(err)
{'Confidence': 1, 'Type': '虫子', 'RequestId': '62533307-1c81-482e-9a3f-71776205f395'}
"""
https://console.cloud.tencent.com/api
/explorer?Product=tiia&Version=2019-05-29&Action=AssessQuality&SignVersion=
图像质量评估
"""
try:
cred = credential.Credential(SecretId, SecretKey)
httpProfile = HttpProfile()
httpProfile.endpoint = "tiia.tencentcloudapi.com"
clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = tiia_client.TiiaClient(cred, "ap-beijing", clientProfile)
img_path="./images/模糊图片2.jpg"
with open(img_path,"rb") as file:
img=base64.b64encode(file.read())
req = tiia_models.AssessQualityRequest()
params = {
"ImageBase64": str(img, encoding='utf-8'),
}
req.from_json_string(json.dumps(params))
resp = client.AssessQuality(req).to_json_string()
resp=json.loads(resp)
print(resp)
except TencentCloudSDKException as err:
print(err)
{'LongImage': False, 'BlackAndWhite': False, 'SmallImage': False, 'BigImage': False, 'PureImage': False, 'ClarityScore': 5, 'AestheticScore': 7, 'RequestId': '0fcca43a-f516-4fd2-97a4-dc9fb6a46325'}
"""
LongImage Boolean 取值为TRUE或FALSE,TRUE为长图,FALSE为正常图,长图定义为长宽比大于等于3或小于等于1/3的图片。
BlackAndWhite Boolean 取值为TRUE或FALSE,TRUE为黑白图,FALSE为否。黑白图即灰度图,指红绿蓝三个通道都是以灰度色阶显示的图片,并非视觉上的“黑白图片”。
SmallImage Boolean 取值为TRUE或FALSE,TRUE为小图,FALSE为否, 小图定义为最长边小于179像素的图片。当一张图片被判断为小图时,不建议做推荐和展示,其他字段统一输出为0或FALSE。
BigImage Boolean 取值为TRUE或FALSE,TRUE为大图,FALSE为否,定义为最短边大于1000像素的图片
PureImage Boolean 取值为TRUE或FALSE,TRUE为纯色图或纯文字图,即没有内容或只有简单内容的图片,FALSE为正常图片。
ClarityScore Integer 综合评分。图像清晰度的得分,对图片的噪声、曝光、模糊、压缩等因素进行综合评估,取值为[0, 100],值越大,越清晰。一般大于50为较清晰图片,标准可以自行把握。
AestheticScore Integer 综合评分。图像美观度得分, 从构图、色彩等多个艺术性维度评价图片,取值为[0, 100],值越大,越美观。一般大于50为较美观图片,标准可以自行把握。
RequestId String 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId
"""