-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (50 loc) · 1.73 KB
/
main.py
File metadata and controls
62 lines (50 loc) · 1.73 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
import os
import cvzone
from cvzone.ClassificationModule import Classifier
import cv2
cap = cv2.VideoCapture(1)
classifier = Classifier('Resources/Model/keras_model.h5', 'Resources/Model/labels.txt')
imgArrow = cv2.imread('Resources/arrow.png', cv2.IMREAD_UNCHANGED)
classIDBin = 0
# Import all the waste images
imgWasteList = []
pathFolderWaste = "Resources/Waste"
pathList = os.listdir(pathFolderWaste)
for path in pathList:
imgWasteList.append(cv2.imread(os.path.join(pathFolderWaste, path), cv2.IMREAD_UNCHANGED))
# Import all the wastebin images
imgBinsList = []
pathFolderBins = "Resources/Bins"
pathList = os.listdir(pathFolderBins)
for path in pathList:
imgBinsList.append(cv2.imread(os.path.join(pathFolderBins, path), cv2.IMREAD_UNCHANGED))
# 0 = Recyclable
# 1 = Hazardous
# 2 = Food
# 3 = Residual
classDic = {0: None,
1: 0,
2: 0,
3: 0,
4: 1,
5: 2,
6: 3,
7: 0
}
while True:
_, img = cap.read()
imgResize = cv2.resize(img, (454, 340))
imgBackground = cv2.imread('Resources/background.png')
predection = classifier.getPrediction(img)
classID = predection[1]
print(classID)
if classID != 0:
imgBackground = cvzone.overlayPNG(imgBackground, imgWasteList[classID - 1], (909, 127))
imgBackground = cvzone.overlayPNG(imgBackground, imgArrow, (978, 320))
classIDBin = classDic[classID]
imgBackground = cvzone.overlayPNG(imgBackground, imgBinsList[classIDBin], (895, 374))
imgBackground[148:148 + 340, 159:159 + 454] = imgResize
# Displays
# cv2.imshow("Image", img)
cv2.imshow("Output", imgBackground)
cv2.waitKey(1)