diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 4c5593f..2755ebf 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -20,10 +20,20 @@
+
+
+
-
+
+
+
+
+
+
+
+
@@ -72,7 +82,7 @@
-
+
@@ -82,7 +92,7 @@
-
+
@@ -131,6 +141,9 @@
+
+
+
@@ -218,8 +231,8 @@
-
+
@@ -265,6 +278,9 @@
+
+
+
1589815443652
@@ -364,7 +380,14 @@
1590846768877
-
+
+ 1590938465634
+
+
+
+ 1590938465634
+
+
@@ -398,13 +421,18 @@
-
+
+
-
+
-
+
+
+
+
+
@@ -425,10 +453,10 @@
-
+
-
+
diff --git a/coder/517.png b/coder/517.png
new file mode 100644
index 0000000..63f943e
Binary files /dev/null and b/coder/517.png differ
diff --git a/coder/digits_recognizer.py b/coder/digits_recognizer.py
index c690cb8..a620e27 100644
--- a/coder/digits_recognizer.py
+++ b/coder/digits_recognizer.py
@@ -75,6 +75,9 @@ print("\nTraining Time (in minutes) =", (time() - time0) / 60)
images, labels = next(iter(val_loader))
img = images[0].view(1, 784)
+print(type(img))
+print(img.size())
+
with torch.no_grad():
logps = model(img)
ps = torch.exp(logps)
diff --git a/coder/ll.png b/coder/ll.png
deleted file mode 100644
index 8ba51ad..0000000
Binary files a/coder/ll.png and /dev/null differ
diff --git a/coder/rocognizer.py b/coder/rocognizer.py
index 143dcbb..fea8f31 100644
--- a/coder/rocognizer.py
+++ b/coder/rocognizer.py
@@ -1,17 +1,19 @@
-import numpy as np
-import argparse
-import imutils
import cv2
import matplotlib.pyplot as plt
import torch
-from matplotlib import cm
+from PIL.Image import Image
from torch import nn
-from PIL import Image
-from skimage.feature import hog
from torchvision.transforms import transforms
+def white_bg_square(img):
+ "return a white-background-color image having the img in exact center"
+ size = (max(img.size),)*2
+ layer = Image.new('RGB', size, (255, 255, 255))
+ layer.paste(img, tuple(map(lambda x:(x[0]-x[1])/2, zip(size, img.size))))
+ return layer
+
code = []
-path = "test1.jpg"
+path = "test5.jpg"
transform = transforms.Compose([transforms.ToTensor(),
transforms.Normalize((0.5,), (0.5,)),
@@ -45,27 +47,19 @@ model.eval()
for rect in rects:
# Crop image
- crop_img = img[rect[1]:rect[1] + rect[3], rect[0]:rect[0] + rect[2]]
- plt.imshow(crop_img)
- plt.show()
-
+ crop_img = img[rect[1]:rect[1] + rect[3] + 10, rect[0]:rect[0] + rect[2] + 10, 0]
# Resize the image
- roi = cv2.resize(crop_img, (28, 28), interpolation=cv2.INTER_AREA)
+ roi = cv2.resize(crop_img, (28, 28), interpolation=cv2.INTER_LINEAR)
+ roi = cv2.dilate(roi, (3, 3))
plt.imshow(roi)
plt.show()
- im = Image.fromarray(roi)
-
- im = transform(im)
- print(im)
- plt.imshow(im)
- plt.show()
-
+ im = transform(roi)
+ im = im.view(1, 784)
with torch.no_grad():
- logps = model(im)
+ logps = model(im.float())
ps = torch.exp(logps)
- print(ps[0])
probab = list(ps.numpy()[0])
print("Predicted Digit =", probab.index(max(probab)))
-cv2.imshow("Resulting Image with Rectangular ROIs", img)
+cv2.imshow("Code", img)
cv2.waitKey()
\ No newline at end of file
diff --git a/coder/test.jpg b/coder/test.jpg
deleted file mode 100644
index 35b669a..0000000
Binary files a/coder/test.jpg and /dev/null differ
diff --git a/coder/test1.jpg b/coder/test1.jpg
deleted file mode 100644
index ac039f4..0000000
Binary files a/coder/test1.jpg and /dev/null differ
diff --git a/coder/test1.png b/coder/test1.png
new file mode 100644
index 0000000..1798762
Binary files /dev/null and b/coder/test1.png differ
diff --git a/coder/test2.png b/coder/test2.png
new file mode 100644
index 0000000..f6e0923
Binary files /dev/null and b/coder/test2.png differ
diff --git a/coder/test3.png b/coder/test3.png
index 99347fe..8804aa8 100644
Binary files a/coder/test3.png and b/coder/test3.png differ
diff --git a/coder/test5.png b/coder/test5.png
deleted file mode 100644
index 4a506f6..0000000
Binary files a/coder/test5.png and /dev/null differ
diff --git a/coder/test9.png b/coder/test9.png
deleted file mode 100644
index c4cca14..0000000
Binary files a/coder/test9.png and /dev/null differ
diff --git a/coder/testno.png b/coder/testno.png
deleted file mode 100644
index e20bf76..0000000
Binary files a/coder/testno.png and /dev/null differ
diff --git a/coder/train_nn.py b/coder/train_nn.py
deleted file mode 100644
index 30cf910..0000000
--- a/coder/train_nn.py
+++ /dev/null
@@ -1,30 +0,0 @@
-import matplotlib.pyplot as plt
-import numpy as np
-from numpy import asarray
-import pygame
-from sklearn import datasets
-from sklearn.neural_network import MLPClassifier
-from sklearn.metrics import accuracy_score
-from PIL import Image
-
-
-# recznie napisane cyfry
-digits = datasets.load_digits()
-
-y = digits.target
-x = digits.images.reshape((len(digits.images), -1))
-
-x_train = x[:1000000]
-y_train = y[:1000000]
-x_test = x[1000:]
-y_test = y[1000:]
-
-mlp = MLPClassifier(hidden_layer_sizes=(15,), activation='logistic', alpha=1e-4,
- solver='sgd', tol=1e-4, random_state=1,
- learning_rate_init=.1, verbose=True)
-
-mlp.fit(x_train, y_train)
-
-predictions = mlp.predict(x_test)
-print(accuracy_score(y_test, predictions))
-print(x_test[1])
\ No newline at end of file