Created
December 18, 2021 16:36
-
-
Save UBISOFT-1/4017d641c329159f8de3d203efc919e1 to your computer and use it in GitHub Desktop.
Google Cloud Vision OCR JSON Response Converter
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
# this script is updated in order to support for multi-threaded applications. | |
# $3 is a random md5 hash or a uuid.uuid4() object that enables gcvocr.sh to be used without having two overlapping files named temp.json | |
#!/bin/bash | |
#cd ~ | |
echo '{"requests":[{"image":{"content":"' > ./$3.json | |
openssl base64 -in $1 | cat >> ./$3.json | |
echo '"}, | |
"features":{"type":"TEXT_DETECTION","maxResults":2048}}]}' >> ./$3.json | |
curl -k -s -H "Content-Type: application/json" https://vision.googleapis.com/v1/images:annotate?key=$2 --data-binary @./$3.json > "$1.json" | |
rm ./$3.json |
Author
UBISOFT-1
commented
Dec 18, 2021
Single Threaded Mode
In single threaded mode as shown above we can go ahead and convert the file with little to no problem.
Multi-Threaded Mode
In order to go ahead and run the script in the Multi-Threaded Mode we can go ahead and do the following bash command to generate a hash that is random in order to go ahead and run the script from the terminal.
./gcvocr.sh ./program_work/27b6db7ac84649e57ed059d0c5b8ebd7/final_images/1.jpeg "xxxxxxxxxxxxxxxxxxxxx" "$RANDOM"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment