golang尝试图片识别OCR库tesseract使用
我测试使用的是在macox下
终端执行命令安装包
brew update brew install leptonica brew install tesseract brew install tesseract-lang go get github.com/otiai10/gosseract
main.go
package
"github.com/otiai10/gosseract/v2"
client := gosseract.NewClient() defer client.Close() client.SetImage("/Users/xxx/Downloads/xxx.jpg") client.SetLanguage("chi_sim") text, _ := client.Text() //fmt.Println(text) reg := regexp.MustCompile("验证码: [^ ]*\\s") yzmStr := reg.FindAllString(text, 1) fmt.Println(yzmStr) yzmSlice := strings.Split(text, "验证码: ") fmt.Println(yzmSlice[1])