willsonlincake 发表于 2022-4-5 11:03:46

Python调用ocrspace进行文字识别

import ocrspace
import requests


api = ocrspace.API()
TEST_IMAGE_URL = 'https://images-na.ssl-images-amazon.com/images/I/71ovNJN1URL._SL1244_.jpg'

print('Testing URL-based OCR:')
print(api.ocr_url(TEST_IMAGE_URL))

print('Testing file-based OCR:')
# Download image for demo purposes
TEST_FILENAME = '/tmp/test_image.jpg'
with open(TEST_FILENAME, 'wb') as f:
    r = requests.get(TEST_IMAGE_URL)
    r.raw.decode_content = True
    f.write(r.content)

# With file path
print(api.ocr_file(TEST_FILENAME))
# With file pointer
print(api.ocr_file(open(TEST_FILENAME, 'rb')))

https://github.com/ErikBoesen/ocrspace/blob/master/example.py
页: [1]
查看完整版本: Python调用ocrspace进行文字识别