mirror of
https://github.com/arnaucube/numberImgRecognition.git
synced 2026-02-07 03:26:45 +01:00
better output
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
media
|
||||
webapp
|
||||
57
goVersion/color.go
Normal file
57
goVersion/color.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
//Color struct, defines the color
|
||||
type Color struct{}
|
||||
|
||||
var c Color
|
||||
|
||||
//DarkGray color
|
||||
func (c Color) DarkGray(t string) {
|
||||
fmt.Print("\x1b[30;1m") //dark gray
|
||||
fmt.Println(t)
|
||||
fmt.Print("\x1b[0m") //defaultColor
|
||||
}
|
||||
|
||||
//Red color
|
||||
func (c Color) Red(t string) {
|
||||
fmt.Print("\x1b[31;1m") //red
|
||||
fmt.Println(t)
|
||||
fmt.Print("\x1b[0m") //defaultColor
|
||||
}
|
||||
|
||||
//Green color
|
||||
func (c Color) Green(t string) {
|
||||
fmt.Print("\x1b[32;1m") //green
|
||||
fmt.Println(t)
|
||||
fmt.Print("\x1b[0m") //defaultColor
|
||||
}
|
||||
|
||||
//Yellow color
|
||||
func (c Color) Yellow(t string) {
|
||||
fmt.Print("\x1b[33;1m") //yellow
|
||||
fmt.Println(t)
|
||||
fmt.Print("\x1b[0m") //defaultColor
|
||||
}
|
||||
|
||||
//Blue color
|
||||
func (c Color) Blue(t string) {
|
||||
fmt.Print("\x1b[34;1m") //blue
|
||||
fmt.Println(t)
|
||||
fmt.Print("\x1b[0m") //defaultColor
|
||||
}
|
||||
|
||||
//Purple color
|
||||
func (c Color) Purple(t string) {
|
||||
fmt.Print("\x1b[35;1m") //purple
|
||||
fmt.Println(t)
|
||||
fmt.Print("\x1b[0m") //defaultColor
|
||||
}
|
||||
|
||||
//Cyan color
|
||||
func (c Color) Cyan(t string) {
|
||||
fmt.Print("\x1b[36;1m") //cyan
|
||||
fmt.Println(t)
|
||||
fmt.Print("\x1b[0m") //defaultColor
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 161 B After Width: | Height: | Size: 161 B |
@@ -1,7 +1,5 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func comparePixels(p []int, q []int) int {
|
||||
numCoincidences := 0
|
||||
for i := 0; i < len(p); i++ {
|
||||
@@ -26,7 +24,7 @@ func analyzeImg(examplesImg map[string][]imgRGBA, timg imgRGBA) map[string]int {
|
||||
|
||||
for k, imgs := range examplesImg {
|
||||
numCoincidences[k] = 0
|
||||
fmt.Println(k)
|
||||
//fmt.Println(k)
|
||||
for _, img := range imgs {
|
||||
numCoincidences[k] = numCoincidences[k] + compareImgs(img, timg)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
//first, read the example images
|
||||
examplesImg := readExamples()
|
||||
@@ -10,6 +12,8 @@ func main() {
|
||||
//fmt.Println(timg)
|
||||
|
||||
numCoincidences := analyzeImg(examplesImg, timg)
|
||||
_ = printSortedMapStringInt(numCoincidences, 0)
|
||||
|
||||
_, result := printSortedMapStringInt(numCoincidences, 0)
|
||||
fmt.Print("The image contains the number: ")
|
||||
c.Green(result)
|
||||
//runServer()
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func printSortedMapStringInt(m map[string]int, threshold int) map[int][]string {
|
||||
total := len(m)
|
||||
fmt.Println("total: " + strconv.Itoa(total))
|
||||
func printSortedMapStringInt(m map[string]int, threshold int) (map[int][]string, string) {
|
||||
/*total := len(m)
|
||||
fmt.Println("total: " + strconv.Itoa(total))*/
|
||||
n := map[int][]string{}
|
||||
var a []int
|
||||
for k, v := range m {
|
||||
@@ -20,10 +18,11 @@ func printSortedMapStringInt(m map[string]int, threshold int) map[int][]string {
|
||||
a = append(a, k)
|
||||
}
|
||||
sort.Sort(sort.Reverse(sort.IntSlice(a)))
|
||||
for _, k := range a {
|
||||
r := n[a[0]][0]
|
||||
/*for _, k := range a {
|
||||
for _, s := range n[k] {
|
||||
fmt.Println(strconv.Itoa(k) + " - " + s)
|
||||
fmt.Println(strconv.Itoa(k) + " - " + s)
|
||||
}
|
||||
}
|
||||
return n
|
||||
}*/
|
||||
return n, r
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
_ "image/png"
|
||||
"io/ioutil"
|
||||
@@ -41,10 +40,10 @@ func readExamples() map[string][]imgRGBA {
|
||||
//for each image in the directory of example images, read the image and generate the histogram
|
||||
files, _ := ioutil.ReadDir("./images/numbers/")
|
||||
for _, f := range files {
|
||||
fmt.Println("images/numbers/" + f.Name())
|
||||
//fmt.Println("images/numbers/" + f.Name())
|
||||
file := readImage("images/numbers/" + f.Name())
|
||||
numberName := strings.Split(f.Name(), ".")[0]
|
||||
fmt.Println(numberName)
|
||||
//fmt.Println(numberName)
|
||||
examplesImg[numberName] = append(examplesImg[numberName], file)
|
||||
}
|
||||
return examplesImg
|
||||
|
||||
32
goVersion/server.go
Normal file
32
goVersion/server.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
type NumberImg struct {
|
||||
File string `json: "file"`
|
||||
Text string `json: "text"`
|
||||
}
|
||||
|
||||
func runServer() {
|
||||
router := mux.NewRouter().StrictSlash(true)
|
||||
router.HandleFunc("/", Index).Methods("GET")
|
||||
router.HandleFunc("/img", ImgToNumber).Methods("POST")
|
||||
log.Fatal(http.ListenAndServe(":3020", router))
|
||||
}
|
||||
func Index(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println(r.URL.Path)
|
||||
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
|
||||
}
|
||||
func ImgToNumber(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println(r.URL.Path)
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
|
||||
var t NumberImg
|
||||
err := decoder.Decode(&t)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(t.Text)
|
||||
fmt.Fprintf(w, "data")
|
||||
}*/
|
||||
Reference in New Issue
Block a user