-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-acquisition.py
48 lines (41 loc) · 1.44 KB
/
data-acquisition.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
import sqlite3
import cv2
import numpy as np
face_cascade_file = 'cascade classifier/face-detect.xml'
face_cascade = cv2.CascadeClassifier(face_cascade_file)
conn = sqlite3.connect('database/mahasiswa.db')
c = conn.cursor()
total_images = 10
nim = int(input("Masukkan NIM\t\t: "))
nama = input("Masukkan Nama Mahasiswa\t: ")
c.execute("INSERT INTO mahasiswa VALUES (?, ?)", (nim, nama))
conn.commit()
c.execute("SELECT * FROM mahasiswa")
print(c.fetchall())
conn.commit()
camera = cv2.VideoCapture(-1)
counter = 1
while True and counter != 11:
_, frame = camera.read()
frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(frame_gray, 1.3, 3)
for x, y, w, h in faces:
if w*h >= 40000 and w*h <= 90000:
cv2.rectangle(frame, (x,y), (x+w, y+h), (0,255,0), 3)
if cv2.waitKey(1) & 0xff == ord('c'):
roi_face = frame_gray[y:y+h, x:x+w]
cv2.imwrite(f'faces data/mahasiswa.{nim}.{nama}.{counter}.jpg', roi_face)
print(f"{counter} Images of {nama} Captured")
counter += 1
if counter > total_images:
break
cv2.imshow('Face Data Acquisition', frame)
if cv2.waitKey(1) & 0xff == ord('q'):
break
camera.release()
cv2.destroyAllWindows()
c.execute("SELECT * FROM mahasiswa")
print("Student Who Have Submitted:\n")
print(c.fetchall())
conn.commit()
conn.close()