-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d823e1
commit e96f56c
Showing
55 changed files
with
364 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<ProjectView>ProjectFiles</ProjectView> | ||
</PropertyGroup> | ||
</Project> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
from PIL import Image | ||
import hashlib | ||
import time | ||
import os, sys | ||
|
||
|
||
import math | ||
|
||
class VectorCompare: | ||
def magnitude(self,concordance): | ||
total = 0 | ||
for word,count in concordance.items(): | ||
total += count ** 2 | ||
return math.sqrt(total) | ||
|
||
def relation(self,concordance1, concordance2): | ||
relevance = 0 | ||
topvalue = 0 | ||
for word, count in concordance1.items(): | ||
if word in concordance2: | ||
topvalue += count * concordance2[word] | ||
return topvalue / (self.magnitude(concordance1) * self.magnitude(concordance2)) | ||
|
||
|
||
|
||
def buildvector(im): | ||
d1 = {} | ||
|
||
count = 0 | ||
for i in im.getdata(): | ||
d1[count] = i | ||
count += 1 | ||
|
||
return d1 | ||
|
||
v = VectorCompare() | ||
|
||
|
||
iconset = ['0','1','2','3','4','5','6','7','8','9'] | ||
|
||
|
||
imageset = [] | ||
|
||
for letter in iconset: | ||
for img in os.listdir('./numbers/%s/'%(letter)): | ||
temp = [] | ||
if img != "Thumbs.db" and img != ".DS_Store": | ||
temp.append(buildvector(Image.open("./numbers/%s/%s"%(letter,img)))) | ||
imageset.append({letter:temp}) | ||
|
||
correctcount = 0 | ||
wrongcount = 0 | ||
|
||
|
||
for filename in os.listdir('./examples/'): | ||
try: | ||
im = Image.open("./examples/%s"%(filename)) | ||
newim = Image.new("RGB",im.size) | ||
newim.paste(im) | ||
except: | ||
break | ||
|
||
print("") | ||
print(filename) | ||
|
||
im2 = Image.new("P",im.size) | ||
im = newim.convert("P") | ||
temp = {} | ||
|
||
for x in range(im.size[1]): | ||
for y in range(im.size[0]): | ||
pix = im.getpixel((y,x)) | ||
temp[pix] = pix | ||
if pix == 220 or pix==225 or pix == 227: | ||
im2.putpixel((y,x),255) | ||
|
||
inletter = False | ||
foundletter=False | ||
start = 0 | ||
end = 0 | ||
|
||
letters = [] | ||
|
||
for y in range(im2.size[0]): | ||
for x in range(im2.size[1]): | ||
pix = im2.getpixel((y,x)) | ||
if pix != 255: | ||
inletter = True | ||
|
||
if foundletter == False and inletter == True: | ||
foundletter = True | ||
start = y | ||
|
||
if foundletter == True and inletter == False: | ||
foundletter = False | ||
end = y | ||
letters.append((start,end)) | ||
|
||
|
||
inletter=False | ||
|
||
count = 0 | ||
guessword = "" | ||
for letter in letters: | ||
m = hashlib.md5() | ||
im3 = im2.crop(( letter[0] , 0, letter[1],im2.size[1] )) | ||
|
||
guess = [] | ||
|
||
for image in imageset: | ||
for x,y in image.items(): | ||
if len(y) != 0: | ||
guess.append( ( v.relation(y[0],buildvector(im3)),x) ) | ||
|
||
guess.sort(reverse=True) | ||
print("",guess[0]) | ||
guessword = "%s%s"%(guessword,guess[0][1]) | ||
|
||
count += 1 | ||
if guessword == filename[:-4]: | ||
correctcount += 1 | ||
else: | ||
wrongcount += 1 | ||
|
||
|
||
print("=======================") | ||
correctcount = float(correctcount) | ||
wrongcount = float(wrongcount) | ||
print("Correct Guesses - ",correctcount) | ||
print("Wrong Guesses - ",wrongcount) | ||
print("Percentage Correct - ", correctcount/(correctcount+wrongcount)*100.00) | ||
print("Percentage Wrong - ", wrongcount/(correctcount+wrongcount)*100.00) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
from PIL import Image | ||
import hashlib | ||
import time | ||
import os | ||
|
||
|
||
import math | ||
|
||
class VectorCompare: | ||
def magnitude(self,concordance): | ||
total = 0 | ||
for word,count in concordance.items(): | ||
total += count ** 2 | ||
return math.sqrt(total) | ||
|
||
def relation(self,concordance1, concordance2): | ||
relevance = 0 | ||
topvalue = 0 | ||
for word, count in concordance1.items(): | ||
if word in concordance2: | ||
topvalue += count * concordance2[word] | ||
return topvalue / (self.magnitude(concordance1) * self.magnitude(concordance2)) | ||
|
||
|
||
|
||
def buildvector(im): | ||
d1 = {} | ||
|
||
count = 0 | ||
for i in im.getdata(): | ||
d1[count] = i | ||
count += 1 | ||
|
||
return d1 | ||
|
||
v = VectorCompare() | ||
|
||
|
||
iconset = ['0','1','2','3','4','5','6','7','8','9'] | ||
|
||
|
||
imageset = [] | ||
|
||
for letter in iconset: | ||
for img in os.listdir('./numbers/%s/'%(letter)): | ||
temp = [] | ||
if img != "Thumbs.db" and img != ".DS_Store": | ||
temp.append(buildvector(Image.open("./numbers/%s/%s"%(letter,img)))) | ||
imageset.append({letter:temp}) | ||
|
||
|
||
im = Image.open("proba.gif") | ||
newim = Image.new("RGB",im.size) | ||
newim.paste(im) | ||
im2 = Image.new("P",im.size) | ||
im = newim.convert("P") | ||
temp = {} | ||
|
||
for x in range(im.size[1]): | ||
for y in range(im.size[0]): | ||
pix = im.getpixel((y,x)) | ||
temp[pix] = pix | ||
if pix == 220 or pix==225 or pix == 227: | ||
im2.putpixel((y,x),255) | ||
|
||
inletter = False | ||
foundletter=False | ||
start = 0 | ||
end = 0 | ||
|
||
letters = [] | ||
print("\n") | ||
for y in range(im2.size[0]): | ||
for x in range(im2.size[1]): | ||
pix = im2.getpixel((y,x)) | ||
if pix != 255: | ||
inletter = True | ||
|
||
if foundletter == False and inletter == True: | ||
foundletter = True | ||
start = y | ||
|
||
if foundletter == True and inletter == False: | ||
foundletter = False | ||
end = y | ||
letters.append((start,end)) | ||
|
||
|
||
inletter=False | ||
|
||
count = 0 | ||
for letter in letters: | ||
m = hashlib.md5() | ||
im3 = im2.crop(( letter[0] , 0, letter[1],im2.size[1] )) | ||
|
||
guess = [] | ||
|
||
for image in imageset: | ||
for x,y in image.items(): | ||
if len(y) != 0: | ||
guess.append( ( v.relation(y[0],buildvector(im3)),x) ) | ||
|
||
guess.sort(reverse=True) | ||
print("",guess[0]) | ||
|
||
count += 1 | ||
print("\nEXPECTED - 0022756") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from PIL import Image | ||
import hashlib | ||
import time | ||
|
||
im = Image.open("examples/12581.gif") | ||
newim = Image.new("RGB",im.size) | ||
newim.paste(im) | ||
im2 = Image.new("P",im.size) | ||
im = newim.convert("P") | ||
|
||
temp = {} | ||
|
||
|
||
for x in range(im.size[1]): | ||
for y in range(im.size[0]): | ||
pix = im.getpixel((y,x)) | ||
temp[pix] = pix | ||
if pix == 220 or pix == 225 or pix == 227: | ||
im2.putpixel((y,x),255) | ||
|
||
im2.save("output.gif") | ||
|
||
inletter = False | ||
foundletter=False | ||
start = 0 | ||
end = 0 | ||
|
||
letters = [] | ||
|
||
|
||
for y in range(im2.size[0]): | ||
for x in range(im2.size[1]): | ||
pix = im2.getpixel((y,x)) | ||
if pix != 255: | ||
inletter = True | ||
|
||
if foundletter == False and inletter == True: | ||
foundletter = True | ||
start = y | ||
|
||
if foundletter == True and inletter == False: | ||
foundletter = False | ||
end = y | ||
letters.append((start,end)) | ||
|
||
inletter=False | ||
|
||
count = 0 | ||
for letter in letters: | ||
m = hashlib.md5() | ||
im3 = im2.crop(( letter[0] , 0, letter[1],im2.size[1] )) | ||
line = "%s%s"%(time.time(),count) | ||
m.update(line.encode('utf-8')) | ||
im3.save("numbers/%s.gif"%(m.hexdigest())) | ||
count += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
������������� ����� �� ������������. | ||
��������� - �� ����� Python. | ||
����� ������������ ���������� pillow. | ||
����� Examples - ��� ��������. | ||
����� numbers - ��� ��������. | ||
����� examples - ������������� �����. |