Created
August 18, 2018 04:45
-
-
Save altbdoor/7dcf4a0dc97daf473b1d64dbc973994c to your computer and use it in GitHub Desktop.
OCR image containing Chinese text with Convertio API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| echo "making request" | |
| make_req_data=$(cat <<JSONDATA | |
| { | |
| "apikey": "__insert api key__", | |
| "input": "upload", | |
| "outputformat": "txt", | |
| "options": { | |
| "ocr_enabled": true, | |
| "ocr_settings": { | |
| "langs": ["chi_sim"] | |
| } | |
| } | |
| } | |
| JSONDATA | |
| ) | |
| make_req=$(curl -s -i -X POST -d "${make_req_data}" http://api.convertio.co/convert) | |
| is_ok=$(echo $make_req | grep -c '"status":"ok"') | |
| if [[ $is_ok == 1 ]]; then | |
| req_id=$(echo $make_req | grep -oP '"id":".+?"' | sed 's/^".*":"//' | sed 's/"$//') | |
| echo "id is ${req_id}" | |
| echo "uploading file" | |
| upload_file="capture.png" | |
| upload_req=$(curl -s -i -X PUT --upload-file "${upload_file}" "http://api.convertio.co/convert/${req_id}/${upload_file}") | |
| echo -n "waiting" | |
| is_done=0 | |
| status_req="" | |
| while [[ $is_done == 0 ]]; do | |
| echo -n "." | |
| sleep 2 | |
| status_req=$(curl -s -i -X GET "http://api.convertio.co/convert/${req_id}/status") | |
| is_done=$(echo $status_req | grep -c '"step_percent":100') | |
| done | |
| echo "" | |
| echo "getting file" | |
| output_url=$(echo $status_req | grep -oP '"url":".+?"' | sed 's/^".*":"//' | sed 's/"$//' | sed 's/\\//g') | |
| curl -s "${output_url}" -o output.txt | |
| echo "cleanup" | |
| cleanup_req=$(curl -s -i -X DELETE "http://api.convertio.co/convert/${req_id}") | |
| else | |
| echo "error" | |
| echo $make_req | |
| fi | |
| echo "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment