Compare commits
No commits in common. "2a527b509e4495bfc40366de80c6208d65f90c27" and "8979b754ddbac600f8e5744ffe96b9923505bc45" have entirely different histories.
2a527b509e
...
8979b754dd
15
ocr.sh
15
ocr.sh
@ -1,20 +1,18 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
INPUT_IMAGE=$1
|
INPUT_IMAGE=$1
|
||||||
|
|
||||||
raw_text=$(tesseract $INPUT_IMAGE stdout --psm 6)
|
raw_text=$(tesseract $INPUT_IMAGE stdout)
|
||||||
|
|
||||||
referece=$(echo "$raw_text" | grep -o 'BLAZ[0-9]*')
|
referece=$(echo "$raw_text" | grep -o 'BLAZ[0-9]*')
|
||||||
to_number=$(echo "$raw_text" | grep -oE '\b9[0-9]{16}\b|\b7[0-9]{12}\b')
|
to_number=$(echo "$raw_text" | grep -oE '\b9[0-9]{16}\b|\b7[0-9]{12}\b')
|
||||||
#date=$(echo "$raw_text" | grep -oE '\b[0-3][0-9]/[0-1][0-9]/[0-9]{4}\b')
|
date=$(echo "$raw_text" | grep -oE '\b[0-3][0-9]/[0-1][0-9]/[0-9]{4}\b')
|
||||||
#time=$(echo "$raw_text" | grep -oE '\b[0-2][0-9]:[0-5][0-9]\b')
|
time=$(echo "$raw_text" | grep -oE '\b[0-2][0-9]:[0-5][0-9]\b')
|
||||||
date=$(echo "$raw_text" | grep -oE '[0-3][0-9]/[0-1][0-9]/[0-9]{4}')
|
|
||||||
time=$(echo "$raw_text" | grep -oE '[0-2][0-9]:[0-5][0-9]')
|
|
||||||
currency=$(echo "$raw_text" | grep -oP '(?<=Amount\s)[A-Z]{3}')
|
currency=$(echo "$raw_text" | grep -oP '(?<=Amount\s)[A-Z]{3}')
|
||||||
amount=$(echo "$raw_text" | grep -oP '(?<=Amount\s[A-Z]{3}\s)[0-9]{1,3}(?:,[0-9]{3})*(?:\.[0-9]{2})')
|
amount=$(echo "$raw_text" | grep -oP '(?<=Amount\s[A-Z]{3}\s)[0-9]{1,3}(?:,[0-9]{3})*(?:\.[0-9]{2})')
|
||||||
status=$(echo "$raw_text" | grep -oP '(?<=Status\s)[A-Z]+')
|
|
||||||
|
|
||||||
json=$(cat <<EOF
|
json_output=$(cat <<EOF
|
||||||
{
|
{
|
||||||
"Amount": "$amount",
|
"Amount": "$amount",
|
||||||
"Currency": "$currency",
|
"Currency": "$currency",
|
||||||
@ -32,5 +30,4 @@ json=$(cat <<EOF
|
|||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
|
|
||||||
echo $json | jq
|
echo $json_output
|
||||||
echo $raw_text
|
|
||||||
|
47
splitv2.sh
47
splitv2.sh
@ -1,47 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
IMAGE_PATH=$1
|
|
||||||
IMAGE_HEIGHT=$(magick identify -format "%h" "$IMAGE_PATH")
|
|
||||||
IMAGE_WIDTH=$(magick identify -format "%w" "$IMAGE_PATH")
|
|
||||||
PART_HEIGHT=$((IMAGE_HEIGHT / 15))
|
|
||||||
|
|
||||||
# Loop to crop the image into 15 parts and perform OCR
|
|
||||||
for i in $(seq 0 14); do
|
|
||||||
OFFSET=$((i * PART_HEIGHT))
|
|
||||||
OCR_PART=$(magick "$IMAGE_PATH" -crop "${IMAGE_WIDTH}x${PART_HEIGHT}+0+${OFFSET}" - | tesseract - - stdout 2>/dev/null)
|
|
||||||
OCR_RESULTS="${OCR_RESULTS} ${OCR_PART}"
|
|
||||||
done
|
|
||||||
|
|
||||||
raw_text=$OCR_RESULTS
|
|
||||||
|
|
||||||
referece=$(echo "$raw_text" | grep -o 'BLAZ[0-9]*')
|
|
||||||
to_number=$(echo "$raw_text" | grep -oE '\b9[0-9]{16}\b|\b7[0-9]{12}\b')
|
|
||||||
#date=$(echo "$raw_text" | grep -oE '\b[0-3][0-9]/[0-1][0-9]/[0-9]{4}\b')
|
|
||||||
#time=$(echo "$raw_text" | grep -oE '\b[0-2][0-9]:[0-5][0-9]\b')
|
|
||||||
date=$(echo "$raw_text" | grep -oE '[0-3][0-9]/[0-1][0-9]/[0-9]{4}')
|
|
||||||
time=$(echo "$raw_text" | grep -oE '[0-2][0-9]:[0-5][0-9]')
|
|
||||||
currency=$(echo "$raw_text" | grep -oP '(?<=Amount\s)[A-Z]{3}')
|
|
||||||
amount=$(echo "$raw_text" | grep -oP '(?<=Amount\s[A-Z]{3}\s)[0-9]{1,3}(?:,[0-9]{3})*(?:\.[0-9]{2})')
|
|
||||||
status=$(echo "$raw_text" | grep -oP '(?<=Status\s)[A-Z]+')
|
|
||||||
from=$(echo "$raw_text" | grep -oP '(?<=From\s)[A-Z\s]+(?=\s[A-Z][a-z])')
|
|
||||||
|
|
||||||
json=$(cat <<EOF
|
|
||||||
{
|
|
||||||
"Amount": "$amount",
|
|
||||||
"Currency": "$currency",
|
|
||||||
"Date": "$date $time",
|
|
||||||
"From": "$from",
|
|
||||||
"Message": "$message",
|
|
||||||
"referece": "$referece",
|
|
||||||
"Remarks": "$remarks",
|
|
||||||
"Status": "$status",
|
|
||||||
"To": {
|
|
||||||
"Account": "$to_number",
|
|
||||||
"Name": "$to_name"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
|
|
||||||
echo $json | jq
|
|
||||||
echo $raw_text
|
|
Loading…
x
Reference in New Issue
Block a user