2
0
forked from s444420/AL-2020

finding barcode

This commit is contained in:
shaaqu 2020-05-20 11:45:55 +02:00
parent ea4f66531d
commit bb070b8085
4 changed files with 72 additions and 44 deletions

View File

@ -19,12 +19,11 @@
<select />
</component>
<component name="ChangeListManager">
<list default="true" id="828778c9-9d97-422f-a727-18ddbd059b85" name="Default Changelist" comment="recognizing but training must be improved">
<change afterPath="$PROJECT_DIR$/coder/test5.jpg" afterDir="false" />
<change afterPath="$PROJECT_DIR$/coder/test5.png" afterDir="false" />
<list default="true" id="828778c9-9d97-422f-a727-18ddbd059b85" name="Default Changelist" comment="zwiekszenie dokladnosci">
<change afterPath="$PROJECT_DIR$/coder/barcode.jpg" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/coder/image.py" beforeDir="false" afterPath="$PROJECT_DIR$/coder/image.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/coder/test3.png" beforeDir="false" afterPath="$PROJECT_DIR$/coder/test3.png" afterDir="false" />
<change beforePath="$PROJECT_DIR$/coder/rocognizer.py" beforeDir="false" afterPath="$PROJECT_DIR$/coder/rocognizer.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -82,7 +81,7 @@
<recent name="C:\Users\Pawel Lukaszewicz\PycharmProjects\AL-2020\coder" />
</key>
</component>
<component name="RunManager" selected="Python.load_image">
<component name="RunManager" selected="Python.rocognizer">
<configuration default="true" type="PythonConfigurationType" factoryName="Python">
<module name="wozek" />
<option name="INTERPRETER_OPTIONS" value="" />
@ -105,28 +104,6 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="board" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="wozek" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/board.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="feature_hashing" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="wozek" />
<option name="INTERPRETER_OPTIONS" value="" />
@ -190,6 +167,25 @@
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="rocognizer" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="wozek" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/coder" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/coder/rocognizer.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="true" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="train_nn" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="wozek" />
<option name="INTERPRETER_OPTIONS" value="" />
@ -210,19 +206,19 @@
<method v="2" />
</configuration>
<list>
<item itemvalue="Python.board" />
<item itemvalue="Python.main" />
<item itemvalue="Python.feature_hashing" />
<item itemvalue="Python.train_nn" />
<item itemvalue="Python.load_image" />
<item itemvalue="Python.rocognizer" />
</list>
<recent_temporary>
<list>
<item itemvalue="Python.rocognizer" />
<item itemvalue="Python.load_image" />
<item itemvalue="Python.train_nn" />
<item itemvalue="Python.main" />
<item itemvalue="Python.feature_hashing" />
<item itemvalue="Python.board" />
</list>
</recent_temporary>
</component>
@ -248,7 +244,7 @@
<workItem from="1589814601057" duration="4208000" />
<workItem from="1589844260514" duration="777000" />
<workItem from="1589845066174" duration="177000" />
<workItem from="1589888090669" duration="20680000" />
<workItem from="1589888090669" duration="24037000" />
</task>
<task id="LOCAL-00001" summary="create Shelf">
<created>1589815443652</created>
@ -299,7 +295,14 @@
<option name="project" value="LOCAL" />
<updated>1589955873104</updated>
</task>
<option name="localTasksCounter" value="8" />
<task id="LOCAL-00008" summary="zwiekszenie dokladnosci">
<created>1589964526485</created>
<option name="number" value="00008" />
<option name="presentableId" value="LOCAL-00008" />
<option name="project" value="LOCAL" />
<updated>1589964526485</updated>
</task>
<option name="localTasksCounter" value="9" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@ -326,7 +329,8 @@
<MESSAGE value="img to 1d array" />
<MESSAGE value="fun created" />
<MESSAGE value="recognizing but training must be improved" />
<option name="LAST_COMMIT_MESSAGE" value="recognizing but training must be improved" />
<MESSAGE value="zwiekszenie dokladnosci" />
<option name="LAST_COMMIT_MESSAGE" value="zwiekszenie dokladnosci" />
</component>
<component name="WindowStateProjectService">
<state x="115" y="162" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog" timestamp="1589923610328">

BIN
coder/barcode.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

View File

@ -32,7 +32,7 @@ print(accuracy_score(y_test, predictions))
# image
img = cv2.cvtColor(cv2.imread('test3.png'), cv2.COLOR_BGR2GRAY)
img = cv2.GaussianBlur(img, (5, 5), 0) # poprawia jakosc
img = cv2.blur(img, (9, 9)) # poprawia jakosc
img = cv2.resize(img, (8, 8), interpolation=cv2.INTER_AREA)
print(type(img))
@ -47,7 +47,7 @@ rows, cols = img.shape
for i in range(rows):
for j in range(cols):
k = img[i, j]
if k == 255:
if k > 225:
k = 0 # brak czarnego
else:
k = 1

View File

@ -1,13 +1,37 @@
import matplotlib.pyplot as plt
import numpy as np
from numpy import asarray
from sklearn import datasets
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import accuracy_score
from PIL import Image
import pygame
import functions
import sys
import time
import argparse
import imutils
import cv2
import matplotlib.pyplot as plt
img = cv2.cvtColor(cv2.imread('barcode.jpg'), cv2.COLOR_BGR2GRAY)
ddepth = cv2.cv.CV_32F if imutils.is_cv2() else cv2.CV_32F
X = cv2.Sobel(img, ddepth=ddepth, dx=1, dy=0, ksize=-1)
Y = cv2.Sobel(img, ddepth=ddepth, dx=0, dy=1, ksize=-1)
gradient = cv2.subtract(X, Y)
gradient = cv2.convertScaleAbs(gradient)
blurred = cv2.blur(gradient, (9, 9))
(_, thresh) = cv2.threshold(blurred, 225, 255, cv2.THRESH_BINARY)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (21, 7))
closed = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel)
closed = cv2.erode(closed, None, iterations=4)
closed = cv2.dilate(closed, None, iterations=4)
cnts = cv2.findContours(closed.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
c = sorted(cnts, key=cv2.contourArea, reverse=True)[0]
rect = cv2.minAreaRect(c)
box = cv2.cv.BoxPoints(rect) if imutils.is_cv2() else cv2.boxPoints(rect)
box = np.int0(box)
cv2.drawContours(img, [box], -1, (0, 255, 0), 3)
cv2.imshow("Image", img)
cv2.waitKey(0)
plt.imshow(closed ,cmap='binary')
plt.show()