Created
October 17, 2017 17:04
-
-
Save deekoder/1f359c07b315acb0760f15a2550d4058 to your computer and use it in GitHub Desktop.
Lambda Function to do OCR and Barcode analysis
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
func processOCR(minioClient *minio.Client, bucketname string, objectname string) string {\ | |
// This is the simplest way :) | |
object, err := minioClient.GetObject(bucketname, objectname, minio.GetObjectOptions{}) | |
if err != nil { | |
fmt.Println(err) | |
return "" | |
} | |
localFile, err := os.Create("/tmp/" + objectname) | |
if err != nil { | |
fmt.Println(err) | |
return "" | |
} | |
if _, err = io.Copy(localFile, object); err != nil { | |
fmt.Println(err) | |
return "" | |
} | |
// Using Tesseract - Opensource OCR | |
client, _ := gosseract.NewClient() | |
out, _ := client.Src(localFile.Name()).Out() | |
fin, _ := os.Open(localFile.Name()) | |
defer fin.Close() | |
//Using zBar - Opensource Barcode Reader // | |
src, _ := jpeg.Decode(fin) | |
img := barcode.NewImage(src) | |
scanner := barcode.NewScanner().SetEnabledAll(true) | |
symbols, _ := scanner.ScanImage(img) | |
for _, s := range symbols { | |
fmt.Println(s.Type.Name(), s.Data, s.Quality, s.Boundary) | |
out += s.Data | |
} | |
return out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment