Barcode
1. Trích xuất thông tin Barcode với đầu vào URL của ảnh hoặc pdf
API:
| Method | URL | 
|---|---|
| GET | https://demo.computervision.com.vn/api/v2/ocr/document/barcode_extract | 
Params:
| Key | Value | Mô tả | 
|---|---|---|
| img | https://example.com/image.png | URL của ảnh hoặc pdf | 
| format_type | url | Loại data truyền vào, nhận giá trị: url,file,base64 | 
| get_thumb | true/false | Trả về ảnh của Barcode đã được căn chỉnh | 
Demo Python:
import requestsapi_key = "YOUR_API_KEY"api_secret = "YOUR_API_SECRET"image_url = 'https://example.com/image.png'response = requests.get("https://demo.computervision.com.vn/api/v2/ocr/document/barcode_extract?img=%s&format_type=url&get_thumb=false"% image_url,auth=(api_key, api_secret))print(response.json())
2. Trích xuất thông tin Barcode với đầu vào file ảnh hoặc file pdf
API:
| Method | URL | content-type | 
|---|---|---|
| POST | https://demo.computervision.com.vn/api/v2/ocr/document/barcode_extract | multipart/form-data | 
Params:
| Key | Value | Mô tả | 
|---|---|---|
| format_type | file | Loại data truyền vào, nhận giá trị: url,file,base64 | 
| get_thumb | true/false | Trả về ảnh của Barcode đã được căn chỉnh | 
Body:
| Key | Type | Value | Mô tả | 
|---|---|---|---|
| img | file | example.jpg | File ảnh hoặc pdf của Barcode | 
Demo Python:
import requestsapi_key = "YOUR_API_KEY"api_secret = "YOUR_API_SECRET"image_path = '/path/to/your/image.jpg'response = requests.post("https://demo.computervision.com.vn/api/v2/ocr/document/barcode_extract?format_type=file&get_thumb=false",auth=(api_key, api_secret),files={'img': open(image_path, 'rb')})print(response.json())
3. Trích xuất thông tin Barcode với đầu vào JSON
API:
| Method | URL | content-type | 
|---|---|---|
| POST | https://demo.computervision.com.vn/api/v2/ocr/document/barcode_extract | application/json | 
Params:
| Key | Value | Mô tả | 
|---|---|---|
| format_type | base64 | Loại data truyền vào, nhận giá trị: url,file,base64 | 
| get_thumb | true/false | Trả về ảnh của Barcode đã được căn chỉnh | 
Body:
{"img": "iVBORw0KGgoAAAANSU..." // string base64 của ảnh hoặc pdf cần trích xuất}
Demo Python:
import base64import ioimport requestsfrom PIL import Imagedef get_byte_img(img):img_byte_arr = io.BytesIO()img.save(img_byte_arr, format='PNG')encoded_img = base64.encodebytes(img_byte_arr.getvalue()).decode('ascii')return encoded_imgapi_key = "YOUR_API_KEY"api_secret = "YOUR_API_SECRET"img_name = "path_img"encode_cmt = get_byte_img(Image.open(img_name))response = requests.post("https://demo.computervision.com.vn/api/v2/ocr/document/barcode_extract?format_type=base64&get_thumb=false",auth=(api_key, api_secret),json={'img' : encode_cmt})print(response.json())
4. Thông tin trả về
Thông tin trả về là một JSON với định dạng sau:
{"data": {"barcode": string, // Giá trị của Barcode"image": string // Ảnh barcode định dạng base64},"errorCode": string, // Mã lỗi"errorMessage": string // Thông báo lỗi}
Bảng mã lỗi:
| Mã lỗi | Message | Mô tả | 
|---|---|---|
| 0 | Success | Thành công | 
| 1 | Incorrect image format | Ảnh bị lỗi | 
| 2 | Url is unavailable | Link ảnh bị lỗi | 
| 3 | Incorrect image format | Ảnh không chứa nội dung | 
| 4 | Incorrect api_key or api_secret | api_key hoặc api_secret sai | 
| 5 | Out of requests | Hết số lượng requests hữu dụng | 
| 6 | Error when processing the request | Lỗi khi xử lý request |