Beispiel #1
0
 def id_card_file_ocr(self):
     """OCR-File-身份证识别"""
     client = self.get_client()
     if len(self.image_file) >= 0 and self.image_surface == 'front':
         # 返回正面文件图片信息
         print(client.idcard_detect(CIUrls(self.image_file), 0))
     elif len(self.image_file) >= 0 and self.image_surface == 'backend':
         # 返回反面文件图片信息
         print(client.idcard_detect(CIUrls(self.image_file), 1))
Beispiel #2
0
 def id_card_url_ocr(self):
     """OCR-URL-身份证识别"""
     client = self.get_client()
     if len(self.image_url) >= 0 and self.image_surface == 'front':
         # 返回正面URL图片信息
         print(client.idcard_detect(CIUrls(self.image_url), 0))
     elif len(self.image_url) >= 0 and self.image_surface == 'backend':
         # 返回反面URL图片信息
         print(client.idcard_detect(CIUrls(self.image_url), 1))
Beispiel #3
0
def porn_detect(data):
    print data
    client = Client(appid, secret_id, secret_key, bucket)
    client.use_http()
    client.set_timeout(30)
    a=client.porn_detect(CIUrls(data[0:5]))
    print a
Beispiel #4
0
 def face_detection(self):
     """Face-人脸检测"""
     client = self.get_client()
     if len(self.image_url) >= 0:
         # URL图片信息
         print(client.face_detect(CIUrls(self.image_url)))
     if len(self.image_file) >= 0:
         # 文件图片信息
         print(client.face_detect(CIFiles(self.image_file)))
Beispiel #5
0
 def business_card_ocr(self):
     """OCR-名片识别"""
     client = self.get_client()
     if len(self.image_url) >= 0:
         # URL图片信息
         print(client.namecard_detect(CIUrls(self.image_url)))
     if len(self.image_file) >= 0:
         # 文件图片信息
         print(client.namecard_detect(CIFiles(self.image_file)))
Beispiel #6
0
 def image_as_yellow_ocr(self):
     """OCR-图片鉴黄"""
     client = self.get_client()
     if len(self.image_url) >= 0:
         # URL图片信息
         print(client.porn_detect(CIUrls(self.image_url)))
     if len(self.image_file) >= 0:
         # 文件图片信息
         print(client.porn_detect(CIFiles(self.image_file)))
Beispiel #7
0
 def facial_detection(self):
     """Face-五官定位"""
     client = self.get_client()
     if len(self.image_url) >= 0:
         # URL图片信息
         print(client.face_shape(CIUrls(self.image_url), 1))
     if len(self.image_file) >= 0:
         # 文件图片信息
         print(client.face_shape(CIFiles(self.image_file), 1))
Beispiel #8
0
def check_image():
    client = Client(appid, secret_id, secret_key, bucket)
    client.use_http()
    client.set_timeout(30)

    status = True
    while status:

        num = str(int(random.uniform(200000, 500000)))
        url = "https://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-" + num + ".jpg"
        result = client.porn_detect(CIUrls([url]))["result_list"][0]
        if result["message"] == "success":
            if result["data"]["porn_score"] < 1:
                status = False
    return url, result
Beispiel #9
0
    def detect_back(link):
        resp = client.idcard_detect(CIUrls([link]), 1)
        if resp['httpcode'] != 200:
            raise IDCardError.IDCARD_DETECT_ERROR(resp['result_list'][0]['message'])
        resp = resp['result_list'][0]
        if resp['code'] != 0:
            raise IDCardError.IDCARD_DETECT_ERROR('验证错误' + str(resp['msg']))
        resp = resp['data']
        try:
            valid_start = datetime.datetime.strptime(
                resp['valid_date'][:10], '%Y.%m.%d').strftime('%Y-%m-%d')
            valid_end = datetime.datetime.strptime(
                resp['valid_date'][-10:], '%Y.%m.%d').strftime('%Y-%m-%d')
        except Exception as err:
            raise IDCardError.IDCARD_DETECT_ERROR('生日验证错误', debug_message=err)

        return dict(
            valid_start=valid_start,
            valid_end=valid_end,
        )
Beispiel #10
0
    def detect_front(link):
        resp = client.idcard_detect(CIUrls([link]), 0)
        if resp['httpcode'] != 200:
            raise IDCardError.IDCARD_DETECT_ERROR(resp['result_list'][0]['message'])
        resp = resp['result_list'][0]
        if resp['code'] != 0:
            raise IDCardError.IDCARD_DETECT_ERROR('验证错误' + str(resp['msg']))
        resp = resp['data']

        try:
            birth = datetime.datetime.strptime(resp['birth'], '%Y/%m/%d').strftime('%Y-%m-%d')
        except Exception as err:
            raise IDCardError.IDCARD_DETECT_ERROR('生日验证错误', debug_message=err)

        return dict(
            male=resp['sex'] == '男',
            name=resp['name'],
            idcard=resp['id'],
            birthday=birth,
        )
Beispiel #11
0
def picture_verify(picture):
    """第三方图片审核api(万象优图)"""
    appid = "10072767"  # 项目ID
    secret_id = "AKIDZBf2DdSCLNoAPXvH4kHeq2AHF1bz4b9a"  # 密钥ID
    secret_key = "1xjPxMjx4zsfGICvyvg4MX5cHAAze9Xp"  # 密钥key
    bucket = 'chuangyi'  # 图片空间名称
    image = tencentyun.ImageV2(appid, secret_id, secret_key)
    try:
        # image_data = open(picture_url, "rb").read()
        # 将图片上传到图片空间
        obj = image.upload_binary(picture, bucket)  # 第二个参数为空间名称
        if obj["code"] == 0:
            fileid = obj["data"]["fileid"]
            download_url = obj["data"]["download_url"]
            # 图片检测
            client = Client(appid, secret_id, secret_key, bucket)
            client.use_http()
            client.set_timeout(30)
            pornRet = client.porn_detect(CIUrls([download_url]))
            image.delete(bucket, fileid)
            return pornRet["result_list"][0]["data"]["result"]
    except IOError:
        return None
Beispiel #12
0
appid = 'APPID'
secret_id = 'SECRETID'
secret_key = 'SECRETKEY'
bucket = 'BUCKET'

client = Client(appid, secret_id, secret_key, bucket)
client.use_http()
client.set_timeout(30)

#图片鉴黄
#单个或多个图片Url
print(
    client.porn_detect(
        CIUrls([
            'http://jiangsu.china.com.cn/uploadfile/2015/1102/1446443026382534.jpg',
            'http://n.sinaimg.cn/fashion/transform/20160704/flgG-fxtspsa6612705.jpg'
        ])))
#单个或多个图片File
print(client.porn_detect(CIFiles([
    './test.jpg',
])))

# 图片标签
#单个图片url
print(
    client.tag_detect(
        CIUrl('http://img3.a0bi.com/upload/ttq/20160814/1471155260063.png')))
#单个图片file
print(client.tag_detect(CIFile('./hot2.jpg')))

#OCR-身份证识别