๐Ÿ“ฆ deluan / lookup

๐Ÿ“„ examples_ocr_test.go ยท 41 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41package lookup_test

import (
	"fmt"
	"image"
	"os"

	_ "image/png"

	"github.com/deluan/lookup"
)

// Helper function to load an image from the filesystem
func loadImageFromFile(imgPath string) image.Image {
	imageFile, _ := os.Open(imgPath)
	defer imageFile.Close()
	img, _, _ := image.Decode(imageFile)
	return img
}

func Example_ocr() {
	// Create an OCR object with an accuracy of 0.7
	ocr := lookup.NewOCR(0.7)

	// Load a fontSet
	_ = ocr.LoadFont("testdata/font_1")

	// Load an image to recognize
	img := loadImageFromFile("testdata/test3.png")

	// Recognize text in image
	text, _ := ocr.Recognize(img)

	// Print the results
	fmt.Printf("Text found in image: %s\n", text)

	// Output:
	// Text found in image: 3662
	// 3 2โ‚ฌ/โ‚ฌ
}