百度智能云 API调用PythonSDK
创始人
2024-05-03 23:25:35

这是一个用于百度云部分开放AI功能的Python库。主要为ORC功能,可以对各种图像文件进行文字识别,包括车牌、手写文字、通用文字、人脸发现、人脸比对和人流量统计等。

更多的功能大家可以提出,后续会慢慢开发这个库。

使用这个库,你可以很方便地调用百度云OCR API,并将识别结果以json的形式返回。你可以根据自己的需要来使用不同的API,以获得更精确或更快速的识别结果。

此外,这个库还提供了URL版本的文字识别功能,可以直接对网络图片进行识别。

使用方法

1.安装库

使用pip安装:

pip install baiducloud
  1. 准备API Key和Secret Key

2.准备API Key和Secret Key

在使用百度云OCR API之前,你需要去百度云控制台申请API Key和Secret Key。

3.初始化baiducloud类

在你的代码中导入baiducloud类,并使用API Key和Secret Key初始化它:

from baiducloud import baiducloudapi_key = "your_api_key"
secret_key = "your_secret_key"bc = baiducloud(api_key, secret_key)

4.使用Python开发你的程序

例子1.车牌识别

result = bc.orc_license_plate("image.jpg")
print(result)

返回结果是一个json

例子2.使用URL版本的文字识别

result = bc.orc_license_plate_url("https://example.com/image.jpg")
print(result)

注意:使用URL版本的文字识别方法时,你需要确保图片URL是可以公开访问的。

例子3.使用人脸比对

result = bc.face_compare("https://example.com/image.jpg","https://example.com/image1.jpg")
print(result)

当然,还有更多的使用方法,具体可以参考baiducloud > main.py,使用方法大同小异,文档就后续再更新。

生成环境

下面是我的机器人的真实使用环境,大家可以进行一个参考:

#百度云 车牌识别
def baiduyun_orc_traffic_plate(img_path):bc = baiducloud.baiducloud(sqlite.search_API("百度云应用API_Key"), sqlite.search_API("百度云应用Secret_Key"))response_data = bc.orc_license_plate(img_path)number = response_data['words_result']['number']color = response_data['words_result']['color']return "车牌号:"+number+"\n颜色:"+color#百度云 车牌识别——URL版
def baiduyun_orc_traffic_plate_url(img_url):bc = baiducloud.baiducloud(sqlite.search_API("百度云应用API_Key"), sqlite.search_API("百度云应用Secret_Key"))response_data = bc.orc_license_plate_url(img_url)number = response_data['words_result']['number']color = response_data['words_result']['color']return "车牌号:"+number+"\n颜色:"+color#百度云 手写文字识别
def baiduyun_orc_handwriting(img_url):bc = baiducloud.baiducloud(sqlite.search_API("百度云应用API_Key"), sqlite.search_API("百度云应用Secret_Key"))response_data = bc.orc_handwriting_url(img_url)words_result = response_data['words_result']words = ""for i in words_result:words += i['words']+"\n"return words[:-1]#百度云 通用文字识别 高精度
def baiduyun_orc_accurate_basic(img_url):bc = baiducloud.baiducloud(sqlite.search_API("百度云应用API_Key"), sqlite.search_API("百度云应用Secret_Key"))response_data = bc.orc_accurate_basic_url(img_url)words_result = response_data['words_result']words = ""for i in words_result:words += i['words']+"\n"return words[:-1]#百度云 通用文字识别
def baiduyun_orc_general_basic(img_url):bc = baiducloud.baiducloud(sqlite.search_API("百度云应用API_Key"), sqlite.search_API("百度云应用Secret_Key"))response_data = bc.orc_general_basic_url()words_result = response_data['words_result']words = ""for i in words_result:words += i['words'] + "\n"return words[:-1]
#百度云 人脸检测
def baiduyun_face_check(img_path):bc = baiducloud.baiducloud(sqlite.search_API("百度云应用API_Key"), sqlite.search_API("百度云应用Secret_Key"))response_data = bc.face_detect(img_path)if response_data['error_code'] != 0:return response_data['error_msg']else:return "检测到"+str(response_data['result']['face_num'])+"张人脸"
#百度云 人脸对比
def baiduyun_face_contrast(img_path,img_path1):bc = baiducloud.baiducloud(sqlite.search_API("百度云应用API_Key"), sqlite.search_API("百度云应用Secret_Key"))response_data = bc.face_compare(img_path,img_path1)if response_data['error_code'] != 0:return response_data['error_msg']else:return "两张人脸相似度为:"+str(response_data['result']['score'])+"%"#百度云 人流量
def baiduyun_person_num(img_path):bc = baiducloud.baiducloud(sqlite.search_API("百度云应用API_Key"), sqlite.search_API("百度云应用Secret_Key"))response_data = bc.person_num(img_path)return "图片中人流量为:"+str(response_data['person_num'])

当然,写的有些乱,但是应该可以看懂。

相关内容

热门资讯

猫咪吃了塑料袋怎么办 猫咪误食... 你知道吗?塑料袋放久了会长猫哦!要说猫咪对塑料袋的喜爱程度完完全全可以媲美纸箱家里只要一有塑料袋的响...
北京的名胜古迹 北京最著名的景... 北京从元代开始,逐渐走上帝国首都的道路,先是成为大辽朝五大首都之一的南京城,随着金灭辽,金代从海陵王...
世界上最漂亮的人 世界上最漂亮... 此前在某网上,选出了全球265万颜值姣好的女性。从这些数量庞大的女性群体中,人们投票选出了心目中最美...
苗族的传统节日 贵州苗族节日有... 【岜沙苗族芦笙节】岜沙,苗语叫“分送”,距从江县城7.5公里,是世界上最崇拜树木并以树为神的枪手部落...
长白山自助游攻略 吉林长白山游... 昨天介绍了西坡的景点详细请看链接:一个人的旅行,据说能看到长白山天池全凭运气,您的运气如何?今日介绍...