Browse Source

go and python version. Both works fine

master
arnaucode 7 years ago
parent
commit
641349cd48
202 changed files with 317 additions and 0 deletions
  1. +9
    -0
      goVersion/errors.go
  2. BIN
      goVersion/images/blank.png
  3. BIN
      goVersion/images/dot.png
  4. BIN
      goVersion/images/dotndot.png
  5. BIN
      goVersion/images/numbers/0.1.png
  6. BIN
      goVersion/images/numbers/0.2.png
  7. BIN
      goVersion/images/numbers/0.3.png
  8. BIN
      goVersion/images/numbers/0.4.png
  9. BIN
      goVersion/images/numbers/0.5.png
  10. BIN
      goVersion/images/numbers/0.6.png
  11. BIN
      goVersion/images/numbers/0.7.png
  12. BIN
      goVersion/images/numbers/0.8.png
  13. BIN
      goVersion/images/numbers/0.9.png
  14. BIN
      goVersion/images/numbers/1.1.png
  15. BIN
      goVersion/images/numbers/1.2.png
  16. BIN
      goVersion/images/numbers/1.3.png
  17. BIN
      goVersion/images/numbers/1.4.png
  18. BIN
      goVersion/images/numbers/1.5.png
  19. BIN
      goVersion/images/numbers/1.6.png
  20. BIN
      goVersion/images/numbers/1.7.png
  21. BIN
      goVersion/images/numbers/1.8.png
  22. BIN
      goVersion/images/numbers/1.9.png
  23. BIN
      goVersion/images/numbers/2.1.png
  24. BIN
      goVersion/images/numbers/2.2.png
  25. BIN
      goVersion/images/numbers/2.3.png
  26. BIN
      goVersion/images/numbers/2.4.png
  27. BIN
      goVersion/images/numbers/2.5.png
  28. BIN
      goVersion/images/numbers/2.6.png
  29. BIN
      goVersion/images/numbers/2.7.png
  30. BIN
      goVersion/images/numbers/2.8.png
  31. BIN
      goVersion/images/numbers/2.9.png
  32. BIN
      goVersion/images/numbers/3.1.png
  33. BIN
      goVersion/images/numbers/3.2.png
  34. BIN
      goVersion/images/numbers/3.3.png
  35. BIN
      goVersion/images/numbers/3.4.png
  36. BIN
      goVersion/images/numbers/3.5.png
  37. BIN
      goVersion/images/numbers/3.6.png
  38. BIN
      goVersion/images/numbers/3.7.png
  39. BIN
      goVersion/images/numbers/3.8.png
  40. BIN
      goVersion/images/numbers/3.9.png
  41. BIN
      goVersion/images/numbers/4.1.png
  42. BIN
      goVersion/images/numbers/4.2.png
  43. BIN
      goVersion/images/numbers/4.3.png
  44. BIN
      goVersion/images/numbers/4.4.png
  45. BIN
      goVersion/images/numbers/4.5.png
  46. BIN
      goVersion/images/numbers/4.6.png
  47. BIN
      goVersion/images/numbers/4.7.png
  48. BIN
      goVersion/images/numbers/4.8.png
  49. BIN
      goVersion/images/numbers/4.9.png
  50. BIN
      goVersion/images/numbers/5.1.png
  51. BIN
      goVersion/images/numbers/5.2.png
  52. BIN
      goVersion/images/numbers/5.3.png
  53. BIN
      goVersion/images/numbers/5.4.png
  54. BIN
      goVersion/images/numbers/5.5.png
  55. BIN
      goVersion/images/numbers/5.6.png
  56. BIN
      goVersion/images/numbers/5.7.png
  57. BIN
      goVersion/images/numbers/5.8.png
  58. BIN
      goVersion/images/numbers/5.9.png
  59. BIN
      goVersion/images/numbers/6.1.png
  60. BIN
      goVersion/images/numbers/6.2.png
  61. BIN
      goVersion/images/numbers/6.3.png
  62. BIN
      goVersion/images/numbers/6.4.png
  63. BIN
      goVersion/images/numbers/6.5.png
  64. BIN
      goVersion/images/numbers/6.6.png
  65. BIN
      goVersion/images/numbers/6.7.png
  66. BIN
      goVersion/images/numbers/6.8.png
  67. BIN
      goVersion/images/numbers/6.9.png
  68. BIN
      goVersion/images/numbers/7.1.png
  69. BIN
      goVersion/images/numbers/7.2.png
  70. BIN
      goVersion/images/numbers/7.3.png
  71. BIN
      goVersion/images/numbers/7.4.png
  72. BIN
      goVersion/images/numbers/7.5.png
  73. BIN
      goVersion/images/numbers/7.6.png
  74. BIN
      goVersion/images/numbers/7.7.png
  75. BIN
      goVersion/images/numbers/7.8.png
  76. BIN
      goVersion/images/numbers/7.9.png
  77. BIN
      goVersion/images/numbers/8.1.png
  78. BIN
      goVersion/images/numbers/8.2.png
  79. BIN
      goVersion/images/numbers/8.3.png
  80. BIN
      goVersion/images/numbers/8.4.png
  81. BIN
      goVersion/images/numbers/8.5.png
  82. BIN
      goVersion/images/numbers/8.6.png
  83. BIN
      goVersion/images/numbers/8.7.png
  84. BIN
      goVersion/images/numbers/8.8.png
  85. BIN
      goVersion/images/numbers/8.9.png
  86. BIN
      goVersion/images/numbers/9.1.png
  87. BIN
      goVersion/images/numbers/9.2.png
  88. BIN
      goVersion/images/numbers/9.3.png
  89. BIN
      goVersion/images/numbers/9.4.png
  90. BIN
      goVersion/images/numbers/9.5.png
  91. BIN
      goVersion/images/numbers/9.6.png
  92. BIN
      goVersion/images/numbers/9.7.png
  93. BIN
      goVersion/images/numbers/9.8.png
  94. BIN
      goVersion/images/numbers/9.9.png
  95. BIN
      goVersion/images/sentdex.png
  96. BIN
      goVersion/images/test.png
  97. +35
    -0
      goVersion/imgOperations.go
  98. +15
    -0
      goVersion/main.go
  99. +29
    -0
      goVersion/printSortedMapStringInt.go
  100. +52
    -0
      goVersion/readExamples.go

+ 9
- 0
goVersion/errors.go

@ -0,0 +1,9 @@
package main
import "fmt"
func check(err error) {
if err != nil {
fmt.Println(err)
}
}

BIN
goVersion/images/blank.png

Before After
Width: 8  |  Height: 8  |  Size: 129 B

BIN
goVersion/images/dot.png

Before After
Width: 8  |  Height: 8  |  Size: 138 B

BIN
goVersion/images/dotndot.png

Before After
Width: 8  |  Height: 8  |  Size: 140 B

BIN
goVersion/images/numbers/0.1.png

Before After
Width: 8  |  Height: 8  |  Size: 168 B

BIN
goVersion/images/numbers/0.2.png

Before After
Width: 8  |  Height: 8  |  Size: 175 B

BIN
goVersion/images/numbers/0.3.png

Before After
Width: 8  |  Height: 8  |  Size: 178 B

BIN
goVersion/images/numbers/0.4.png

Before After
Width: 8  |  Height: 8  |  Size: 156 B

BIN
goVersion/images/numbers/0.5.png

Before After
Width: 8  |  Height: 8  |  Size: 167 B

BIN
goVersion/images/numbers/0.6.png

Before After
Width: 8  |  Height: 8  |  Size: 172 B

BIN
goVersion/images/numbers/0.7.png

Before After
Width: 8  |  Height: 8  |  Size: 165 B

BIN
goVersion/images/numbers/0.8.png

Before After
Width: 8  |  Height: 8  |  Size: 168 B

BIN
goVersion/images/numbers/0.9.png

Before After
Width: 8  |  Height: 8  |  Size: 167 B

BIN
goVersion/images/numbers/1.1.png

Before After
Width: 8  |  Height: 8  |  Size: 141 B

BIN
goVersion/images/numbers/1.2.png

Before After
Width: 8  |  Height: 8  |  Size: 135 B

BIN
goVersion/images/numbers/1.3.png

Before After
Width: 8  |  Height: 8  |  Size: 136 B

BIN
goVersion/images/numbers/1.4.png

Before After
Width: 8  |  Height: 8  |  Size: 150 B

BIN
goVersion/images/numbers/1.5.png

Before After
Width: 8  |  Height: 8  |  Size: 147 B

BIN
goVersion/images/numbers/1.6.png

Before After
Width: 8  |  Height: 8  |  Size: 156 B

BIN
goVersion/images/numbers/1.7.png

Before After
Width: 8  |  Height: 8  |  Size: 156 B

BIN
goVersion/images/numbers/1.8.png

Before After
Width: 8  |  Height: 8  |  Size: 154 B

BIN
goVersion/images/numbers/1.9.png

Before After
Width: 8  |  Height: 8  |  Size: 171 B

BIN
goVersion/images/numbers/2.1.png

Before After
Width: 8  |  Height: 8  |  Size: 177 B

BIN
goVersion/images/numbers/2.2.png

Before After
Width: 8  |  Height: 8  |  Size: 178 B

BIN
goVersion/images/numbers/2.3.png

Before After
Width: 8  |  Height: 8  |  Size: 176 B

BIN
goVersion/images/numbers/2.4.png

Before After
Width: 8  |  Height: 8  |  Size: 175 B

BIN
goVersion/images/numbers/2.5.png

Before After
Width: 8  |  Height: 8  |  Size: 173 B

BIN
goVersion/images/numbers/2.6.png

Before After
Width: 8  |  Height: 8  |  Size: 175 B

BIN
goVersion/images/numbers/2.7.png

Before After
Width: 8  |  Height: 8  |  Size: 175 B

BIN
goVersion/images/numbers/2.8.png

Before After
Width: 8  |  Height: 8  |  Size: 176 B

BIN
goVersion/images/numbers/2.9.png

Before After
Width: 8  |  Height: 8  |  Size: 176 B

BIN
goVersion/images/numbers/3.1.png

Before After
Width: 8  |  Height: 8  |  Size: 166 B

BIN
goVersion/images/numbers/3.2.png

Before After
Width: 8  |  Height: 8  |  Size: 160 B

BIN
goVersion/images/numbers/3.3.png

Before After
Width: 8  |  Height: 8  |  Size: 165 B

BIN
goVersion/images/numbers/3.4.png

Before After
Width: 8  |  Height: 8  |  Size: 166 B

BIN
goVersion/images/numbers/3.5.png

Before After
Width: 8  |  Height: 8  |  Size: 174 B

BIN
goVersion/images/numbers/3.6.png

Before After
Width: 8  |  Height: 8  |  Size: 175 B

BIN
goVersion/images/numbers/3.7.png

Before After
Width: 8  |  Height: 8  |  Size: 176 B

BIN
goVersion/images/numbers/3.8.png

Before After
Width: 8  |  Height: 8  |  Size: 176 B

BIN
goVersion/images/numbers/3.9.png

Before After
Width: 8  |  Height: 8  |  Size: 173 B

BIN
goVersion/images/numbers/4.1.png

Before After
Width: 8  |  Height: 8  |  Size: 152 B

BIN
goVersion/images/numbers/4.2.png

Before After
Width: 8  |  Height: 8  |  Size: 156 B

BIN
goVersion/images/numbers/4.3.png

Before After
Width: 8  |  Height: 8  |  Size: 159 B

BIN
goVersion/images/numbers/4.4.png

Before After
Width: 8  |  Height: 8  |  Size: 157 B

BIN
goVersion/images/numbers/4.5.png

Before After
Width: 8  |  Height: 8  |  Size: 150 B

BIN
goVersion/images/numbers/4.6.png

Before After
Width: 8  |  Height: 8  |  Size: 154 B

BIN
goVersion/images/numbers/4.7.png

Before After
Width: 8  |  Height: 8  |  Size: 151 B

BIN
goVersion/images/numbers/4.8.png

Before After
Width: 8  |  Height: 8  |  Size: 151 B

BIN
goVersion/images/numbers/4.9.png

Before After
Width: 8  |  Height: 8  |  Size: 155 B

BIN
goVersion/images/numbers/5.1.png

Before After
Width: 8  |  Height: 8  |  Size: 169 B

BIN
goVersion/images/numbers/5.2.png

Before After
Width: 8  |  Height: 8  |  Size: 158 B

BIN
goVersion/images/numbers/5.3.png

Before After
Width: 8  |  Height: 8  |  Size: 174 B

BIN
goVersion/images/numbers/5.4.png

Before After
Width: 8  |  Height: 8  |  Size: 171 B

BIN
goVersion/images/numbers/5.5.png

Before After
Width: 8  |  Height: 8  |  Size: 167 B

BIN
goVersion/images/numbers/5.6.png

Before After
Width: 8  |  Height: 8  |  Size: 168 B

BIN
goVersion/images/numbers/5.7.png

Before After
Width: 8  |  Height: 8  |  Size: 159 B

BIN
goVersion/images/numbers/5.8.png

Before After
Width: 8  |  Height: 8  |  Size: 158 B

BIN
goVersion/images/numbers/5.9.png

Before After
Width: 8  |  Height: 8  |  Size: 169 B

BIN
goVersion/images/numbers/6.1.png

Before After
Width: 8  |  Height: 8  |  Size: 180 B

BIN
goVersion/images/numbers/6.2.png

Before After
Width: 8  |  Height: 8  |  Size: 175 B

BIN
goVersion/images/numbers/6.3.png

Before After
Width: 8  |  Height: 8  |  Size: 180 B

BIN
goVersion/images/numbers/6.4.png

Before After
Width: 8  |  Height: 8  |  Size: 176 B

BIN
goVersion/images/numbers/6.5.png

Before After
Width: 8  |  Height: 8  |  Size: 178 B

BIN
goVersion/images/numbers/6.6.png

Before After
Width: 8  |  Height: 8  |  Size: 176 B

BIN
goVersion/images/numbers/6.7.png

Before After
Width: 8  |  Height: 8  |  Size: 174 B

BIN
goVersion/images/numbers/6.8.png

Before After
Width: 8  |  Height: 8  |  Size: 170 B

BIN
goVersion/images/numbers/6.9.png

Before After
Width: 8  |  Height: 8  |  Size: 170 B

BIN
goVersion/images/numbers/7.1.png

Before After
Width: 8  |  Height: 8  |  Size: 158 B

BIN
goVersion/images/numbers/7.2.png

Before After
Width: 8  |  Height: 8  |  Size: 165 B

BIN
goVersion/images/numbers/7.3.png

Before After
Width: 8  |  Height: 8  |  Size: 168 B

BIN
goVersion/images/numbers/7.4.png

Before After
Width: 8  |  Height: 8  |  Size: 163 B

BIN
goVersion/images/numbers/7.5.png

Before After
Width: 8  |  Height: 8  |  Size: 164 B

BIN
goVersion/images/numbers/7.6.png

Before After
Width: 8  |  Height: 8  |  Size: 163 B

BIN
goVersion/images/numbers/7.7.png

Before After
Width: 8  |  Height: 8  |  Size: 168 B

BIN
goVersion/images/numbers/7.8.png

Before After
Width: 8  |  Height: 8  |  Size: 162 B

BIN
goVersion/images/numbers/7.9.png

Before After
Width: 8  |  Height: 8  |  Size: 163 B

BIN
goVersion/images/numbers/8.1.png

Before After
Width: 8  |  Height: 8  |  Size: 151 B

BIN
goVersion/images/numbers/8.2.png

Before After
Width: 8  |  Height: 8  |  Size: 168 B

BIN
goVersion/images/numbers/8.3.png

Before After
Width: 8  |  Height: 8  |  Size: 168 B

BIN
goVersion/images/numbers/8.4.png

Before After
Width: 8  |  Height: 8  |  Size: 177 B

BIN
goVersion/images/numbers/8.5.png

Before After
Width: 8  |  Height: 8  |  Size: 153 B

BIN
goVersion/images/numbers/8.6.png

Before After
Width: 8  |  Height: 8  |  Size: 153 B

BIN
goVersion/images/numbers/8.7.png

Before After
Width: 8  |  Height: 8  |  Size: 148 B

BIN
goVersion/images/numbers/8.8.png

Before After
Width: 8  |  Height: 8  |  Size: 150 B

BIN
goVersion/images/numbers/8.9.png

Before After
Width: 8  |  Height: 8  |  Size: 169 B

BIN
goVersion/images/numbers/9.1.png

Before After
Width: 8  |  Height: 8  |  Size: 168 B

BIN
goVersion/images/numbers/9.2.png

Before After
Width: 8  |  Height: 8  |  Size: 158 B

BIN
goVersion/images/numbers/9.3.png

Before After
Width: 8  |  Height: 8  |  Size: 160 B

BIN
goVersion/images/numbers/9.4.png

Before After
Width: 8  |  Height: 8  |  Size: 165 B

BIN
goVersion/images/numbers/9.5.png

Before After
Width: 8  |  Height: 8  |  Size: 172 B

BIN
goVersion/images/numbers/9.6.png

Before After
Width: 8  |  Height: 8  |  Size: 163 B

BIN
goVersion/images/numbers/9.7.png

Before After
Width: 8  |  Height: 8  |  Size: 165 B

BIN
goVersion/images/numbers/9.8.png

Before After
Width: 8  |  Height: 8  |  Size: 172 B

BIN
goVersion/images/numbers/9.9.png

Before After
Width: 8  |  Height: 8  |  Size: 174 B

BIN
goVersion/images/sentdex.png

Before After
Width: 67  |  Height: 67  |  Size: 5.4 KiB

BIN
goVersion/images/test.png

Before After
Width: 8  |  Height: 8  |  Size: 161 B

+ 35
- 0
goVersion/imgOperations.go

@ -0,0 +1,35 @@
package main
import "fmt"
func comparePixels(p []int, q []int) int {
numCoincidences := 0
for i := 0; i < len(p); i++ {
if p[i] == q[i] {
numCoincidences++
}
}
return numCoincidences
}
func compareImgs(a imgRGBA, b imgRGBA) int {
numCoincidences := 0
for i := 0; i < len(a); i++ {
numCoincidences = numCoincidences + comparePixels(a[i], b[i])
}
return numCoincidences
}
func analyzeImg(examplesImg map[string][]imgRGBA, timg imgRGBA) map[string]int {
numCoincidences := make(map[string]int)
for k, imgs := range examplesImg {
numCoincidences[k] = 0
fmt.Println(k)
for _, img := range imgs {
numCoincidences[k] = numCoincidences[k] + compareImgs(img, timg)
}
}
return numCoincidences
}

+ 15
- 0
goVersion/main.go

@ -0,0 +1,15 @@
package main
func main() {
//first, read the example images
examplesImg := readExamples()
//fmt.Println(examplesImg)
//now, read the target image
timg := readImage("images/test.png")
//fmt.Println(timg)
numCoincidences := analyzeImg(examplesImg, timg)
_ = printSortedMapStringInt(numCoincidences, 0)
}

+ 29
- 0
goVersion/printSortedMapStringInt.go

@ -0,0 +1,29 @@
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))
n := map[int][]string{}
var a []int
for k, v := range m {
if v > threshold {
n[v] = append(n[v], k)
}
}
for k := range n {
a = append(a, k)
}
sort.Sort(sort.Reverse(sort.IntSlice(a)))
for _, k := range a {
for _, s := range n[k] {
fmt.Println(strconv.Itoa(k) + " - " + s)
}
}
return n
}

+ 52
- 0
goVersion/readExamples.go

@ -0,0 +1,52 @@
package main
import (
"fmt"
"image"
_ "image/png"
"io/ioutil"
"os"
"strings"
)
type imgRGBA [][]int
type CollectionImgs []imgRGBA
type ExamplesImg map[string]CollectionImgs
func readImage(path string) imgRGBA {
//open image, and generate the histogram, made from r,g,b,a components
reader, err := os.Open(path)
check(err)
defer reader.Close()
m, _, err := image.Decode(reader)
check(err)
bounds := m.Bounds()
//generate the histogram
var histogram imgRGBA
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
r, g, b, a := m.At(x, y).RGBA()
var pixel []int
pixel = append(pixel, int(r), int(g), int(b), int(a))
histogram = append(histogram, pixel)
}
}
return histogram
}
func readExamples() map[string][]imgRGBA {
//var examplesImg ExamplesImg
examplesImg := make(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())
file := readImage("images/numbers/" + f.Name())
numberName := strings.Split(f.Name(), ".")[0]
fmt.Println(numberName)
examplesImg[numberName] = append(examplesImg[numberName], file)
}
return examplesImg
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save