Skip to content

Commit 873a21b

Browse files
authored
Merge pull request #1 from codewhizz/recognization
Recognization Feature Works. Fixed Bugs as well ;)
2 parents fd692e0 + 9b13733 commit 873a21b

13 files changed

+108
-86
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,8 @@ fabric.properties
7171
.idea/caches/build_file_checksums.ser
7272

7373
# our project
74+
Attendance/
75+
training_images/
76+
unknown_images/
77+
files/trainer.yml
7478
trainer.yml
75-
training_images/

files/student_details.csv

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Id,Name
1+
ID,Name
22
,
33
,
44
,
@@ -17,5 +17,4 @@ Id,Name
1717
,
1818
,
1919
,
20-
0, Test
21-
1,Aslam
20+
0,Test

main.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
import pyfiglet
77

88

9+
# input live stream from a recorder
10+
INPUT_VIDEO = "http://192.168.1.100:8080/video"
11+
12+
# input from saved video
13+
# INPUT_VIDEO = "video.avi"
14+
15+
# input from a device attached to computer
16+
# INPUT_VIDEO = 0 # or -1 if 0 doesn't work
17+
18+
919
# creating the title bar function
1020
def title_bar():
1121
# os.system('cls') # for windows
@@ -31,16 +41,16 @@ def main_menu():
3141
choice = int(input("Enter Choice: "))
3242

3343
if choice == 1:
34-
check_camera()
44+
check_camera(INPUT_VIDEO)
3545
break
3646
elif choice == 2:
37-
capture_face()
47+
capture_face(INPUT_VIDEO)
3848
break
3949
elif choice == 3:
4050
train_face()
4151
break
4252
elif choice == 4:
43-
recognize_face()
53+
recognize_face(INPUT_VIDEO)
4454
break
4555
elif choice == 5:
4656
print("Thank You =)")
@@ -57,15 +67,15 @@ def main_menu():
5767

5868
# ---------------------------------------------------------
5969
# calling the camera test function from check camera.py file
60-
def check_camera():
61-
capture_video.start()
70+
def check_camera(input_video):
71+
capture_video.start(input_video)
6272
main_menu()
6373

6474

6575
# --------------------------------------------------------------
6676
# calling the take image function form capture image.py file
67-
def capture_face():
68-
capture_images.capture()
77+
def capture_face(input_video):
78+
capture_images.capture(input_video)
6979
main_menu()
7080

7181

@@ -78,8 +88,8 @@ def train_face():
7888

7989
# --------------------------------------------------------------------
8090
# calling the recognize_attendance from recognize.py file
81-
def recognize_face():
82-
recognize.mark_attendance()
91+
def recognize_face(input_video):
92+
recognize.mark_attendance(input_video)
8393
main_menu()
8494

8595

0 Bytes
Binary file not shown.
42 Bytes
Binary file not shown.
44 Bytes
Binary file not shown.
90 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

modules/capture_images.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@
33
import cv2
44
import unicodedata # to check if entered in different unicode format
55

6-
# input live stream from a recorder
7-
# URL = "http://192.168.1.103:8080/video"
8-
9-
# input from saved video
10-
# URL = "video.avi"
11-
12-
# input from a device attached to computer
13-
URL = 0 # or -1
14-
156

167
# check if student_id is a number
178
def is_number(_id):
@@ -31,13 +22,14 @@ def is_number(_id):
3122

3223

3324
# Capture Image function definition
34-
def capture():
25+
def capture(input_video):
3526
student_id = input("Enter Your ID (numbers only): ")
3627
name = input("Enter Your Name (alphabets only): ")
3728

3829
# if "student_id is a number" and "name consists of alphabetic chars only" then
3930
if is_number(student_id) and name.isalpha():
40-
cap = cv2.VideoCapture(URL)
31+
# store input video stream in cap variable
32+
cap = cv2.VideoCapture(input_video)
4133

4234
# using haar cascade
4335
haar_cascade_path = "files" + os.sep + "haarcascade_frontalface_default.xml"
@@ -48,35 +40,38 @@ def capture():
4840
while True:
4941
# capture frame-by-frame
5042
ret, img = cap.read()
51-
52-
if ret is True:
53-
# operations on the frame come here
43+
if ret is True: # video is detected
44+
# convert frame to grayscale
5445
gray_frame = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
5546

47+
# detect faces using haar cascade detector
5648
faces = detector.detectMultiScale(gray_frame, 1.3, 5)
5749
for(x, y, w, h) in faces:
58-
cv2.rectangle(gray_frame, (x, y), (x+w, y+h), (255, 0, 0), 2) # ##gray
50+
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2) # ##gray
5951

6052
# incrementing number
6153
increment_num += 1
6254

6355
# saving the captured face in the data-set folder training_images
6456
cv2.imwrite("training_images" + os.sep + name + "." + student_id + '.' +
65-
str(increment_num) + ".jpg", gray_frame[y:y+h, x:x+w]) # ##gray[y:y+h, x:x+w]
57+
str(increment_num) + ".jpg", img[y:y+h, x:x+w]) # ##gray[y:y+h, x:x+w]
6658

6759
# display the resulting frame
68-
cv2.imshow('frame', gray_frame) # ##gray
60+
cv2.imshow('Capturing Face - Attendance using Face Recognition', img) # ##gray
6961

7062
# wait for 100 milliseconds
7163
if cv2.waitKey(100) & 0xFF == ord('q'):
7264
break
7365
# break if the sample number is more than 100
7466
elif increment_num > 60:
7567
break
76-
else:
68+
else: # video not detected
7769
break
70+
71+
# when everything is done
7872
cap.release()
7973
cv2.destroyAllWindows()
74+
8075
# res = "Images Saved for ID : " + student_id + " Name : " + name
8176
row = [student_id, name]
8277
with open("files" + os.sep + "student_details.csv", 'a+') as csv_file:

modules/capture_video.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
11
import cv2
22

3-
# input live stream from a recorder
4-
# URL = "http://192.168.1.103:8080/video"
53

6-
# input from saved video
7-
# URL = "video.avi"
4+
def start(input_video):
5+
# store input video stream capture in cap variable
6+
cap = cv2.VideoCapture(input_video)
87

9-
# input from a device attached to computer
10-
URL = 0 # or -1
11-
12-
13-
def start():
14-
cap = cv2.VideoCapture(URL)
158
while cap.isOpened():
169
# capture frame-by-frame
1710
ret, frame = cap.read()
1811
if ret is True: # video is detected
12+
# convert frame to grayscale
1913
# gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
2014

2115
# display the resulting frame
22-
cv2.imshow('frame', frame)
16+
cv2.imshow('Checking Video - Attendance using Face Recognition', frame)
2317

2418
if cv2.waitKey(1) & 0xFF == ord('q'):
2519
break
2620
else: # video not detected
2721
break
22+
2823
# when everything is done
2924
cap.release()
3025
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)