🧾 泰国收据OCR
1 IC每页
欢迎使用泰国收据OCR API,这是由艾艾普科技有限公司开发的一款AI驱动解决方案,用于从泰国收据和发票中提取数据。本文档将帮助您有效地集成和使用我们的OCR服务。
入门指南
-
先决条件
- 来自艾艾普科技的API密钥
- 打印或手写的泰国/英文收据图像
- 支持的文件格式:JPEG、JPG、PNG、HEIC、HEIF 、PDF
- 最大文件大小:10MB
-
快速开始
- 快速处理(每份文件5-10秒)
- 高精度文本提取
- 支持多种文件格式
-
主要功能
- 详细字段提取,包括:
- 发票详情(类型、ID、日期、账簿编号)
- 发行人信息(名称、地址、税号、联系方式)
- 客户信息(名称、地址、税号、联系方式)
- 行项详情(商品代码、名称、数量、单价、总价)
- 财务汇总(小计、折扣、增值税、总计)
- 支持单页和多页文档(PDF)
- 可选返回原始OCR文本和处理后的图像
- 灵活的JSON响应格式,提供详细的字段提取
- 详细字段提取,包括:
-
安全与合规
- 符合GDPR和PDPA
- 安全的API端点
- 处理后不保留数据
我们的API旨在处理泰国常用的各种收据格式和布局,从简单的零售收据到正式的税务发票。后期处理AI模型经过训练,能够理解泰国收据结构,即使是嘈杂或扫描质量不佳的文档也能可靠地提取信息。
示例
以下是一份示例收据及其提取的数据:
请求:
cURL
curl -X POST "https://api.iapp.co.th/ocr/v3/receipt/file" \
-H "apikey: YOUR_API_KEY" \
-F "file=@/path/to/receipt.jpg" \
-F "return_image=false" \
-F "return_ocr=false"
API端点
| 端点 | 方法 | 描述 | 费用 |
|---|---|---|---|
/v3/store/ocr/receipt/ocr/v3/receipt | POST | 从泰国收据和发票中提取数据 | 每页1 IC |
响应:
{
"message": "success",
"processed": {
"invoiceType": "ใบเสร็จรับเงิน/ใบกำกับภาษีอย่างย่อ",
"invoiceBook": null,
"invoiceID": "4504RC112566/004044",
"invoiceDate": "27/11/2566",
"issuerName": "หจก.บุญรอดคอฟฟี (ตลาดรัตนบุรี)",
"issuerTaxID": "0323560000723",
"items": [
{
"itemNo": 1,
"itemName": "ชาเขียวนม ร้อน ขนาดใหญ่",
"itemUnit": 1,
"itemUnitCost": 60.0,
"itemTotalCost": 60.0
}
],
"totalCost": 60.0,
"discount": 0.0,
"totalCostAfterDiscount": 60.0,
"vat": 3.93,
"grandTotal": 60.0
},
"process_ms": 6821
}
功能与能力
核心功能
-
文档处理
- 高精度文本提取和 字段识别
- 支持泰语/英语。
- 支持打印/手写。
- 快速处理时间,每份文件5-10秒
- 多格式支持(JPEG、JPG、PNG、HEIC、HEIF、PDF)
- 多页文档处理
- 可选返回原始OCR文本和处理后的图像
- 符合GDPR和PDPA的处理
-
数据提取
- 灵活的JSON响应格式,提供详细的字段提取
支持的字段
| 字段 | 类型 | 描述 |
|---|---|---|
| invoiceType | String | 发票的标题或类型 |
| invoiceBook | String | 发票的账簿编号 |
| invoiceID | String | 发票的ID号 |
| invoiceDate | String | 发票开具日期 |
| purchaseOrderID | String | 关联采购订单的ID号 |
| issuerName | String | 发票发行人名称 |
| issuerAddress | String | 发票发行人地址 |
| issuerTaxID | String | 发票发行人税号 |
| issuerPhone | String | 发票发行人联系电话 |
| customerName | String | 客户名称 |
| customerAddress | String | 客户地址 |
| customerTaxID | String | 客户税号 |
| customerPhone | String | 客户联系电话 |
| items | Array | 行项数组,包含以下详情 |
| - itemNo | String | 行项序列号 |
| - itemCode | String | 产品/服务代码 |
| - itemName | String | 产品/服务名称 |
| - itemUnit | Number | 行项数量 |
| - itemUnitCost | Number | 每单位成本 |
| - itemTotalCost | Number | 此行项的总成本 |
| totalCost | Number | 所有行项成本的总和 |
| discount | Number | 折扣金额(如果适用) |
| totalCostAfterDiscount | Number | 应用折扣后的总成本 |
| vat | Number | 增值税金额(7%) |
| grandTotal | Number | 含增值税的最终总金额 |
注意:所有货币值均四舍五入到小数点后两位。
API参考
欢迎使用泰国收据OCR API,这是一个将泰国收据和发票转换为结构化JSON数据的强大工具。该API利用先进的OCR和AI技术来提取关键信息,如发票详情、发行人和客户数据、行项以及财务总计。
识别收据
有两种端点可用于处理收据:
1. 文件上传
POST https://api.iapp.co.th/ocr/v3/receipt/file
请求头
| 名称 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| apikey | string | 是 | 您的API密钥 |
请求正文 (multipart/form-data)
| 参数 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| file | file | 是 | 收据图像 (JPEG, PNG) 或 PDF 文档 |
| return_image | boolean | 否 | 在响应中包含base64编码的图像 (默认:false) |
| return_ocr | boolean | 否 | 在响应中包含原始OCR文本 (默认:false) |
支持的文件类型
- 图像:JPEG, PNG
- 文档:PDF(单页或多页)
响应格式
{
"message": "success",
"raw": {
"image": "string", // Base64 编码,仅当 return_image=true 时返回
"text": "string" // 仅当 return_ocr=true 时返回
},
"processed": {
"invoiceType": "string",
"invoiceBook": "string",
"invoiceID": "string",
"invoiceDate": "string",
"purchaseOrderID": "string",
"issuerName": "string",
"issuerAddress": "string",
"issuerTaxID": "string",
"issuerPhone": "string",
"customerName": "string",
"customerAddress": "string",
"customerTaxID": "string",
"customerPhone": "string",
"items": [
{
"itemNo": "string",
"itemCode": "string",
"itemName": "string",
"itemUnit": "number",
"itemUnitCost": "number",
"itemTotalCost": "number"
}
],
"totalCost": "number",
"discount": "number",
"totalCostAfterDiscount": "number",
"vat": "number",
"grandTotal": "number"
},
"template": "receipt",
"iapp": "string",
"process_ms": "number"
}
错误处理
| 状态 | 代码 | 描述 |
|---|---|---|
| 400 | BAD_REQUEST | 参数或文件格式无效 |
| 401 | UNAUTHORIZED | API密钥无效或缺失 |
| 404 | NOT_FOUND | 端点无效 |
| 500 | INTERNAL_SERVER_ERROR | 处理失败 |
2. Base64 图像
POST https://api.iapp.co.th/ocr/v3/receipt/base64
请求头
| 名称 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| apikey | string | 是 | 您的API密钥 |
请求正文
您可以通过JSON或表单数据发送base64数据:
JSON 格式:
{
"base64_string": "string", // Base64 编码的图像数据
"return_image": false, // 可选
"return_ocr": false // 可选
}
表单数据格式:
| 参数 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| base64_string | string | 是 | Base64 编码的图像数据 |
| return_image | boolean | 否 | 在响应中包含base64编码的图像 (默认:false) |
| return_ocr | boolean | 否 | 在响应中包含原始OCR文本 (默认:false) |
响应格式
与文件上传端点相同
代码示例
Curl
curl -X POST https://api.iapp.co.th/v3/store/ocr/receipt \
-H "apikey: YOUR_API_KEY" \
-F "file=@/path/to/file.jpg"
Python (文件上传)
import requests
apiKey = 'YOUR_API_KEY'
filePath = '/path/to/receipt.jpg'
url = "https://api.iapp.co.th/ocr/v3/receipt/file"
headers = {'apikey': apiKey}
files = {'file': ('receipt.jpg', open(filePath, 'rb'), 'image/jpeg')}
data = {'return_image': 'false', 'return_ocr': 'false'}
response = requests.post(url, headers=headers, files=files, data=data)
print(response.json())
Python (Base64)
import requests
import base64
apiKey = 'YOUR_API_KEY'
url = "https://api.iapp.co.th/ocr/v3/receipt/base64"
# 读取图像文件并转换为base64
with open('/path/to/receipt.jpg', 'rb') as image_file:
base64_string = base64.b64encode(image_file.read()).decode()
headers = {
'apikey': apiKey,
'Content-Type': 'application/json'
}
data = {
'base64_string': base64_string,
'return_image': False,
'return_ocr': False
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
Javascript (文件上传)
const axios = require("axios")
const FormData = require("form-data")
const fs = require("fs")
const apiKey = "YOUR_API_KEY"
const filePath = "/path/to/receipt.jpg"
const url = "https://api.iapp.co.th/ocr/v3/receipt/file"
const form = new FormData()
form.append("file", fs.createReadStream(filePath))
form.append("return_image", "false")
form.append("return_ocr", "false")
try {
const response = await axios.post(url, form, {
headers: {
...form.getHeaders(),
apikey: apiKey,
},
})
return response.data
} catch (error) {
throw error
}
Javascript (Base64)
const axios = require("axios")
const fs = require("fs")
const apiKey = "YOUR_API_KEY"
const url = "https://api.iapp.co.th/ocr/v3/receipt/base64"
// 读取图像文件并转换为base64
const base64String = fs.readFileSync("/path/to/receipt.jpg", { encoding: "base64" })
const data = {
base64_string: base64String,
return_image: false,
return_ocr: false,
}
try {
const response = await axios.post(url, data, {
headers: {
"Content-Type": "application/json",
apikey: apiKey,
},
})
return response.data
} catch (error) {
throw error
}
PHP (文件上传)
$url = 'https://api.iapp.co.th/ocr/v3/receipt/file';
$apiKey = 'YOUR_API_KEY';
$filePath = '/path/to/receipt.jpg';
$headers = array(
'apikey: ' . $apiKey
);
$postFields = array(
'file' => new CURLFile($filePath),
'return_image' => 'false',
'return_ocr' => 'false'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
PHP (Base64)
<?php
$url = 'https://api.iapp.co.th/ocr/v3/receipt/base64';
$apiKey = 'YOUR_API_KEY';
$filePath = '/path/to/receipt.jpg';
// 读取图像文件并转换为base64
$base64String = base64_encode(file_get_contents($filePath));
$data = array(
'base64_string' => $base64String,
'return_image' => false,
'return_ocr' => false
);
$headers = array(
'Content-Type: application/json',
'apikey: ' . $apiKey
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
Swift (文件上传)
import Foundation
let url = URL(string: "https://api.iapp.co.th/ocr/v3/receipt/file")!
let filePath = "/path/to/receipt.jpg"
let apiKey = "YOUR_API_KEY"
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue(apiKey, forHTTPHeaderField: "apikey")
let boundary = UUID().uuidString
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
var body = Data()
body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"file\"; filename=\"receipt.jpg\"\r\n".data(using: .utf8)!)
body.append("Content-Type: image/jpeg\r\n\r\n".data(using: .utf8)!)
body.append(try! Data(contentsOf: URL(fileURLWithPath: filePath)))
body.append("\r\n--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"return_image\"\r\n\r\nfalse\r\n".data(using: .utf8)!)
body.append("--\(boundary)\r\n".data(using: .utf8)!)
body.append("Content-Disposition: form-data; name=\"return_ocr\"\r\n\r\nfalse\r\n".data(using: .utf8)!)
body.append("--\(boundary)--\r\n".data(using: .utf8)!)
request.httpBody = body
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data, error == nil else {
print("Error: \(error?.localizedDescription ?? "Unknown error")")
return
}
print(String(data: data, encoding: .utf8)!)
}
task.resume()
Swift (Base64)
import Foundation
let url = URL(string: "https://api.iapp.co.th/ocr/v3/receipt/base64")!
let filePath = "/path/to/receipt.jpg"
let apiKey = "YOUR_API_KEY"
// 读取图像文件并转换为base64
guard let imageData = try? Data(contentsOf: URL(fileURLWithPath: filePath)) else {
print("Error reading file")
return
}
let base64String = imageData.base64EncodedString()
let parameters: [String: Any] = [
"base64_string": base64String,
"return_image": false,
"return_ocr": false
]
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue(apiKey, forHTTPHeaderField: "apikey")
request.httpBody = try? JSONSerialization.data(withJSONObject: parameters)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data, error == nil else {
print("Error: \(error?.localizedDescription ?? "Unknown error")")
return
}
print(String(data: data, encoding: .utf8)!)
}
task.resume()
Kotlin (文件上传)
import okhttp3.*
import java.io.File
val client = OkHttpClient()
val apiKey = "YOUR_API_KEY"
val filePath = "/path/to/receipt.jpg"
val url = "https://api.iapp.co.th/ocr/v3/receipt/file"
val file = File(filePath)
val requestBody = MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", file.name, RequestBody.create(MediaType.parse("image/jpeg"), file))
.addFormDataPart("return_image", "false")
.addFormDataPart("return_ocr", "false")
.build()
val request = Request.Builder()
.url(url)
.post(requestBody)
.addHeader("apikey", apiKey)
.build()
client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
e.printStackTrace()
}
override fun onResponse(call: Call, response: Response) {
response.use {
if (!response.isSuccessful) throw IOException("Unexpected code $response")
println(response.body()?.string())
}
}
})
Kotlin (Base64)
import okhttp3.*
import java.io.File
import android.util.Base64
import org.json.JSONObject
fun processBase64Image() {
val client = OkHttpClient()
val apiKey = "YOUR_API_KEY"
val filePath = "/path/to/receipt.jpg"
val url = "https://api.iapp.co.th/ocr/v3/receipt/base64"
// 读取文件并转换为base64
val file = File(filePath)
val bytes = file.readBytes()
val base64String = Base64.encodeToString(bytes, Base64.DEFAULT)
val json = JSONObject()
json.put("base64_string", base64String)
json.put("return_image", false)
json.put("return_ocr", false)
val requestBody = RequestBody.create(
MediaType.parse("application/json"),
json.toString()
)
val request = Request.Builder()
.url(url)
.post(requestBody)
.addHeader("Content-Type", "application/json")
.addHeader("apikey", apiKey)
.build()
client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
e.printStackTrace()
}
override fun onResponse(call: Call, response: Response) {
response.use {
if (!response.isSuccessful) throw IOException("Unexpected code $response")
println(response.body()?.string())
}
}
})
}
Java (文件上传)
import okhttp3.*;
import java.io.File;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
OkHttpClient client = new OkHttpClient();
String apiKey = "YOUR_API_KEY";
String url = "https://api.iapp.co.th/ocr/v3/receipt/file";
String filePath = "/path/to/receipt.jpg";
File file = new File(filePath);
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", file.getName(), RequestBody.create(MediaType.parse("image/jpeg"), file))
.addFormDataPart("return_image", "false")
.addFormDataPart("return_ocr", "false")
.build();
Request request = new Request.Builder()
.url(url)
.post(requestBody)
.addHeader("apikey", apiKey)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
System.out.println(response.body().string());
}
});
}
}
Java (Base64)
import okhttp3.*;
import java.io.File;
import java.io.IOException;
import java.util.Base64;
import java.nio.file.Files;
import org.json.JSONObject;
public class Main {
public static void main(String[] args) {
OkHttpClient client = new OkHttpClient();
String apiKey = "YOUR_API_KEY";
String url = "https://api.iapp.co.th/ocr/v3/receipt/base64";
String filePath = "/path/to/receipt.jpg";
try {
// 读取文件并转换为base64
byte[] fileContent = Files.readAllBytes(new File(filePath).toPath());
String base64String = Base64.getEncoder().encodeToString(fileContent);
JSONObject json = new JSONObject();
json.put("base64_string", base64String);
json.put("return_image", false);
json.put("return_ocr", false);
RequestBody requestBody = RequestBody.create(
MediaType.parse("application/json"),
json.toString()
);
Request request = new Request.Builder()
.url(url)
.post(requestBody)
.addHeader("Content-Type", "application/json")
.addHeader("apikey", apiKey)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
System.out.println(response.body().string());
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
Dart (文件上传)
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
String url = 'https://api.iapp.co.th/ocr/v3/receipt/file';
String filePath = '/path/to/receipt.jpg';
String apiKey = 'YOUR_API_KEY';
void main() async {
var url = Uri.parse(url);
var request = http.MultipartRequest('POST', url)
..headers['apikey'] = apiKey
..files.add(await http.MultipartFile.fromPath('file', filePath))
..fields['return_image'] = 'false'
..fields['return_ocr'] = 'false';
var response = await request.send();
if (response.statusCode == 200) {
var responseData = await response.stream.bytesToString();
print(responseData);
} else {
print('Error: ${response.statusCode}');
}
}
Dart (Base64)
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
void main() async {
String url = 'https://api.iapp.co.th/ocr/v3/receipt/base64';
String filePath = '/path/to/receipt.jpg';
String apiKey = 'YOUR_API_KEY';
try {
// 读取文件并转换为base64
File file = File(filePath);
List<int> fileBytes = await file.readAsBytes();
String base64String = base64Encode(fileBytes);
Map<String, dynamic> data = {
'base64_string': base64String,
'return_image': false,
'return_ocr': false
};
var response = await http.post(
Uri.parse(url),
headers: {
'Content-Type': 'application/json',
'apikey': apiKey
},
body: jsonEncode(data)
);
if (response.statusCode == 200) {
print(response.body);
} else {
print('Error: ${response.statusCode}');
}
} catch (e) {
print('Error: $e');
}
}
限制与最佳实践
限制
- 最大文件 大小:10MB
- 支持语言:泰语
- PDF文件:最多10页
- 速率限制:每个API密钥每秒10个请求
最佳实践
- 确保图像质量以获得最佳结果
- 图像格式请使用JPEG或PNG
- 对失败的请求实现错误处理
- 处理同一文档多次时,缓存响应
- 为大文件设置适当的超时时间
准确性与性能
整体准确性
基于我们10,000份泰国收据的基准数据集:
| 字段类型 | 准确率 (%) | 备注 |
|---|---|---|
| 发票号码 | 99.2% | 包括税务发票号码 |
| 金额 | 99.5% | 货币值和总计 |
| 日期 | 98.7% | 各种泰国日期格式 |
| 行项 | 97.8% | 产品详情和价格 |
| 总体 | 98.8% | 加权平均 |
处理速度
- 平均处理时间:5-10秒
- 95%百分位数:12秒
- 最长处理时间:15秒
影响准确性的因素
-
图像质量
- 分辨率(建议最低300 DPI)
- 光照条件
- 图像聚焦和清晰度
-
文档状况
- 物理损坏
- 褪色或磨损
- 手写修改
-
收据格式
- 标准格式:99%+ 准确率
- 非标准布局:95%+ 准确率
- 手写元素:90%+ 准确率
历史记录
我们的模型会不断用新数据进行训练以提高准确性:
| 版本 | 发布日期 | 准确率 | 主要改进 |
|---|---|---|---|
| 3.0 | 2024-12-27 | 96.5% | 基础版本 |
定价
| AI API服务名称 | 端点 | 定价 | 本地部署 |
|---|---|---|---|
| 收据OCR [v1.0] | receipt-ocr | 1 IC/页 | 联系我们 |