首页 > 其他分享 >TextIn.com API使用心得

TextIn.com API使用心得

时间:2024-04-14 12:33:59浏览次数:29  
标签:__ TextIn code img self ti API ._ com

我们参加了本次大学生创新创业服务外包大赛,在项目中大量使用到了合合信息所提供的api进行相关功能实现,所以在这里写一篇博客分享一下我们在项目的实际推进中关于TextIn.com API使用心得

我们的产品是一款面向公司管理的REP微信小程序,由于需要覆盖大部分的企业办公需求,我们使用到了大量的API,进行功能实现,这里列举四个使用的比较多的API功能进行讲解和展示

一、通用文字识别

首先是最常用的通用文字识别功能,即识别图片上的的文字并进行输出,实现代码如下:

import requests
import json

def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

class CommonOcr(object):
    def __init__(self, img_path):
        self._app_id = '******************************'
        self._secret_code = '********************************'
        self._img_path = img_path

    def recognize(self):
        url = 'https://api.textin.com/ai/service/v2/recognize'
        head = {}
        texts = []
        try:
            image = get_file_content(self._img_path)
            head['x-ti-app-id'] = self._app_id
            head['x-ti-secret-code'] = self._secret_code
            response = requests.post(url, data=image, headers=head)
            results = json.loads(response.text)
            for line in results['result']['lines']:
                texts.append(line['text'])
            return texts
        except Exception as e:
            return str(e)

if __name__ == "__main__":
    response = CommonOcr(r'img.png')
    print(response.recognize())

实现效果如下:

 二、车牌号识别

在公司管理中,公司的汽车管理是企业业务的常见组成部分,所以我们在小程序中加入公车管理的功能,其中汽车的登记任务就是通过车牌识别的api进行实现的,实现代码如下:

import requests
import json

def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

class CommonOcr(object):
    def __init__(self, img_path):
        # 请登录后前往 “工作台-账号设置-开发者信息” 查看 x-ti-app-id
        # 示例代码中 x-ti-app-id 非真实数据
        self._app_id = '****************************'
        # 请登录后前往 “工作台-账号设置-开发者信息” 查看 x-ti-secret-code
        # 示例代码中 x-ti-secret-code 非真实数据
        self._secret_code = '*******************************'
        self._img_path = img_path

    def recognize(self):
        # 车牌号识别
        url = 'https://api.textin.com/robot/v1.0/api/plate_number'
        head = {}
        try:
            image = get_file_content(self._img_path)
            head['x-ti-app-id'] = self._app_id
            head['x-ti-secret-code'] = self._secret_code
            result = requests.post(url, data=image, headers=head)
            return result.text
        except Exception as e:
            return e

if __name__ == "__main__":
    response = CommonOcr(r'img_1.png')
    print(response.recognize())

实现效果如下:

 

 三、票据识别

企业业务流程中,票据识别是一个很重要的事务,票据识别的效率很大程度上会影响到整体报销流程的效率,所以一个精确高效的票据识别功能是不可或缺的。我们的实现代码如下:

import requests
import json

def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

class CommonOcr(object):
    def __init__(self, img_path):
        self._app_id = '**********************************'
        self._secret_code = '***********************************'
        self._img_path = img_path

    def recognize(self):
        url = 'https://api.textin.com/robot/v1.0/api/bills_crop'
        head = {}
        result_formatted = []
        try:
            image = get_file_content(self._img_path)
            head['x-ti-app-id'] = self._app_id
            head['x-ti-secret-code'] = self._secret_code
            response = requests.post(url, data=image, headers=head)
            results = json.loads(response.text)
            if "result" in results and "object_list" in results["result"]:
                for item in results["result"]["object_list"]:
                    if "item_list" in item:
                        for field in item["item_list"]:
                            result_formatted.append(field["key"] + ": " + field["value"])
                            result_formatted.append("")  # Adds an empty line
            return "\n".join(result_formatted)
        except Exception as e:
            return str(e)

if __name__ == "__main__":
    response = CommonOcr(r'img_2.png')
    print(response.recognize())

实现效果如下:

 

 四、名片识别

名片是员工管理的重要依据,我们的小程序也通过名片识别实现了公司员工的登记和管理,名片识别代码如下:

import requests
import json

def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

class CommonOcr(object):
    def __init__(self, img_path):
        # 请登录后前往 “工作台-账号设置-开发者信息” 查看 x-ti-app-id
        # 示例代码中 x-ti-app-id 非真实数据
        self._app_id = '***************************'
        # 请登录后前往 “工作台-账号设置-开发者信息” 查看 x-ti-secret-code
        # 示例代码中 x-ti-secret-code 非真实数据
        self._secret_code = '***************************'
        self._img_path = img_path

    def recognize(self):
        # 名片识别
        url = 'https://api.textin.com/robot/v1.0/api/business_card'
        head = {}
        try:
            image = get_file_content(self._img_path)
            head['x-ti-app-id'] = self._app_id
            head['x-ti-secret-code'] = self._secret_code
            result = requests.post(url, data=image, headers=head)
            return result.text
        except Exception as e:
            return e

if __name__ == "__main__":
    response = CommonOcr(r'img_3.png')
    print(response.recognize())

实现效果如下:

 

 除上面的api外,合合信息还有很多丰富的面向办公需求的api端口,并且有免费额度,推荐大家进行使用。

 

标签:__,TextIn,code,img,self,ti,API,._,com
From: https://www.cnblogs.com/wangxiaomeidegou/p/18133992

相关文章

  • 10-接口测试工具(PostMan和ApiPost)
    在前后端分离的开发模式下,通常需要使用接口测试工具进行开发,这里介绍两种比较好用的1)PostManPostman是一款功能强大的网页调试与发送网页HTTP请求的Chrome插件,常用于接口测试官方下载网址:DownloadPostman|GetStartedforFree安装教程:PostMan——安装使用教程(图文详解)_po......
  • Control Panel Command Line Commands in Windows
    CMDCommandsforControlPanelAppletsAppletCommandOSVersionAccessibilityOptionscontrolaccess.cplXPActionCentercontrol/nameMicrosoft.ActionCenter8,7 controlwscui.cpl8,7AddFeaturestoWindows8control/nameMicrosoft.Win......
  • FastAPI-MySQL-Cookie代码实现
    连接数据库fromsqlalchemyimportcreate_enginefromsqlalchemy.ext.declarativeimportdeclarative_basefromsqlalchemy.ormimportsessionmakerfromurllib.parseimportquote_pluspassword='123456'encoded_password=quote_plus(password)SQLALCHEM......
  • 实验一-密码引擎-3-加密API研究
    任务要求密码引擎API的主要标准和规范包括:1微软的CryptoAPI2RAS公司的PKCS#11标准3中国商用密码标准:GMT0016-2012智能密码钥匙密码应用接口规范,GMT0018-2012密码设备应用接口规范等研究以上API接口,总结他们的异同,并以龙脉GM3000Key为例,写出调用不同接口的代码,提交博客......
  • 密码引擎-加密API研究
    任务详细密码引擎API的主要标准和规范包括:1微软的CryptoAPI2RAS公司的PKCS#11标准3中国商用密码标准:GMT0016-2012智能密码钥匙密码应用接口规范,GMT0018-2012密码设备应用接口规范等研究以上API接口,总结他们的异同,并以龙脉GM3000Key为例,写出调用不同接口的代码,提交......
  • 实验一-密码引擎-3-加密API研究
    一、微软的CryptoAPI参考网站:https://learn.microsoft.com/zh-cn/windows/win32/seccrypto/cryptoapi-system-architecturehttps://developer.mozilla.org/zh-CN/docs/Web/API/Web_Crypto_APIhttps://www.w3.org/TR/2017/REC-WebCryptoAPI-20170126/https://blog.csdn.net/l......
  • CommandNotFoundError: Your shell has not been properly configured to use 'conda
    当使用condaactivatemy_env激活环境时,可能会遇到如下错误:CommandNotFoundError:Yourshellhasnotbeenproperlyconfiguredtouse'condaactivate'.Toinitializeyourshell,run$condainit<SHELL_NAME>Currentlysupportedshellsare:-bash......
  • COMP7250 用神经网络进行简单分类
    COMP7250的编程赋值欢迎参加COMP7250的课业!本课业由两部分组成:第1部分:用神经网络进行简单分类第2部分:神经网络的对抗性例子。通过尝试此任务,您将对以下内容有一个简要的了解:如何处理数据;如何建立一个简单的网络;向前和向后传播的机制;如何使用FGSM和PGD方法生成对抗性示例。注意:尽管......
  • 02_Web Api使用Jwt
    JWT(JSONWebToken)是一种用于在网络应用之间传递信息的开放标准(RFC7519)。它使用JSON对象在安全可靠的方式下传递信息,通常用于身份验证和信息交换。在WebAPI中,JWT通常用于对用户进行身份验证和授权。当用户登录成功后,服务器会生成一个Token并返回给客户端,客户端在接下来的请求......
  • Git 提交 Umi Max 项目报错:Invalid commit message format
    Git提交UmiMax项目报错:Invalidcommitmessageformat1、发现问题使用UmiMax构建的项目,commit(提交)时报错!.2、分析问题⚠️提交信息需要满足某些固定的消息格式。1、项目根目录的.umirc.ts文件中verifyCommit属性用于验证commitmessage信息。.2、配置文件......