Python - ekelner, analiza obrazu

Dodano nasłuchiwanie folderu pod kątem pojawiania się nowych obrazów.

Dodano połączenie z bazą danych, wraz z dodawaniem rekordów
This commit is contained in:
s421507 2020-06-20 09:33:14 +02:00
parent c1ae17227d
commit d9493aee69
6 changed files with 314 additions and 68 deletions

View File

@ -1,7 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="a79cebc0-13eb-413e-acdb-02d703308306" name="Default Changelist" comment="" /> <list default="true" id="a79cebc0-13eb-413e-acdb-02d703308306" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/directoryListener.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/mysqlConnect.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/menuAnalysis.py" beforeDir="false" afterPath="$PROJECT_DIR$/menuAnalysis.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/orders/CCI18022020.jpg" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/photoAnalysisUtils.py" beforeDir="false" afterPath="$PROJECT_DIR$/photoAnalysisUtils.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -14,18 +21,15 @@
</list> </list>
</option> </option>
</component> </component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" /> <component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" /> <component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsGulpfileManager"> <component name="JsGulpfileManager">
<detection-done>true</detection-done> <detection-done>true</detection-done>
<sorting>DEFINITION_ORDER</sorting> <sorting>DEFINITION_ORDER</sorting>
</component> </component>
<component name="ProjectFrameBounds">
<option name="x" value="-9" />
<option name="y" value="-9" />
<option name="width" value="1938" />
<option name="height" value="1048" />
</component>
<component name="ProjectId" id="1XxVTPZDbvkT8cPJL4efN0bxYyL" /> <component name="ProjectId" id="1XxVTPZDbvkT8cPJL4efN0bxYyL" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" /> <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState"> <component name="ProjectViewState">
@ -37,9 +41,15 @@
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" /> <property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" /> <property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="settings.editor.selected.configurable" value="vcs.Git" /> <property name="restartRequiresConfirmation" value="false" />
<property name="settings.editor.selected.configurable" value="configurable.group.tools" />
</component> </component>
<component name="RunManager" selected="Python.templateGenerator"> <component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\Users\czup\PycharmProjects\MenuReader" />
</key>
</component>
<component name="RunManager" selected="Python.directoryListener (1)">
<configuration default="true" type="PythonConfigurationType" factoryName="Python"> <configuration default="true" type="PythonConfigurationType" factoryName="Python">
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" /> <option name="PARENT_ENVS" value="true" />
@ -62,6 +72,50 @@
<option name="INPUT_FILE" value="" /> <option name="INPUT_FILE" value="" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="directoryListener (1)" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="MenuReader" />
<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" enabled="false" sample_coverage="true" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/directoryListener.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="directoryListener" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="MenuReader" />
<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$/orders" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" runner="coverage.py" />
<option name="SCRIPT_NAME" value="C:\Users\czup\PycharmProjects\MenuReader\directoryListener.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="menuAnalysis" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <configuration name="menuAnalysis" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="MenuReader" /> <module name="MenuReader" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
@ -84,6 +138,28 @@
<option name="INPUT_FILE" value="" /> <option name="INPUT_FILE" value="" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
<configuration name="mysqlConnect" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="MenuReader" />
<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" enabled="false" sample_coverage="true" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/mysqlConnect.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="templateGenerator" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true"> <configuration name="templateGenerator" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="MenuReader" /> <module name="MenuReader" />
<option name="INTERPRETER_OPTIONS" value="" /> <option name="INTERPRETER_OPTIONS" value="" />
@ -108,10 +184,16 @@
</configuration> </configuration>
<list> <list>
<item itemvalue="Python.templateGenerator" /> <item itemvalue="Python.templateGenerator" />
<item itemvalue="Python.directoryListener" />
<item itemvalue="Python.menuAnalysis" /> <item itemvalue="Python.menuAnalysis" />
<item itemvalue="Python.directoryListener (1)" />
<item itemvalue="Python.mysqlConnect" />
</list> </list>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Python.directoryListener (1)" />
<item itemvalue="Python.mysqlConnect" />
<item itemvalue="Python.directoryListener" />
<item itemvalue="Python.menuAnalysis" /> <item itemvalue="Python.menuAnalysis" />
</list> </list>
</recent_temporary> </recent_temporary>
@ -137,53 +219,57 @@
<option name="LAST_COMMIT_MESSAGE" value="Python - ekelner, analiza obrazu&#10;" /> <option name="LAST_COMMIT_MESSAGE" value="Python - ekelner, analiza obrazu&#10;" />
</component> </component>
<component name="WindowStateProjectService"> <component name="WindowStateProjectService">
<state x="361" y="74" key="#Notifications" timestamp="1582003638335"> <state x="361" y="74" key="#Notifications" timestamp="1592604887703">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="361" y="74" key="#Notifications/0.0.1536.824@0.0.1536.824" timestamp="1582003638335" /> <state x="361" y="74" key="#Notifications/0.0.1536.824@0.0.1536.824" timestamp="1592604887703" />
<state x="223" y="70" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1581989120082"> <state x="549" y="157" key="FileChooserDialogImpl" timestamp="1592605200406">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="223" y="70" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.0.1536.824@0.0.1536.824" timestamp="1581989120082" /> <state x="549" y="157" key="FileChooserDialogImpl/0.0.1536.824@0.0.1536.824" timestamp="1592605200406" />
<state x="503" y="54" key="#templateGenerator" timestamp="1581990133935"> <state width="1515" height="175" key="GridCell.Tab.0.bottom" timestamp="1592638239473">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="503" y="54" key="#templateGenerator/0.0.1536.824@0.0.1536.824" timestamp="1581990133935" /> <state width="1515" height="175" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1592638239473" />
<state x="549" y="157" key="FileChooserDialogImpl" timestamp="1582004315801"> <state width="1515" height="175" key="GridCell.Tab.0.center" timestamp="1592638239473">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="549" y="157" key="FileChooserDialogImpl/0.0.1536.824@0.0.1536.824" timestamp="1582004315801" /> <state width="1515" height="175" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1592638239473" />
<state width="1515" height="147" key="GridCell.Tab.0.bottom" timestamp="1582003939046"> <state width="1515" height="175" key="GridCell.Tab.0.left" timestamp="1592638239473">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1515" height="147" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1582003939046" /> <state width="1515" height="175" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1592638239473" />
<state width="1515" height="147" key="GridCell.Tab.0.center" timestamp="1582003939046"> <state width="1515" height="175" key="GridCell.Tab.0.right" timestamp="1592638239473">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1515" height="147" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1582003939046" /> <state width="1515" height="175" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1592638239473" />
<state width="1515" height="147" key="GridCell.Tab.0.left" timestamp="1582003939045"> <state width="757" height="261" key="GridCell.Tab.1.bottom" timestamp="1592611063544">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1515" height="147" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1582003939045" /> <state width="757" height="261" key="GridCell.Tab.1.bottom/0.0.1536.824@0.0.1536.824" timestamp="1592611063544" />
<state width="1515" height="147" key="GridCell.Tab.0.right" timestamp="1582003939046"> <state width="757" height="261" key="GridCell.Tab.1.center" timestamp="1592611063544">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1515" height="147" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1582003939046" /> <state width="757" height="261" key="GridCell.Tab.1.center/0.0.1536.824@0.0.1536.824" timestamp="1592611063544" />
<state x="279" y="58" key="SettingsEditor" timestamp="1582004322138"> <state width="757" height="261" key="GridCell.Tab.1.left" timestamp="1592611063544">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="279" y="58" key="SettingsEditor/0.0.1536.824@0.0.1536.824" timestamp="1582004322138" /> <state width="757" height="261" key="GridCell.Tab.1.left/0.0.1536.824@0.0.1536.824" timestamp="1592611063544" />
<state x="477" y="240" key="com.intellij.ide.util.TipDialog" timestamp="1582004024357"> <state width="757" height="261" key="GridCell.Tab.1.right" timestamp="1592611063544">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="477" y="240" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1582004024356" /> <state width="757" height="261" key="GridCell.Tab.1.right/0.0.1536.824@0.0.1536.824" timestamp="1592611063544" />
<state x="599" y="206" key="svn.repositoryBrowser" timestamp="1582003770148"> <state x="279" y="58" key="SettingsEditor" timestamp="1592605156082">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="599" y="206" key="svn.repositoryBrowser/0.0.1536.824@0.0.1536.824" timestamp="1582003770148" /> <state x="279" y="58" key="SettingsEditor/0.0.1536.824@0.0.1536.824" timestamp="1592605156082" />
<state x="585" y="199" key="svn4idea.import.options" timestamp="1582003767167"> <state x="477" y="240" key="com.intellij.ide.util.TipDialog" timestamp="1592605238078">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="585" y="199" key="svn4idea.import.options/0.0.1536.824@0.0.1536.824" timestamp="1582003767167" /> <state x="477" y="240" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1592605238078" />
<state x="431" y="145" width="672" height="678" key="search.everywhere.popup" timestamp="1592602138706">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="431" y="145" width="672" height="678" key="search.everywhere.popup/0.0.1536.824@0.0.1536.824" timestamp="1592602138706" />
</component> </component>
</project> </project>

82
directoryListener.py Normal file
View File

@ -0,0 +1,82 @@
from datetime import datetime
from os import scandir
from time import sleep
import numpy as np
import argparse
import cv2
from photoAnalysisUtils import *
from menuAnalysis import *
from mysqlConnect import *
def convert_date(timestamp):
d = datetime.utcfromtimestamp(timestamp)
formated_date = d.strftime('%d %b %Y %H:%M:%S"')
return formated_date
def get_files():
dir_entries = scandir('../orders/')
for entry in dir_entries:
if entry.is_file():
info = entry.stat()
#print(f'{entry.name}\t Created: {convert_date(info.st_ctime)}')
def compareNewest(newest_info):
dir_entries = scandir('orders/')
for entry in dir_entries:
if entry.is_file():
info = entry.stat()
info = info.st_ctime
if datetime.fromtimestamp(info) > datetime.fromtimestamp(newest_info):
return entry
return True
newest_file = 0
newest_info = 0
dir_entries = scandir('orders/')
for entry in dir_entries:
if entry.is_file():
info = entry.stat()
info = info.st_ctime
if newest_file == 0:
newest_file = entry
newest_info = newest_file.stat()
newest_info = newest_info.st_ctime
# print(convert_date(info.st_ctime))
#print(f'{newest_file.name}\t Przypisany: {convert_date(newest_info)}')
else:
if datetime.fromtimestamp(info) > datetime.fromtimestamp(newest_info):
#print(f'{entry.name}\t Nowszy: {convert_date(info)}')
#print(f'{newest_file.name}\t Starszy: {convert_date(newest_info)}')
newest_file = entry
newest_info = newest_file.stat()
newest_info = newest_info.st_ctime
try:
while True:
sleep(1)
if compareNewest(newest_info) != True:
# Sprawdzanie czy nowy plik
newest_file = compareNewest(newest_info)
newest_info = newest_file.stat()
newest_info = newest_info.st_ctime
print('Nowy plik to:')
print(datetime.fromtimestamp(newest_info))
print(f'{newest_file.name}\t Data: {newest_info}')
print(newest_file.name)
# URL Do analizy pliku
url = 'orders/'+ str(newest_file.name)
print(url)
img_tested = cv2.imread(url)
mySqlRecords(menuAnalyseIMG(img_tested))
except KeyboardInterrupt:
pass

View File

@ -3,49 +3,56 @@ import argparse
import cv2 import cv2
from photoAnalysisUtils import * from photoAnalysisUtils import *
img_tested = cv2.imread("samples/CCI18022020.jpg") def menuAnalyseIMG(url):
image = img_tested result_vector = []
img_tested = url
image = img_tested
blurred = cv2.GaussianBlur(image, (5, 5), 0) blurred = cv2.GaussianBlur(image, (5, 5), 0)
edged = cv2.Canny(blurred, 20, 50) edged = cv2.Canny(blurred, 20, 50)
height = image.shape[0] height = image.shape[0]
width = image.shape[1] width = image.shape[1]
referencePoint = open("referencePoint.txt", "r") referencePoint = open("referencePoint.txt", "r")
checkBoxesCords = open("checkBoxesCords.txt", "r") checkBoxesCords = open("checkBoxesCords.txt", "r")
referencePoint = referencePoint.readlines() referencePoint = referencePoint.readlines()
checkBoxesCords = checkBoxesCords.readlines() checkBoxesCords = checkBoxesCords.readlines()
for corners in referencePoint: for corners in referencePoint:
template_x, template_y = corners.split() template_x, template_y = corners.split()
image, x, y = searchReferencePointCorner(image) image, x, y = searchReferencePointCorner(image)
offsetX = int(template_x) - x offsetX = int(template_x) - x
offsetY = int(template_y) - y offsetY = int(template_y) - y
i=1 i=1
for checkBox in checkBoxesCords: for checkBox in checkBoxesCords:
x, y, w, h = checkBox.split() x, y, w, h = checkBox.split()
x = int(x) - offsetX x = int(x) - offsetX
y = int(y) - offsetY y = int(y) - offsetY
w = int(w) w = int(w)
h = int(h) h = int(h)
cv2.rectangle(image, (x, y), (x + w, y + h), (36, 255, 12), 2) cv2.rectangle(image, (x, y), (x + w, y + h), (36, 255, 12), 2)
crop_img = edged[y:y + h, x:x + w] crop_img = edged[y:y + h, x:x + w]
n_white_pix = np.sum(crop_img == 255) n_white_pix = np.sum(crop_img == 255)
n_black_pix = np.sum(crop_img == 0) n_black_pix = np.sum(crop_img == 0)
if(n_white_pix+n_black_pix)*0.2 < n_white_pix: if(n_white_pix+n_black_pix)*0.2 < n_white_pix:
print(str(i)+" FILL") #print(str(i)+" FILL")
else: result_vector.append([i, 1])
print(str(i)+" EMPTY") else:
#print("White i ="+str(i)+" white = "+str(n_white_pix)) #print(str(i)+" EMPTY")
#print("Black i ="+str(i)+" black = "+str(n_black_pix)) result_vector.append([i, 0])
#cv2.imwrite("maska"+str(i)+".jpg", crop_img) #print("White i ="+str(i)+" white = "+str(n_white_pix))
i = i+1 #print("Black i ="+str(i)+" black = "+str(n_black_pix))
#cv2.imwrite("maska"+str(i)+".jpg", crop_img)
i = i+1
cv2.imwrite("tested.jpg", image) cv2.imwrite("tested.jpg", image)
return result_vector
# img_tested = cv2.imread('orders/1.jpg')
# menuAnalyseIMG(img_tested)

70
mysqlConnect.py Normal file
View File

@ -0,0 +1,70 @@
import mysql.connector
import random
import string
from datetime import datetime
def id_generator(size=5, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
def mySqlRecords(array):
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="",
database="kelner"
)
timestamp = 1545730073
mycursor = mydb.cursor(buffered=True)
# Wyciąganie aktualnego aktywnego szablonu oraz przypisywanie ID do activeTemplateID
mycursor.execute("SELECT id FROM template WHERE active=1")
myresult = mycursor.fetchone()
activeTemplateID = str(myresult[0])
# for x in myresult:
# print(x)
price = 0
# array = [[1, 0], [2, 0], [3, 1], [4, 0], [5, 0], [6, 0], [7, 1], [8, 0], [9, 1]]
# Wyliczanie ceny
for x in array:
if x[1] == 1:
# Wyciaganie szablonu dan po id szablonu oraz numerze checkboxu
checkboxnumber = str(x[0])
mycursor.execute("SELECT * FROM templatedishmap WHERE template_id=" + activeTemplateID + " AND checkboxnumber=" + checkboxnumber)
myresult = mycursor.fetchone()
price = price + myresult[3]*myresult[5]
# Dodanie zamówienia
sql = "INSERT INTO orders (number, price, active, created_at) VALUES (%s, %s, 1, %s)"
val = (str(id_generator()), str(price), str(datetime.fromtimestamp(timestamp)))
mycursor.execute(sql, val)
mydb.commit()
# Sprawdzenie id ostatniego zamowienia
mycursor = mydb.cursor(buffered=True)
mycursor.execute("SELECT id FROM orders ORDER BY id DESC")
myresult = mycursor.fetchone()
addedID = myresult[0]
for x in array:
if x[1] == 1:
# Wyciaganie szablonu dan po id szablonu oraz numerze checkboxu
checkboxnumber = str(x[0])
mycursor.execute("SELECT * FROM templatedishmap WHERE template_id=" + activeTemplateID + " AND checkboxnumber=" + checkboxnumber)
myresult = mycursor.fetchone()
templateDishMapID = myresult[0]
# Dodawanie poszczegolnych potraw do zamowienia
sql = "INSERT INTO orders_template_dish_map (order_id, template_id, created_at) VALUES (%s, %s, %s)"
val = (str(addedID), str(templateDishMapID), str(datetime.fromtimestamp(timestamp)))
mycursor.execute(sql, val)
mydb.commit()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 603 KiB

View File

@ -22,6 +22,7 @@ def searchReferencePointCorner(image):
x, y, w, h = cv2.boundingRect(approx) x, y, w, h = cv2.boundingRect(approx)
aspect_ratio = w / float(h) aspect_ratio = w / float(h)
area = cv2.contourArea(c) area = cv2.contourArea(c)
if len(approx) == 4 and area < threshold_max_area and area > threshold_min_area and (aspect_ratio >= 0.9 and aspect_ratio <= 1.1): if len(approx) == 4 and area < threshold_max_area and area > threshold_min_area and (aspect_ratio >= 0.9 and aspect_ratio <= 1.1):
# Prawy górny róg # Prawy górny róg
if x > width * 0.80 and y < height * 0.20: if x > width * 0.80 and y < height * 0.20: