-
Notifications
You must be signed in to change notification settings - Fork 1
/
shooping.py
63 lines (50 loc) · 1.74 KB
/
shooping.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from tools.face_recognition import detector
import constants
import sqlite3
from termcolor import colored
from tools import color_objects_detect
##conect to the local database
conn = sqlite3.connect('store.db')
c = conn.cursor()
def getUser():
return detector.get_faceID(constants.shop_camera), False
def storeProducts():
red_objetcs=0
green_objetcs=0
yellow_objetcs=0
try:
c.execute("SELECT COUNT(Name),color FROM products GROUP BY color")
rows = c.fetchall()
print(rows)
for row in rows:
if 'yellow' in row[1]:
yellow_objetcs = row[0]
elif 'green' in row[1]:
green_objetcs = row[0]
except sqlite3.Error as er :
print (colored("SQLite Error: "+ str(er), 'red'))
print("green:",green_objetcs)
print("yellow:",yellow_objetcs)
return green_objetcs, yellow_objetcs
def getItem():
green, yellow = color_objects_detect.detect_objects(constants.produtcs_camera)
green_objetcs, yellow_objetcs = storeProducts()
diffGreen = green-green_objetcs
diffYellow = yellow-yellow_objetcs
if(diffGreen>0 or diffGreen <0):
c.execute("SELECT * FROM products WHERE color = 'green'")
rows = c.fetchall()
for row in rows:
c.execute("DELETE FROM products WHERE ID = "+str(row[0]))
conn.commit()
break
return 2, diffGreen
elif(diffYellow>0 or diffYellow <0):
c.execute("SELECT * FROM products WHERE color = 'yellow'")
rows = c.fetchall()
for row in rows:
c.execute("DELETE FROM products WHERE ID = "+str(row[0]))
conn.commit()
break
return 3, diffYellow
return None, True