-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkk.py
More file actions
64 lines (56 loc) · 2.1 KB
/
kk.py
File metadata and controls
64 lines (56 loc) · 2.1 KB
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
64
import tensorflow.keras
import numpy as np
import cv2
# Disable scientific notation for clarity
np.set_printoptions(suppress=True)
# Load the model
model = tensorflow.keras.models.load_model('keras_model.h5')
# Create the array of the right shape to feed into the keras model
# The 'length' or number of images you can put into the array is
# determined by the first position in the shape tuple, in this case 1.
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
# Replace this with the path to your image
cam = cv2.VideoCapture(0)
text = ""
text2=""
text3="NAME:"
text4="CALORIES:"
while True:
# _,img = cv2.imread('right.jpg')
_,img = cam.read()
img = cv2.resize(img,(224, 224))
#turn the image into a numpy array
image_array = np.asarray(img)
# Normalize the image
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
# Load the image into the array
data[0] = normalized_image_array
# run the inference
prediction = model.predict(data)
# print(prediction)
for i in prediction:
if i[0] > 0.7:
text ="apple"
text2="52 kcal"
if i[1] > 0.7:
text ="banana"
text2="89 kcal"
if i[2] > 0.7:
text ="egg"
text2="155 kcal"
if i[3] > 0.7:
text ="brown bread"
text2="75 kcal"
# print(text)
img = cv2.resize(img,(500, 500))
cv2.rectangle(img, (500,500), (3,350), (240,240,240), cv2.FILLED)
cv2.putText(img,text3,(10,400),cv2.FONT_HERSHEY_COMPLEX_SMALL,2,(0,0,0),1)
cv2.putText(img,text4,(10,440),cv2.FONT_HERSHEY_COMPLEX_SMALL,2,(0,0,0),1)
cv2.putText(img,text,(170,400),cv2.FONT_HERSHEY_COMPLEX_SMALL,2,(0,0,0),1)
cv2.putText(img,text2,(250,440),cv2.FONT_HERSHEY_COMPLEX_SMALL,2,(0,0,0),1)
if cv2.waitKey(1) & 0xFF == ord('q'): #This adds a Delay and looks for the key press inorder to break the loop
cv2.destroyAllWindows()
break
cv2.imshow('img',img)
cv2.waitKey(1)
cv2.createButton