Graduate

Change cropping method to imporve accuracy

...@@ -126,12 +126,12 @@ def verify(): ...@@ -126,12 +126,12 @@ def verify():
126 break 126 break
127 127
128 if verified_id != None: 128 if verified_id != None:
129 - sql = "SELECT DATE(attendance_time) FROM student_attendance WHERE (lecture_id=%s) AND (student_id=%s) AND (DATE(attendance_time) = CURDATE());"
130 - cursor.execute(sql, ('0', verified_id))
131 sql = "SELECT student_name FROM student WHERE student_id = %s" 129 sql = "SELECT student_name FROM student WHERE student_id = %s"
132 cursor.execute(sql, (verified_id)) 130 cursor.execute(sql, (verified_id))
133 row_data = cursor.fetchone() 131 row_data = cursor.fetchone()
134 verified_name = row_data['student_name'] 132 verified_name = row_data['student_name']
133 + sql = "SELECT DATE(attendance_time) FROM student_attendance WHERE (lecture_id=%s) AND (student_id=%s) AND (DATE(attendance_time) = CURDATE());"
134 + cursor.execute(sql, ('0', verified_id))
135 if cursor.rowcount == 0: 135 if cursor.rowcount == 0:
136 sql = "INSERT INTO student_attendance(lecture_id, student_id, status) VALUES (%s, %s, %s)" 136 sql = "INSERT INTO student_attendance(lecture_id, student_id, status) VALUES (%s, %s, %s)"
137 # TODO: attend / late 처리 137 # TODO: attend / late 처리
......
1 [verification_server] 1 [verification_server]
2 model=models/20200816-080621 2 model=models/20200816-080621
3 -threshold=0.75 3 +threshold=0.765
4 image_size=160 4 image_size=160
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
6 <style> 6 <style>
7 #container { 7 #container {
8 margin: 0px auto; 8 margin: 0px auto;
9 - width: 640px;
10 - height: 480px;
11 border: 10px #333 solid; 9 border: 10px #333 solid;
12 } 10 }
13 #videoInput { 11 #videoInput {
...@@ -24,7 +22,9 @@ ...@@ -24,7 +22,9 @@
24 22
25 function init() 23 function init()
26 { 24 {
27 - let video = document.getElementById("videoInput"); 25 + let video = document.getElementById('videoInput');
26 + let container = document.getElementById('container');
27 + let canvasOutput = document.getElementById("canvasOutput");
28 if (navigator.mediaDevices.getUserMedia){ 28 if (navigator.mediaDevices.getUserMedia){
29 navigator.mediaDevices.getUserMedia({ video: true }) 29 navigator.mediaDevices.getUserMedia({ video: true })
30 .then(function (stream) { 30 .then(function (stream) {
...@@ -32,6 +32,10 @@ function init() ...@@ -32,6 +32,10 @@ function init()
32 video.addEventListener('canplay', () => { 32 video.addEventListener('canplay', () => {
33 video.width = video.videoWidth; 33 video.width = video.videoWidth;
34 video.height = video.videoHeight; 34 video.height = video.videoHeight;
35 + container.style.width = video.videoWidth + 'px';
36 + container.style.height = video.videoHeight + 'px';
37 + canvasOutput.width = video.videoWidth;
38 + canvasOutput.height = video.videoHeight;
35 load_cascade(); 39 load_cascade();
36 }); 40 });
37 }).catch(function (err0r) { 41 }).catch(function (err0r) {
...@@ -59,7 +63,7 @@ let canvasOutput = document.getElementById("canvasOutput"); ...@@ -59,7 +63,7 @@ let canvasOutput = document.getElementById("canvasOutput");
59 let canvasContext = canvasOutput.getContext('2d'); 63 let canvasContext = canvasOutput.getContext('2d');
60 let src = new cv.Mat(video.height, video.width, cv.CV_8UC4); 64 let src = new cv.Mat(video.height, video.width, cv.CV_8UC4);
61 let dst = new cv.Mat(video.height, video.width, cv.CV_8UC4); 65 let dst = new cv.Mat(video.height, video.width, cv.CV_8UC4);
62 -let gray = new cv.Mat(); 66 +// let gray = new cv.Mat();
63 let cap = new cv.VideoCapture(video); 67 let cap = new cv.VideoCapture(video);
64 let faces = new cv.RectVector(); 68 let faces = new cv.RectVector();
65 let classifier = new cv.CascadeClassifier(); 69 let classifier = new cv.CascadeClassifier();
...@@ -109,22 +113,21 @@ function processVideo() { ...@@ -109,22 +113,21 @@ function processVideo() {
109 let begin = Date.now(); 113 let begin = Date.now();
110 // start processing. 114 // start processing.
111 cap.read(src); 115 cap.read(src);
116 + cv.flip(src, src, 1);
112 src.copyTo(dst); 117 src.copyTo(dst);
113 - cv.cvtColor(dst, gray, cv.COLOR_RGBA2GRAY, 0); 118 + // cv.cvtColor(dst, gray, cv.COLOR_RGBA2GRAY, 0);
114 // detect faces. 119 // detect faces.
115 - let msize = new cv.Size(120, 120); 120 + let msize = new cv.Size(video.width / 4, video.height / 4);
116 - classifier.detectMultiScale(gray, faces, 1.1, 3, 0, msize); 121 + classifier.detectMultiScale(dst, faces, 1.1, 3, 0, msize);
117 // draw faces. 122 // draw faces.
118 console.log('draw faces'); 123 console.log('draw faces');
119 for (let i = 0; i < faces.size(); ++i) { 124 for (let i = 0; i < faces.size(); ++i) {
120 let face = faces.get(i); 125 let face = faces.get(i);
121 let point1 = new cv.Point(face.x, face.y); 126 let point1 = new cv.Point(face.x, face.y);
122 let point2 = new cv.Point(face.x + face.width, face.y + face.height); 127 let point2 = new cv.Point(face.x + face.width, face.y + face.height);
123 - cv.rectangle(dst, point1, point2, [255, 0, 0, 255]); 128 + cv.rectangle(dst, point1, point2, [255, 0, 0, 255], 8);
124 let cropped = new cv.Mat(); 129 let cropped = new cv.Mat();
125 - let margin_x = face.width / 5; 130 + let rect = new cv.Rect(face.x, face.y, face.width, face.height);
126 - let margin_y = face.height / 5;
127 - let rect = new cv.Rect(Math.max(face.x - margin_x, 0), Math.max(face.y - margin_y, 0), face.width + margin_x, face.height + margin_y);
128 cropped = src.roi(rect); 131 cropped = src.roi(rect);
129 let tempCanvas = document.createElement("canvas"); 132 let tempCanvas = document.createElement("canvas");
130 cv.imshow(tempCanvas,cropped); 133 cv.imshow(tempCanvas,cropped);
......
...@@ -38,18 +38,18 @@ function detect_face() ...@@ -38,18 +38,18 @@ function detect_face()
38 ctx.drawImage(tempImage, 0, 0); 38 ctx.drawImage(tempImage, 0, 0);
39 let src = cv.imread(canvas); 39 let src = cv.imread(canvas);
40 let dst = new cv.Mat(src.cols, src.rows, cv.CV_8UC4); 40 let dst = new cv.Mat(src.cols, src.rows, cv.CV_8UC4);
41 - let gray = new cv.Mat(); 41 + // let gray = new cv.Mat();
42 let faces = new cv.RectVector(); 42 let faces = new cv.RectVector();
43 let classifier = new cv.CascadeClassifier(); 43 let classifier = new cv.CascadeClassifier();
44 classifier.load('haarcascade_frontalface_default.xml'); 44 classifier.load('haarcascade_frontalface_default.xml');
45 src.copyTo(dst); 45 src.copyTo(dst);
46 - cv.cvtColor(dst, gray, cv.COLOR_RGBA2GRAY, 0); 46 + // cv.cvtColor(dst, gray, cv.COLOR_RGBA2GRAY, 0);
47 - let msize = new cv.Size(120, 120); 47 + let msize = new cv.Size(tempImage.width / 4, tempImage.height / 4);
48 // detect faces. 48 // detect faces.
49 - classifier.detectMultiScale(gray, faces, 1.1, 3, 0, msize); 49 + classifier.detectMultiScale(dst, faces, 1.1, 3, 0, msize);
50 if (faces.size() == 0) 50 if (faces.size() == 0)
51 { 51 {
52 - alert('얼굴이 인식되지 않았습니다.'); 52 + alert('얼굴이 인식되지 않았습니다. 얼굴 이미지가 작지 않은지 확인해주세요.');
53 } 53 }
54 else if (faces.size() > 1) 54 else if (faces.size() > 1)
55 { 55 {
...@@ -60,10 +60,8 @@ function detect_face() ...@@ -60,10 +60,8 @@ function detect_face()
60 let face = faces.get(i); 60 let face = faces.get(i);
61 let point1 = new cv.Point(face.x, face.y); 61 let point1 = new cv.Point(face.x, face.y);
62 let point2 = new cv.Point(face.x + face.width, face.y + face.height); 62 let point2 = new cv.Point(face.x + face.width, face.y + face.height);
63 - cv.rectangle(dst, point1, point2, [255, 0, 0, 255]); 63 + cv.rectangle(dst, point1, point2, [255, 0, 0, 255], 8);
64 - let margin_x = face.width / 5; 64 + let rect = new cv.Rect(face.x, face.y, face.width, face.height);
65 - let margin_y = face.height / 5;
66 - let rect = new cv.Rect(Math.max(face.x - margin_x, 0), Math.max(face.y - margin_y, 0), face.width + margin_x, face.height + margin_y);
67 let cropped = src.roi(rect); 65 let cropped = src.roi(rect);
68 cv.imshow(tempCanvas,cropped); 66 cv.imshow(tempCanvas,cropped);
69 } 67 }
......