# 百度智能云 API调用PythonSDK
这是一个用于百度云部分开放AI功能的Python库。主要为ORC功能,可以对各种图像文件进行文字识别,包括车牌、手写文字、通用文字、人脸发现、人脸比对和人流量统计等。
更多的功能大家可以提出,后续会慢慢开发这个库。
使用这个库,你可以很方便地调用百度云OCR API,并将识别结果以json的形式返回。你可以根据自己的需要来使用不同的API,以获得更精确或更快速的识别结果。
此外,这个库还提供了URL版本的文字识别功能,可以直接对网络图片进行识别。
# 使用方法
## 1.安装库
使用pip安装:
```bash
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初始化它:
```python
from baiducloud import baiducloud
api_key = "your_api_key"
secret_key = "your_secret_key"
bc = baiducloud(api_key, secret_key)
```
## 4.使用Python开发你的程序
### 例子1.车牌识别
```python
result = bc.orc_license_plate("image.jpg")
print(result)
```
返回结果是一个json
### 例子2.使用URL版本的文字识别
```python
result = bc.orc_license_plate_url("https://example.com/image.jpg")
print(result)
```
**注意:使用URL版本的文字识别方法时,你需要确保图片URL是可以公开访问的。**
### 例子3.使用人脸比对
```python
result = bc.face_compare("https://example.com/image.jpg","https://example.com/image1.jpg")
print(result)
```
当然,还有更多的使用方法,具体可以参考`baiducloud > main.py`,使用方法大同小异,文档就后续再更新。
# 生成环境
下面是我的机器人的真实使用环境,大家可以进行一个参考:
```python
#百度云 车牌识别
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'])
```
当然,写的有些乱,但是应该可以看懂。
Raw data
{
"_id": null,
"home_page": "https://github.com/Moxin1044/baiducloud-py",
"name": "baiducloud",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Moxin",
"author_email": "1044631097@qq.com",
"download_url": "https://files.pythonhosted.org/packages/23/53/cd9836a6d2b2e2a7f3bf725b65a40a7fd75b97e27ec9f369466735a40b0e/baiducloud-1.0.8.tar.gz",
"platform": null,
"description": "# \u767e\u5ea6\u667a\u80fd\u4e91 API\u8c03\u7528PythonSDK\r\n\r\n\u8fd9\u662f\u4e00\u4e2a\u7528\u4e8e\u767e\u5ea6\u4e91\u90e8\u5206\u5f00\u653eAI\u529f\u80fd\u7684Python\u5e93\u3002\u4e3b\u8981\u4e3aORC\u529f\u80fd\uff0c\u53ef\u4ee5\u5bf9\u5404\u79cd\u56fe\u50cf\u6587\u4ef6\u8fdb\u884c\u6587\u5b57\u8bc6\u522b\uff0c\u5305\u62ec\u8f66\u724c\u3001\u624b\u5199\u6587\u5b57\u3001\u901a\u7528\u6587\u5b57\u3001\u4eba\u8138\u53d1\u73b0\u3001\u4eba\u8138\u6bd4\u5bf9\u548c\u4eba\u6d41\u91cf\u7edf\u8ba1\u7b49\u3002\r\n\r\n\u66f4\u591a\u7684\u529f\u80fd\u5927\u5bb6\u53ef\u4ee5\u63d0\u51fa\uff0c\u540e\u7eed\u4f1a\u6162\u6162\u5f00\u53d1\u8fd9\u4e2a\u5e93\u3002\r\n\r\n\u4f7f\u7528\u8fd9\u4e2a\u5e93\uff0c\u4f60\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u8c03\u7528\u767e\u5ea6\u4e91OCR API\uff0c\u5e76\u5c06\u8bc6\u522b\u7ed3\u679c\u4ee5json\u7684\u5f62\u5f0f\u8fd4\u56de\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u6765\u4f7f\u7528\u4e0d\u540c\u7684API\uff0c\u4ee5\u83b7\u5f97\u66f4\u7cbe\u786e\u6216\u66f4\u5feb\u901f\u7684\u8bc6\u522b\u7ed3\u679c\u3002\r\n\r\n\u6b64\u5916\uff0c\u8fd9\u4e2a\u5e93\u8fd8\u63d0\u4f9b\u4e86URL\u7248\u672c\u7684\u6587\u5b57\u8bc6\u522b\u529f\u80fd\uff0c\u53ef\u4ee5\u76f4\u63a5\u5bf9\u7f51\u7edc\u56fe\u7247\u8fdb\u884c\u8bc6\u522b\u3002\r\n\r\n# \u4f7f\u7528\u65b9\u6cd5\r\n\r\n## 1.\u5b89\u88c5\u5e93\r\n\r\n\u4f7f\u7528pip\u5b89\u88c5\uff1a\r\n\r\n```bash\r\npip install baiducloud\r\n```\r\n\r\n1. \u51c6\u5907API Key\u548cSecret Key\r\n\r\n## 2.\u51c6\u5907API Key\u548cSecret Key\r\n\r\n\u5728\u4f7f\u7528\u767e\u5ea6\u4e91OCR API\u4e4b\u524d\uff0c\u4f60\u9700\u8981\u53bb\u767e\u5ea6\u4e91\u63a7\u5236\u53f0\u7533\u8bf7API Key\u548cSecret Key\u3002\r\n\r\n## 3.\u521d\u59cb\u5316baiducloud\u7c7b\r\n\r\n\u5728\u4f60\u7684\u4ee3\u7801\u4e2d\u5bfc\u5165baiducloud\u7c7b\uff0c\u5e76\u4f7f\u7528API Key\u548cSecret Key\u521d\u59cb\u5316\u5b83\uff1a\r\n\r\n```python\r\nfrom baiducloud import baiducloud\r\n\r\napi_key = \"your_api_key\"\r\nsecret_key = \"your_secret_key\"\r\n\r\nbc = baiducloud(api_key, secret_key)\r\n```\r\n\r\n## 4.\u4f7f\u7528Python\u5f00\u53d1\u4f60\u7684\u7a0b\u5e8f\r\n\r\n### \u4f8b\u5b501.\u8f66\u724c\u8bc6\u522b\r\n\r\n```python\r\nresult = bc.orc_license_plate(\"image.jpg\")\r\nprint(result)\r\n```\r\n\r\n\u8fd4\u56de\u7ed3\u679c\u662f\u4e00\u4e2ajson\r\n\r\n### \u4f8b\u5b502.\u4f7f\u7528URL\u7248\u672c\u7684\u6587\u5b57\u8bc6\u522b\r\n\r\n```python\r\nresult = bc.orc_license_plate_url(\"https://example.com/image.jpg\")\r\nprint(result)\r\n```\r\n\r\n**\u6ce8\u610f\uff1a\u4f7f\u7528URL\u7248\u672c\u7684\u6587\u5b57\u8bc6\u522b\u65b9\u6cd5\u65f6\uff0c\u4f60\u9700\u8981\u786e\u4fdd\u56fe\u7247URL\u662f\u53ef\u4ee5\u516c\u5f00\u8bbf\u95ee\u7684\u3002**\r\n\r\n### \u4f8b\u5b503.\u4f7f\u7528\u4eba\u8138\u6bd4\u5bf9\r\n\r\n```python\r\nresult = bc.face_compare(\"https://example.com/image.jpg\"\uff0c\"https://example.com/image1.jpg\")\r\nprint(result)\r\n```\r\n\r\n\u5f53\u7136\uff0c\u8fd8\u6709\u66f4\u591a\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u5177\u4f53\u53ef\u4ee5\u53c2\u8003`baiducloud > main.py`\uff0c\u4f7f\u7528\u65b9\u6cd5\u5927\u540c\u5c0f\u5f02\uff0c\u6587\u6863\u5c31\u540e\u7eed\u518d\u66f4\u65b0\u3002\r\n\r\n# \u751f\u6210\u73af\u5883\r\n\r\n\u4e0b\u9762\u662f\u6211\u7684\u673a\u5668\u4eba\u7684\u771f\u5b9e\u4f7f\u7528\u73af\u5883\uff0c\u5927\u5bb6\u53ef\u4ee5\u8fdb\u884c\u4e00\u4e2a\u53c2\u8003\uff1a\r\n\r\n```python\r\n#\u767e\u5ea6\u4e91 \u8f66\u724c\u8bc6\u522b\r\ndef baiduyun_orc_traffic_plate(img_path):\r\n bc = baiducloud.baiducloud(sqlite.search_API(\"\u767e\u5ea6\u4e91\u5e94\u7528API_Key\"), sqlite.search_API(\"\u767e\u5ea6\u4e91\u5e94\u7528Secret_Key\"))\r\n response_data = bc.orc_license_plate(img_path)\r\n number = response_data['words_result']['number']\r\n color = response_data['words_result']['color']\r\n return \"\u8f66\u724c\u53f7\uff1a\"+number+\"\\n\u989c\u8272\uff1a\"+color\r\n\r\n#\u767e\u5ea6\u4e91 \u8f66\u724c\u8bc6\u522b\u2014\u2014URL\u7248\r\ndef baiduyun_orc_traffic_plate_url(img_url):\r\n bc = baiducloud.baiducloud(sqlite.search_API(\"\u767e\u5ea6\u4e91\u5e94\u7528API_Key\"), sqlite.search_API(\"\u767e\u5ea6\u4e91\u5e94\u7528Secret_Key\"))\r\n response_data = bc.orc_license_plate_url(img_url)\r\n number = response_data['words_result']['number']\r\n color = response_data['words_result']['color']\r\n return \"\u8f66\u724c\u53f7\uff1a\"+number+\"\\n\u989c\u8272\uff1a\"+color\r\n\r\n#\u767e\u5ea6\u4e91 \u624b\u5199\u6587\u5b57\u8bc6\u522b\r\ndef baiduyun_orc_handwriting(img_url):\r\n bc = baiducloud.baiducloud(sqlite.search_API(\"\u767e\u5ea6\u4e91\u5e94\u7528API_Key\"), sqlite.search_API(\"\u767e\u5ea6\u4e91\u5e94\u7528Secret_Key\"))\r\n response_data = bc.orc_handwriting_url(img_url)\r\n words_result = response_data['words_result']\r\n words = \"\"\r\n for i in words_result:\r\n words += i['words']+\"\\n\"\r\n return words[:-1]\r\n\r\n#\u767e\u5ea6\u4e91 \u901a\u7528\u6587\u5b57\u8bc6\u522b \u9ad8\u7cbe\u5ea6\r\ndef baiduyun_orc_accurate_basic(img_url):\r\n bc = baiducloud.baiducloud(sqlite.search_API(\"\u767e\u5ea6\u4e91\u5e94\u7528API_Key\"), sqlite.search_API(\"\u767e\u5ea6\u4e91\u5e94\u7528Secret_Key\"))\r\n response_data = bc.orc_accurate_basic_url(img_url)\r\n words_result = response_data['words_result']\r\n words = \"\"\r\n for i in words_result:\r\n words += i['words']+\"\\n\"\r\n return words[:-1]\r\n\r\n#\u767e\u5ea6\u4e91 \u901a\u7528\u6587\u5b57\u8bc6\u522b\r\ndef baiduyun_orc_general_basic(img_url):\r\n bc = baiducloud.baiducloud(sqlite.search_API(\"\u767e\u5ea6\u4e91\u5e94\u7528API_Key\"), sqlite.search_API(\"\u767e\u5ea6\u4e91\u5e94\u7528Secret_Key\"))\r\n response_data = bc.orc_general_basic_url()\r\n words_result = response_data['words_result']\r\n words = \"\"\r\n for i in words_result:\r\n words += i['words'] + \"\\n\"\r\n return words[:-1]\r\n#\u767e\u5ea6\u4e91 \u4eba\u8138\u68c0\u6d4b\r\ndef baiduyun_face_check(img_path):\r\n bc = baiducloud.baiducloud(sqlite.search_API(\"\u767e\u5ea6\u4e91\u5e94\u7528API_Key\"), sqlite.search_API(\"\u767e\u5ea6\u4e91\u5e94\u7528Secret_Key\"))\r\n response_data = bc.face_detect(img_path)\r\n if response_data['error_code'] != 0:\r\n return response_data['error_msg']\r\n else:\r\n return \"\u68c0\u6d4b\u5230\"+str(response_data['result']['face_num'])+\"\u5f20\u4eba\u8138\"\r\n#\u767e\u5ea6\u4e91 \u4eba\u8138\u5bf9\u6bd4\r\ndef baiduyun_face_contrast(img_path,img_path1):\r\n bc = baiducloud.baiducloud(sqlite.search_API(\"\u767e\u5ea6\u4e91\u5e94\u7528API_Key\"), sqlite.search_API(\"\u767e\u5ea6\u4e91\u5e94\u7528Secret_Key\"))\r\n response_data = bc.face_compare(img_path,img_path1)\r\n if response_data['error_code'] != 0:\r\n return response_data['error_msg']\r\n else:\r\n return \"\u4e24\u5f20\u4eba\u8138\u76f8\u4f3c\u5ea6\u4e3a\uff1a\"+str(response_data['result']['score'])+\"%\"\r\n\r\n#\u767e\u5ea6\u4e91 \u4eba\u6d41\u91cf\r\ndef baiduyun_person_num(img_path):\r\n bc = baiducloud.baiducloud(sqlite.search_API(\"\u767e\u5ea6\u4e91\u5e94\u7528API_Key\"), sqlite.search_API(\"\u767e\u5ea6\u4e91\u5e94\u7528Secret_Key\"))\r\n response_data = bc.person_num(img_path)\r\n return \"\u56fe\u7247\u4e2d\u4eba\u6d41\u91cf\u4e3a\uff1a\"+str(response_data['person_num'])\r\n```\r\n\r\n\u5f53\u7136\uff0c\u5199\u7684\u6709\u4e9b\u4e71\uff0c\u4f46\u662f\u5e94\u8be5\u53ef\u4ee5\u770b\u61c2\u3002\r\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Python\u7684\u767e\u5ea6\u667a\u80fd\u4e91api\u8c03\u7528",
"version": "1.0.8",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "ee98d0ebb99d03b3dac67e184df529c9",
"sha256": "b92be6fff55ba111f2af39b7ba0b401afcbce22209a811cd7383ebf492d5278c"
},
"downloads": -1,
"filename": "baiducloud-1.0.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ee98d0ebb99d03b3dac67e184df529c9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 6292,
"upload_time": "2023-01-01T00:59:14",
"upload_time_iso_8601": "2023-01-01T00:59:14.552961Z",
"url": "https://files.pythonhosted.org/packages/dd/7e/3bd40d3ec296b4c90cf16f00c7dae547e6fa0beb10a69b861fc1bc93597b/baiducloud-1.0.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "e0fd0e93e90b76a94536792428783fac",
"sha256": "4c4c6f52b8ea595936102e0deb2a56b5172bc33271cc28a00f14c83f61bd952d"
},
"downloads": -1,
"filename": "baiducloud-1.0.8.tar.gz",
"has_sig": false,
"md5_digest": "e0fd0e93e90b76a94536792428783fac",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4890,
"upload_time": "2023-01-01T00:59:16",
"upload_time_iso_8601": "2023-01-01T00:59:16.336365Z",
"url": "https://files.pythonhosted.org/packages/23/53/cd9836a6d2b2e2a7f3bf725b65a40a7fd75b97e27ec9f369466735a40b0e/baiducloud-1.0.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-01 00:59:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "Moxin1044",
"github_project": "baiducloud-py",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "baiducloud"
}