Browse Source

efficiency

increased the speed and efficiency of the barcode reader
add-license-1
Yiğit Çolakoğlu 7 years ago
parent
commit
d4110f3299
11 changed files with 398 additions and 85 deletions
  1. +12
    -0
      Barcode_Reader_Python/.idea/Barcode_Reader_Python.iml
  2. +7
    -0
      Barcode_Reader_Python/.idea/misc.xml
  3. +8
    -0
      Barcode_Reader_Python/.idea/modules.xml
  4. +6
    -0
      Barcode_Reader_Python/.idea/vcs.xml
  5. +292
    -0
      Barcode_Reader_Python/.idea/workspace.xml
  6. +0
    -1
      Barcode_Reader_Python/barcodes.csv
  7. +46
    -55
      Barcode_Reader_Python/raspberry_zbar.py
  8. +4
    -0
      Barcode_Reader_Python/run.py
  9. +22
    -26
      Barcode_Reader_Python/zbar_live.py
  10. +1
    -1
      FoodCloud/.idea/misc.xml
  11. +0
    -2
      FoodCloud/app/src/main/java/gq/yigit/foodcloud/ProductInfo.java

+ 12
- 0
Barcode_Reader_Python/.idea/Barcode_Reader_Python.iml View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="projectConfiguration" value="py.test" />
<option name="PROJECT_TEST_RUNNER" value="py.test" />
</component>
</module>

+ 7
- 0
Barcode_Reader_Python/.idea/misc.xml View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7" project-jdk-type="Python SDK" />
</project>

+ 8
- 0
Barcode_Reader_Python/.idea/modules.xml View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Barcode_Reader_Python.iml" filepath="$PROJECT_DIR$/.idea/Barcode_Reader_Python.iml" />
</modules>
</component>
</project>

+ 6
- 0
Barcode_Reader_Python/.idea/vcs.xml View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

+ 292
- 0
Barcode_Reader_Python/.idea/workspace.xml View File

@ -0,0 +1,292 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="7b5ef56c-2d3e-44d9-be69-b414f166f99b" name="Default" comment="">
<change beforePath="$PROJECT_DIR$/barcodes.csv" beforeDir="false" afterPath="$PROJECT_DIR$/barcodes.csv" afterDir="false" />
<change beforePath="$PROJECT_DIR$/raspberry_zbar.py" beforeDir="false" afterPath="$PROJECT_DIR$/raspberry_zbar.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/zbar_live.py" beforeDir="false" afterPath="$PROJECT_DIR$/zbar_live.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../FoodCloud/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../FoodCloud/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../FoodCloud/app/src/main/java/gq/yigit/foodcloud/ProductInfo.java" beforeDir="false" afterPath="$PROJECT_DIR$/../FoodCloud/app/src/main/java/gq/yigit/foodcloud/ProductInfo.java" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="CoverageDataManager">
<SUITE FILE_PATH="coverage/Barcode_Reader_Python$RUN.coverage" NAME="RUN Coverage Results" MODIFIED="1529584815747" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/Barcode_Reader_Python$raspberry_live.coverage" NAME="raspberry_live Coverage Results" MODIFIED="1529585357099" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/Barcode_Reader_Python$Unnamed.coverage" NAME="raspberry_live Coverage Results" MODIFIED="1529543452123" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component>
<component name="DockManager">
<window id="1">
<content type="file-editors">
<state>
<leaf>
<file leaf-file-name="zbar_live.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/zbar_live.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="660">
<caret line="33" lean-forward="true" selection-start-line="33" selection-end-line="33" />
<folding>
<element signature="e#0#25#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</state>
</content>
</window>
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="raspberry_zbar.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/raspberry_zbar.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="105">
<caret line="37" lean-forward="true" selection-start-line="37" selection-end-line="37" />
<folding>
<element signature="e#32#69#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="run.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/run.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="45">
<caret line="3" column="23" selection-start-line="3" selection-start-column="23" selection-end-line="3" selection-end-column="23" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Python Script" />
</list>
</option>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find />
<find>cam.read</find>
</findStrings>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/run.py" />
<option value="$PROJECT_DIR$/zbar_live.py" />
<option value="$PROJECT_DIR$/raspberry_zbar.py" />
</list>
</option>
</component>
<component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsGulpfileManager">
<detection-done>true</detection-done>
<sorting>DEFINITION_ORDER</sorting>
</component>
<component name="NodePackageJsonFileManager">
<packageJsonPaths />
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="1920" />
<option name="y" value="-4" />
<option name="width" value="1366" />
<option name="height" value="772" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="Barcode_Reader_Python" type="b2602c69:ProjectViewProjectNode" />
<item name="Barcode_Reader_Python" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
</panes>
</component>
<component name="PropertiesComponent">
<property name="SearchEverywhereHistoryKey" value="keymap&#9;ACTION&#9;ChangeKeymap" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/run.py" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="settings.editor.selected.configurable" value="preferences.keymap" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager" selected="Python.raspberry_live">
<configuration name="RUN" type="PythonConfigurationType" factoryName="Python">
<module name="Barcode_Reader_Python" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="/usr/bin/python2.7" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="false" />
<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$/run.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
</configuration>
<configuration name="raspberry_live" type="PythonConfigurationType" factoryName="Python">
<module name="Barcode_Reader_Python" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="/usr/bin/python2.7" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="false" />
<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$/raspberry_zbar.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
</configuration>
<list>
<item itemvalue="Python.raspberry_live" />
<item itemvalue="Python.RUN" />
</list>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="7b5ef56c-2d3e-44d9-be69-b414f166f99b" name="Default" comment="" />
<created>1529543214918</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1529543214918</updated>
</task>
<servers />
</component>
<component name="ToolWindowManager">
<frame x="1920" y="-4" width="1366" height="772" extended-state="6" />
<editor active="true" />
<layout>
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Event Log" order="7" sideWeight="0.5007587" side_tool="true" weight="0.4638365" />
<window_info anchor="bottom" id="Database Changes" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" order="7" />
<window_info anchor="bottom" id="Python Console" order="7" />
<window_info active="true" anchor="bottom" id="Run" order="2" sideWeight="0.49924126" visible="true" weight="0.27056962" />
<window_info anchor="bottom" id="Terminal" order="7" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25872535" />
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
<window_info anchor="right" id="Database" order="3" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32911393" />
<window_info anchor="right" id="SciView" order="3" weight="0.32928678" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.39873418" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.24962063" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/raspberry_zbar.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="90">
<caret line="12" column="67" lean-forward="true" selection-start-line="12" selection-start-column="67" selection-end-line="12" selection-end-column="67" />
<folding>
<element signature="e#32#69#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/run.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="45">
<caret line="3" column="23" lean-forward="true" selection-start-line="3" selection-start-column="23" selection-end-line="3" selection-end-column="23" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/barcodes.csv">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/run.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="45">
<caret line="3" column="23" selection-start-line="3" selection-start-column="23" selection-end-line="3" selection-end-column="23" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/barcodes.csv">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/zbar_live.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="660">
<caret line="33" lean-forward="true" selection-start-line="33" selection-end-line="33" />
<folding>
<element signature="e#0#25#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/raspberry_zbar.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="105">
<caret line="37" lean-forward="true" selection-start-line="37" selection-end-line="37" />
<folding>
<element signature="e#32#69#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
</project>

+ 0
- 1
Barcode_Reader_Python/barcodes.csv View File

@ -1 +0,0 @@
2018-06-15 23:18:13.020993,2

+ 46
- 55
Barcode_Reader_Python/raspberry_zbar.py View File

@ -1,71 +1,62 @@
# import the necessary packages
from imutils.video import VideoStream
from pyzbar import pyzbar
import argparse
import datetime
import imutils
import time
import cv2
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-o", "--output", type=str, default="barcodes.csv",
help="path to output CSV file containing barcodes")
args = vars(ap.parse_args())
import database_actions
# initialize the video stream and allow the camera sensor to warm up
print("[INFO] starting video stream...")
# vs = VideoStream(src=0).start()
vs = VideoStream().start()
time.sleep(2.0)
# open the output CSV file for writing and initialize the set of
# barcodes found thus far
csv = open(args["output"], "w")
found = set()
dates = []
reps = 0
barcodes = None
prevcode = None
exp_date = []
# loop over the frames from the video stream
while True:
# grab the frame from the threaded video stream and resize it to
# have a maximum width of 400 pixels
frame = vs.read()
frame = imutils.resize(frame, width=400)
# find the barcodes in the frame and decode each of the barcodes
barcodes = pyzbar.decode(frame)
# loop over the detected barcodes
for barcode in barcodes:
# extract the bounding box location of the barcode and draw
# the bounding box surrounding the barcode on the image
(x, y, w, h) = barcode.rect
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
# the barcode data is a bytes object so if we want to draw it
# on our output image we need to convert it to a string first
barcodeData = barcode.data.decode("utf-8")
barcodeType = barcode.type
# draw the barcode data and barcode type on the image
text = "{} ({})".format(barcodeData, barcodeType)
cv2.putText(frame, text, (x, y - 10),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
# if the barcode text is currently not in our CSV file, write
# the timestamp + barcode to disk and update the set
if barcodeData not in found:
csv.write("{},{}\n".format(datetime.datetime.now(),
barcodeData))
csv.flush()
found.add(barcodeData)
# show the output frame
cv2.imshow("Barcode Scanner", frame)
key = cv2.waitKey(1) & 0xFF
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
while reps<1:
# grab the frame from the threaded video stream and resize it to
try:
while (barcodes == None or barcodes == []):
frame = vs.read()
frame = imutils.resize(frame, width=400)
barcodes = pyzbar.decode(frame)
cv2.imshow("Image", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
barcodes = pyzbar.decode(frame)
# loop over the detected barcodes
for barcode in barcodes:
(x, y, w, h) = barcode.rect
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
barcodeData = barcode.data.decode("utf-8")
barcodeType = barcode.type
if (barcodeData != prevcode):
text = "{} ({})".format(barcodeData, barcodeType)
cv2.putText(frame, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
0.5, (0, 0, 255), 2)
print("[INFO] Found {} barcode: {}".format(barcodeType, barcodeData))
dates.append(database_actions.getDate(barcodeData))
reps += 1
prevcode = barcodeData
barcodes = None
cv2.imshow("Image", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
except KeyboardInterrupt:
break
# close the output CSV file do a bit of cleanup
print("[INFO] cleaning up...")
csv.close()
print dates
cv2.destroyAllWindows()
vs.stop()
vs.stop()

+ 4
- 0
Barcode_Reader_Python/run.py View File

@ -0,0 +1,4 @@
import os
script = raw_input("Please enter what you would like to run: ")
os.system("python " + script + ".py")

+ 22
- 26
Barcode_Reader_Python/zbar_live.py View File

@ -1,7 +1,5 @@
from pyzbar import pyzbar
import argparse
import cv2
import time
import database_actions
dates = []
@ -10,9 +8,9 @@ barcodes = None
prevcode = None
exp_date = []
cam = cv2.VideoCapture(0)
while(reps<2):
while(barcodes == None or barcodes == []):
ret , image = cam.read()
while (reps < 2):
while (barcodes == None or barcodes == []):
ret, image = cam.read()
barcodes = pyzbar.decode(image)
cv2.imshow("Image", image)
if cv2.waitKey(1) & 0xFF == ord('q'):
@ -20,26 +18,24 @@ while(reps<2):
for barcode in barcodes:
(x, y, w, h) = barcode.rect
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)
barcodeData = barcode.data.decode("utf-8")
barcodeType = barcode.type
if(barcodeData != prevcode):
text = "{} ({})".format(barcodeData, barcodeType)
cv2.putText(image, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
0.5, (0, 0, 255), 2)
print("[INFO] Found {} barcode: {}".format(barcodeType, barcodeData))
dates.append(database_actions.getDate(barcodeData))
exp_date.append(int(barcodeData))
reps += 1
prevcode = barcodeData
barcodes = None
cv2.imshow("Image", image)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
(x, y, w, h) = barcode.rect
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)
barcodeData = barcode.data.decode("utf-8")
barcodeType = barcode.type
if (barcodeData != prevcode):
text = "{} ({})".format(barcodeData, barcodeType)
cv2.putText(image, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
0.5, (0, 0, 255), 2)
print dates
print("[INFO] Found {} barcode: {}".format(barcodeType, barcodeData))
dates.append(database_actions.getDate(barcodeData))
exp_date.append(int(barcodeData))
reps += 1
prevcode = barcodeData
barcodes = None
cv2.imshow("Image", image)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
print dates

+ 1
- 1
FoodCloud/.idea/misc.xml View File

@ -25,7 +25,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">


+ 0
- 2
FoodCloud/app/src/main/java/gq/yigit/foodcloud/ProductInfo.java View File

@ -133,8 +133,6 @@ public class ProductInfo extends AppCompatActivity implements OnClickListener {
BBD.setText("BBD : " +bbd);
Processed = (TextView) findViewById(R.id.Process);
Processed.setText("Process : " + processed);
Problematic = (TextView) findViewById(R.id.Problems);
Problematic.setText("Problemed : " + problematic);
}


Loading…
Cancel
Save