python做图片文字识别和图片鉴黄
代码如下:
import re
from aip import AipOcr,AipBodyAnalysis,AipImageCensor
class Bd(object):
"""
加载配置
"""
def __init__(self):
self.W_APP_ID = ''
self.API_KEY = ''
self.SECRET_KEY = ''
#文字识别
def wz(self,img_file):
client = AipOcr(self.W_APP_ID, self.API_KEY, self.SECRET_KEY)
# 通用文字识别接口
data = client.basicGeneral(img_file)
data = str(data)
ds = re.compile(r"{'words': ' (.*?)'}")
res = ds.findall(data)
for i in res:
print(i)
# res = data['words_result'][0]['words']
# print(res)
def jh(self,file_name):
s_client = AipImageCensor(self.W_APP_ID, self.API_KEY, self.SECRET_KEY)
res = s_client.imageCensorUserDefined(file_name)
print(res)
if __name__ == '__main__':
bd = Bd()
with open('6.jpg','rb')as f:
# bd.wz(f.read())
bd.jh(f.read())
仅供参考