Skip to content

Instantly share code, notes, and snippets.

@deekoder
Created October 17, 2017 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deekoder/1f359c07b315acb0760f15a2550d4058 to your computer and use it in GitHub Desktop.
Save deekoder/1f359c07b315acb0760f15a2550d4058 to your computer and use it in GitHub Desktop.
Lambda Function to do OCR and Barcode analysis
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