12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #!/usr/bin/env python
- # -*- encoding: utf-8 -*-
- '''
- @Author : liuyuqi
- @Contact : liuyuqi.gov@msn.cn
- @Time : 2020/02/17 22:13:38
- @Version : 1.0
- @License : Copyright © 2017-2020 liuyuqi. All Rights Reserved.
- @Desc : ocr 文字识别
- '''
- import base64
- import json,os,sys,re,requests
- import user_agent
- class OcrUtils():
- def __init__(self):
- pass
- def ocrImg(self, imgData, ocrType):
- if ocrType == 0:
- return self.bdGeneralOcr(imgData)
- elif ocrType == 1:
- return self.bdAccurateOcr(imgData)
- elif ocrType == 1:
- return self.sogouMobileOcr(imgData)
- else:
- return self.sogouWebOcr(imgData)
- def bdGeneralOcr(self, imgData):
- return self.bdBaseOcr(imgData, "general_location")
- def sogouMobileOcr(self, imgData):
- pass
- def bdAccurateOcr(self, imgData):
- self.bdBaseOcr(imgData, "https://aip.baidubce.com/rest/2.0/ocr/v1/accurate")
- data={}
- res=requests.post(url=url,data=data,headers=user_agent.getheaders()).content.decode("utf8")
- def sogouWebOcr(self, imgData):
- url = "https://deepi.sogou.com/api/sogouService"
- referer = "https://deepi.sogou.com/?from=picsearch&tdsourcetag=s_pctim_aiomsg"
- imageData = base64.encode(imgData)
- def bdBaseOcr(self, imgData, param):
- urlArr = ["http://ai.baidu.com/tech/ocr/general", "http://ai.baidu.com/index/seccode?action=show"]
- if __name__ == '__main__':
- test=OcrUtils()
- print(test.sogouWebOcr())
|