package main import ( //"flag" "fmt" ocr "github.com/otiai10/gosseract" "github.com/whitman-colm/go-lib/src/input" "io/ioutil" ) var ( image string output string ) /*func init() { st1 := `Path to the image to be OCR'd.` st2 := `Where to direct output of file. Leave blank to pipe to stdout.` flag.StringVar(&image, "i", "", st1) flag.StringVar(&output, "o", "", st2) flag.Parse() }*/ func main() { image := "" output := "" if image == "" { fmt.Println("Please provide the path to an image file.") fmt.Println("Accepted formats are .png, .jpeg, and .tiff.\n") fmt.Println("If you're not sure what a path is, drag an image file into this window.") image = input.StringInput("> ") } if output == "" { fmt.Println("Provide an output file (leave blank to print result to console)") output = input.StringInput("> ") } client := ocr.NewClient() defer client.Close() client.SetImage(image) text, err := client.Text() if err != nil { panic(err) } if output != "" { tAsByte := []byte(text) err = ioutil.WriteFile(output, tAsByte, 0644) if err != nil { panic(err) } } else { fmt.Println(text) _ = input.StringInput("press enter when done. ") } }