diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4aff4be --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +media +webapp diff --git a/goVersion/color.go b/goVersion/color.go new file mode 100644 index 0000000..e945ac5 --- /dev/null +++ b/goVersion/color.go @@ -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 +} diff --git a/goVersion/images/test.png b/goVersion/images/test.png index b1e843f..ae6c53e 100644 Binary files a/goVersion/images/test.png and b/goVersion/images/test.png differ diff --git a/goVersion/imgOperations.go b/goVersion/imgOperations.go index f3f51d7..55851e9 100644 --- a/goVersion/imgOperations.go +++ b/goVersion/imgOperations.go @@ -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) } diff --git a/goVersion/main.go b/goVersion/main.go index fd8dc3f..842ce04 100644 --- a/goVersion/main.go +++ b/goVersion/main.go @@ -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() } diff --git a/goVersion/printSortedMapStringInt.go b/goVersion/printSortedMapStringInt.go index 993cca6..ca6007f 100644 --- a/goVersion/printSortedMapStringInt.go +++ b/goVersion/printSortedMapStringInt.go @@ -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 } diff --git a/goVersion/readExamples.go b/goVersion/readExamples.go index abb2755..929ce8e 100644 --- a/goVersion/readExamples.go +++ b/goVersion/readExamples.go @@ -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 diff --git a/goVersion/server.go b/goVersion/server.go new file mode 100644 index 0000000..54667dd --- /dev/null +++ b/goVersion/server.go @@ -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") +}*/