Showing
2 changed files
with
12 additions
and
9 deletions
... | @@ -31,8 +31,9 @@ function activate() | ... | @@ -31,8 +31,9 @@ function activate() |
31 | 31 | ||
32 | function detect_face() | 32 | function detect_face() |
33 | { | 33 | { |
34 | - alert(tempImage) | ||
35 | let canvas = document.createElement('canvas'); | 34 | let canvas = document.createElement('canvas'); |
35 | + canvas.width = tempImage.width; | ||
36 | + canvas.height = tempImage.height; | ||
36 | let ctx = canvas.getContext('2d') | 37 | let ctx = canvas.getContext('2d') |
37 | ctx.drawImage(tempImage, 0, 0); | 38 | ctx.drawImage(tempImage, 0, 0); |
38 | let src = cv.imread(canvas); | 39 | let src = cv.imread(canvas); |
... | @@ -41,7 +42,6 @@ function detect_face() | ... | @@ -41,7 +42,6 @@ function detect_face() |
41 | let faces = new cv.RectVector(); | 42 | let faces = new cv.RectVector(); |
42 | let classifier = new cv.CascadeClassifier(); | 43 | let classifier = new cv.CascadeClassifier(); |
43 | classifier.load('haarcascade_frontalface_default.xml'); | 44 | classifier.load('haarcascade_frontalface_default.xml'); |
44 | - | ||
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(120, 120); |
... | @@ -55,8 +55,8 @@ function detect_face() | ... | @@ -55,8 +55,8 @@ function detect_face() |
55 | cv.rectangle(dst, point1, point2, [255, 0, 0, 255]); | 55 | cv.rectangle(dst, point1, point2, [255, 0, 0, 255]); |
56 | // margin 44 | 56 | // margin 44 |
57 | let rect = new cv.Rect(Math.max(face.x - 22, 0), Math.max(face.y - 22, 0), face.width + 22, face.height + 22); | 57 | let rect = new cv.Rect(Math.max(face.x - 22, 0), Math.max(face.y - 22, 0), face.width + 22, face.height + 22); |
58 | - let cropped = src.roi(rect); | 58 | + let cropped = src.roi(rect); |
59 | - cv.imshow(tempCanvas,cropped); | 59 | + cv.imshow(tempCanvas,cropped); |
60 | } | 60 | } |
61 | let preview = document.getElementById('preview'); | 61 | let preview = document.getElementById('preview'); |
62 | cv.imshow(preview, dst); | 62 | cv.imshow(preview, dst); |
... | @@ -102,7 +102,10 @@ var loadFile = function(event) { | ... | @@ -102,7 +102,10 @@ var loadFile = function(event) { |
102 | reader.readAsDataURL(event.target.files[0]); | 102 | reader.readAsDataURL(event.target.files[0]); |
103 | reader.onload = function() { | 103 | reader.onload = function() { |
104 | tempImage.src = reader.result; | 104 | tempImage.src = reader.result; |
105 | - detect_face(); | 105 | + tempImage.onload = function() |
106 | + { | ||
107 | + detect_face(); | ||
108 | + } | ||
106 | }; | 109 | }; |
107 | }; | 110 | }; |
108 | </script> | 111 | </script> |
... | @@ -120,13 +123,13 @@ and is wrapped around the whole page content, except for the footer in this exam | ... | @@ -120,13 +123,13 @@ and is wrapped around the whole page content, except for the footer in this exam |
120 | <div class="w3-row", style='text-align:center'> | 123 | <div class="w3-row", style='text-align:center'> |
121 | <h2><b>얼굴 파일을 등록해주세요 (jpeg only)</b></h2> | 124 | <h2><b>얼굴 파일을 등록해주세요 (jpeg only)</b></h2> |
122 | <div> | 125 | <div> |
123 | - 학번: <input type="text" name="student_id"><br> | 126 | + 학번: <input type="text" id="student_id"><br> |
124 | - 이름: <input type="text" name="student_name"><br><br> | 127 | + 이름: <input type="text" id="student_name"><br><br> |
125 | <input type="file" id="fileloader" name="file" onchange="loadFile(event)" autocomplete="off" accept="image/jpeg" required disabled> | 128 | <input type="file" id="fileloader" name="file" onchange="loadFile(event)" autocomplete="off" accept="image/jpeg" required disabled> |
126 | <div> | 129 | <div> |
127 | <canvas id="preview"></canvas> | 130 | <canvas id="preview"></canvas> |
128 | </div> | 131 | </div> |
129 | - <input id="sender" type="button" onclick="submit" value="등록" disabled> | 132 | + <input id="sender" type="button" onclick="submit()" value="등록" disabled> |
130 | </div> | 133 | </div> |
131 | </div> | 134 | </div> |
132 | </div> | 135 | </div> | ... | ... |
-
Please register or login to post a comment