nowe shelfy kolorowe wziuuu #10

Merged
s444428 merged 10 commits from s444428/AL-2020:master into master 2020-06-09 22:56:57 +02:00
121 changed files with 26704 additions and 87 deletions
Showing only changes of commit 686c2e1009 - Show all commits

View File

@ -3,5 +3,5 @@
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (AL-2020)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (AL-2020)" project-jdk-type="Python SDK" />
</project>

View File

@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.7 (AL-2020)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.8 (AL-2020)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

18
assigning.py Normal file
View File

@ -0,0 +1,18 @@
import os
from codes_recognizer.rocognizer import recognizer
def assigning(product_code_path, shelfs):
c = None
code = recognizer(product_code_path)
print(code)
product_color = str(code[0]) + str(code[1])
print(product_color)
for shelf in shelfs:
if shelf.color == product_color:
shelf.add_product(code)
c = shelf.get_field()
print("Product", product_code_path, "is on", c)
return c

View File

@ -1,12 +1,14 @@
import pygame
from settings import Settings
from field import Field
from shelf import Shelf
settings = Settings()
#(250, 650), (250, 750)
def create_board(screen):
board = []
shelfs = [
(50, 50), (150, 50), (450, 50), (550, 50), (850, 50), (950, 50),
(250, 250), (350, 250), (650, 250), (750, 250),
@ -49,3 +51,73 @@ def draw_board(board):
field.blitme()
def get_shelfs(board):
field_shelfs = []
shelfs = []
for row in board:
for field in row:
if field.isShelf():
field_shelfs.append(field)
shelf = Shelf(field_shelfs[0], "01")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[1], "01")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[2], "02")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[3], "02")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[4], "03")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[5], "03")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[6], "04")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[7], "04")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[8], "05")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[9], "05")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[10], "06")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[11], "06")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[12], "07")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[13], "07")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[14], "08")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[15], "08")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[16], "09")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[17], "09")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[18], "10")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[19], "10")
shelfs.append(shelf)
return shelfs

130
board.py.orig Normal file
View File

@ -0,0 +1,130 @@
import pygame
from settings import Settings
from field import Field
from shelf import Shelf
settings = Settings()
#(250, 650), (250, 750)
def create_board(screen):
board = []
<<<<<<< HEAD
=======
>>>>>>> upstream/master
shelfs = [
(50, 50), (150, 50), (450, 50), (550, 50), (850, 50), (950, 50),
(250, 250), (350, 250), (650, 250), (750, 250),
(50, 450), (150, 450), (450, 450), (550, 450), (850, 450), (950, 450),
<<<<<<< HEAD
(250, 650), (350, 650), (650, 650), (750, 650)
=======
(250, 650), (350, 650), (650, 650), (750, 650),
>>>>>>> upstream/master
]
for y in range(settings.y_fields):
row = []
for x in range(settings.x_fields):
field = Field(screen, x, y, 50 + x * 100, 50 + y * 100, False, False, 1)
for shelf in shelfs:
if field.center_x == shelf[0] and field.center_y == shelf[1]:
field.is_shelf = True
field.image = pygame.image.load('img/shelf.png')
row.append(field)
board.append(row)
for row in board:
for field in row:
field.add_neighbors(board)
for row in board:
for field in row:
if field.x > 0 and board[field.y][field.x - 1].is_shelf:
field.cost_of_travel += 1
if field.x < 9 and board[field.y][field.x + 1].is_shelf:
field.cost_of_travel += 1
if field.y > 0 and board[field.y - 1][field.x].is_shelf:
field.cost_of_travel += 1
if field.y < 9 and board[field.y + 1][field.x].is_shelf:
field.cost_of_travel += 1
return board
def draw_board(board):
for row in board:
for field in row:
field.blitme()
def get_shelfs(board):
field_shelfs = []
shelfs = []
for row in board:
for field in row:
if field.isShelf():
field_shelfs.append(field)
shelf = Shelf(field_shelfs[0], "01")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[1], "01")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[2], "02")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[3], "02")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[4], "03")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[5], "03")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[6], "04")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[7], "04")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[8], "05")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[9], "05")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[10], "06")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[11], "06")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[12], "07")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[13], "07")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[14], "08")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[15], "08")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[16], "09")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[17], "09")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[18], "10")
shelfs.append(shelf)
shelf = Shelf(field_shelfs[19], "10")
shelfs.append(shelf)
return shelfs

View File

@ -68,8 +68,8 @@ def create_image(product):
print(string)
img = Image.new('RGB', (560, 112), color='white')
d = ImageDraw.Draw(img)
fnt = ImageFont.truetype('D:\Studia\Projects\AL-2020\img\codes\\arial_bold.ttf', 75)
d.text((30, 30), string, font=fnt, fill=(0, 0, 0))
fnt = ImageFont.truetype('img\codes\\arial_bold.ttf', 75)
d.text((28, 28), string, font=fnt, fill=(0, 0, 0))
path = 'img/codes/' + product.name + '.png'
img.save(path)
return path

View File

@ -1,56 +0,0 @@
import cv2
import torch
from nn_model import Net
from torchvision.transforms import transforms
def recognizer(paths):
codes = []
code = []
transform = transforms.Compose([transforms.ToTensor(),
transforms.Normalize((0.5,), (0.5,)),
])
# load nn model
model = Net()
model.load_state_dict(torch.load('model.pt'))
model.eval()
for path in paths:
img = cv2.imread(path)
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_gray = cv2.GaussianBlur(img_gray, (5, 5), 0)
ret, im_th = cv2.threshold(img_gray, 90, 255, cv2.THRESH_BINARY_INV)
ctrs, hier = cv2.findContours(im_th.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
rects = [cv2.boundingRect(ctr) for ctr in ctrs]
for rect in rects:
# Crop image
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_CUBIC)
# roi = cv2.dilate(roi, (3, 3))
# plt.imshow(roi)
# plt.show()
im = transform(roi)
im = im.view(1, 1, 28, 28)
with torch.no_grad():
logps = model(im)
ps = torch.exp(logps)
probab = list(ps.numpy()[0])
code.append(probab.index(max(probab)))
codes.append(code)
# cv2.imshow("Code", img)
# cv2.waitKey()
return codes

View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

File diff suppressed because it is too large Load Diff

View File

@ -18,4 +18,4 @@ class Net(nn.Module):
x = F.relu(self.fc1(x))
x = F.dropout(x, training=self.training)
x = self.fc2(x)
return F.log_softmax(x)
return F.log_softmax(x, 1)

View File

@ -0,0 +1,51 @@
import cv2
import torch
from torchvision.transforms import transforms
from codes_recognizer.network_model import Net
def recognizer(path):
codes = []
code = []
transform = transforms.Compose([transforms.ToTensor(),
transforms.Normalize((0.5,), (0.5,)),
])
# load nn model
model = Net()
model.load_state_dict(torch.load('codes_recognizer/model.pt'))
model.eval()
img = cv2.imread(path)
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_gray = cv2.GaussianBlur(img_gray, (5, 5), 0)
ret, im_th = cv2.threshold(img_gray, 90, 255, cv2.THRESH_BINARY_INV)
ctrs, hier = cv2.findContours(im_th.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
rects = [cv2.boundingRect(ctr) for ctr in ctrs]
for rect in rects:
# Crop image
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_CUBIC)
# roi = cv2.dilate(roi, (3, 3))
# plt.imshow(roi)
# plt.show()
im = transform(roi)
im = im.view(1, 1, 28, 28)
with torch.no_grad():
logps = model(im)
ps = torch.exp(logps)
probab = list(ps.numpy()[0])
code.append(probab.index(max(probab)))
# cv2.imshow("Code", img)
# cv2.waitKey()
return code

38
data.py
View File

@ -54,31 +54,31 @@ learning_data = [
['white', 'rectangle', 25, 'small', 'Duplo'],
['brown', 'jar', 500, 'big', 'GoOn'],
['brown', 'jar', 470, 'big', 'Active Orzechowe'],
['red', 'jar', 250, 'medium', 'Strawberry Jam'],
['black', 'jar', 250, 'medium', 'Blackberry Jam'],
['orange', 'jar', 250, 'medium', 'Peach Jam'],
['brown', 'rectangle', 140, 'big', 'Jezyki classic'],
['blue', 'rectangle', 140, 'big', 'Jezyki kokos'],
['white', 'rectangle', 100, 'big', 'Kinder Chocolate'],
['red', 'jar', 250, 'medium', 'Strawberry-Jam'],
['black', 'jar', 250, 'medium', 'Blackberry-Jam'],
['orange', 'jar', 250, 'medium', 'Peach-Jam'],
['brown', 'rectangle', 140, 'big', 'Jezyki-classic'],
['blue', 'rectangle', 140, 'big', 'Jezyki-kokos'],
['white', 'rectangle', 100, 'big', 'Kinder-Chocolate'],
['yellow', 'rectangle', 300, 'big', 'belVita'],
['blue', 'rectangle', 380, 'big', 'Wedel-Ptasie Mleczko'],
['purple', 'rectangle', 330, 'big', 'Milka-Alpejskie Mleczko'],
['blue', 'rectangle', 380, 'big', 'Wedel-Ptasie-Mleczko'],
['purple', 'rectangle', 330, 'big', 'Milka-Alpejskie-Mleczko'],
['blue', 'rectangle', 294, 'big', 'Delicje'],
['silver', 'pack', 280, 'big', 'Wawel-Michalki'],
['red', 'rectangle', 50, 'medium', 'Krakuski Petit Beurre'],
['white', 'egg', 20, 'small', 'Kinder Niespodzianka'],
['brown', 'rectangle', 180, 'big', 'Familijne Wafle'],
['red', 'rectangle', 235, 'big', 'dr Gerard PryncyPałki'],
['white', 'rectangle', 25, 'medium', 'Nestlé Cini Minis Batonik'],
['black', 'pack', 70, 'big', 'Korsarz Draże'],
['white', 'rectangle', 50, 'medium', 'Góralki'],
['white', 'rectangle', 24, 'medium', 'Kinder Country'],
['red', 'rectangle', 50, 'medium', 'Krakuski-Petit-Beurre'],
['white', 'egg', 20, 'small', 'Kinder-Niespodzianka'],
['brown', 'rectangle', 180, 'big', 'Familijne-Wafle'],
['red', 'rectangle', 235, 'big', 'dr-Gerard-PryncyPalki'],
['white', 'rectangle', 25, 'medium', 'Nestle-Cini-Minis-Batonik'],
['black', 'pack', 70, 'big', 'Korsarz-Draze'],
['white', 'rectangle', 50, 'medium', 'Goralki'],
['white', 'rectangle', 24, 'medium', 'Kinder-Country'],
['red', 'rectangle', 46, 'medium', '3Bit'],
['yellow', 'rectangle', 25, 'medium', 'Nestlé Nesquik Batonik'],
['yellow', 'rectangle', 47, 'medium', 'Wedel WW'],
['yellow', 'rectangle', 25, 'medium', 'Nestle-Nesquik-Batonik'],
['yellow', 'rectangle', 47, 'medium', 'Wedel-WW'],
['brown', 'rectangle', 30, 'medium', 'Lubisie'],
['purple', 'rectangle', 22, 'small', 'Maoam'],
['brown', 'rectangle', 294, 'medium', 'Grześki'],
['brown', 'rectangle', 294, 'medium', 'Grzeski'],
['white', 'rectangle', 250, 'big', 'merci'],
]

View File

@ -52,3 +52,6 @@ class Field:
def addShelf(self):
shelf = Shelf(len(self.shelves) + 1)
self.shelves.append(shelf)
def isShelf(self):
return self.is_shelf

Binary file not shown.

After

Width:  |  Height:  |  Size: 860 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 857 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 867 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 856 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 867 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 864 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 872 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 896 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 894 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 927 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 886 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 922 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 918 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 950 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 900 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 898 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 930 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 890 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 925 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 921 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 955 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 901 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 899 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 931 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 891 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 926 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 922 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 956 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 893 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 891 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 924 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 884 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 919 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 915 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 947 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 898 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 896 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 929 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 889 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 924 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 920 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 953 B

BIN
img/shelves/red/red001.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 900 B

BIN
img/shelves/red/red010.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 898 B

BIN
img/shelves/red/red011.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 930 B

BIN
img/shelves/red/red100.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 890 B

BIN
img/shelves/red/red101.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 925 B

BIN
img/shelves/red/red110.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 921 B

BIN
img/shelves/red/red111.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 955 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 891 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 890 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 922 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 882 B

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