ktejeshnaidu commited on
Commit
7487330
·
verified ·
1 Parent(s): 62b77d4

Delete main.py

Browse files
Files changed (1) hide show
  1. main.py +0 -61
main.py DELETED
@@ -1,61 +0,0 @@
1
- import cv2
2
- from model import EmotionPredictor
3
-
4
- cap = cv2.VideoCapture(0)
5
- predictor = EmotionPredictor()
6
-
7
- face_cascade = cv2.CascadeClassifier(
8
- cv2.data.haarcascades + "haarcascade_frontalface_default.xml"
9
- )
10
-
11
- if face_cascade.empty():
12
- raise RuntimeError("Failed to load Haar Cascade")
13
-
14
- FRAME_SKIP = 2
15
- frame_count = 0
16
- current_faces = []
17
-
18
-
19
- while True:
20
- ret, frame = cap.read()
21
- if not ret:
22
- break
23
-
24
- frame_count += 1
25
-
26
- if frame_count % FRAME_SKIP == 0:
27
- gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
28
- detected = face_cascade.detectMultiScale(
29
- gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30)
30
- )
31
- current_faces = []
32
- if len(detected) > 0:
33
- x, y, w, h = max(detected, key=lambda r: r[2]*r[3])
34
-
35
- y1, y2 = max(0, y), min(frame.shape[0], y + h)
36
- x1, x2 = max(0, x), min(frame.shape[1], x + w)
37
-
38
- if y2 > y1 and x2 > x1:
39
- face_rgb = cv2.cvtColor(frame[y1:y2, x1:x2], cv2.COLOR_BGR2RGB)
40
- label = predictor.predict(face_rgb)
41
- current_faces.append((x, y, w, h, label))
42
-
43
- for (x, y, w, h, label) in current_faces:
44
- cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
45
- cv2.putText(
46
- frame, label, (x, y - 10),
47
- cv2.FONT_HERSHEY_SIMPLEX, 0.9, (255, 255, 255), 2
48
- )
49
-
50
- cv2.imshow("Emotion Detection", frame)
51
-
52
- if cv2.waitKey(1) & 0xFF == ord("q"):
53
- break
54
- if cv2.getWindowProperty("Emotion Detection", cv2.WND_PROP_VISIBLE) < 1:
55
- break
56
-
57
- cap.release()
58
- cv2.destroyAllWindows()
59
-
60
-
61
-