Graduate

Resize registered image

1 -flask run --host 0.0.0.0 --cert=cert.pem --key=key.pem 1 +python3 -m flask run --host 0.0.0.0 --port 443 --cert=cert.pem --key=key.pem
......
...@@ -112,7 +112,9 @@ function processVideo() { ...@@ -112,7 +112,9 @@ function processVideo() {
112 let point2 = new cv.Point(face.x + face.width, face.y + face.height); 112 let point2 = new cv.Point(face.x + face.width, face.y + face.height);
113 cv.rectangle(dst, point1, point2, [255, 0, 0, 255]); 113 cv.rectangle(dst, point1, point2, [255, 0, 0, 255]);
114 let cropped = new cv.Mat(); 114 let cropped = new cv.Mat();
115 - let rect = new cv.Rect(Math.max(face.x - 22, 0), Math.max(face.y - 22, 0), face.width + 22, face.height + 22); 115 + let margin_x = face.width / 5;
116 + let margin_y = face.height / 5;
117 + 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);
116 cropped = src.roi(rect); 118 cropped = src.roi(rect);
117 let tempCanvas = document.createElement("canvas"); 119 let tempCanvas = document.createElement("canvas");
118 cv.imshow(tempCanvas,cropped); 120 cv.imshow(tempCanvas,cropped);
......
...@@ -47,32 +47,39 @@ function detect_face() ...@@ -47,32 +47,39 @@ function detect_face()
47 let msize = new cv.Size(120, 120); 47 let msize = new cv.Size(120, 120);
48 // detect faces. 48 // detect faces.
49 classifier.detectMultiScale(gray, faces, 1.1, 3, 0, msize); 49 classifier.detectMultiScale(gray, faces, 1.1, 3, 0, msize);
50 + if (faces.size() == 0)
51 + {
52 + alert('얼굴이 인식되지 않았습니다.');
53 + }
54 + else if (faces.size() > 1)
55 + {
56 + alert('하나의 얼굴만 등록해주세요.')
57 + }
50 // draw faces. 58 // draw faces.
51 for (let i = 0; i < faces.size(); ++i) { 59 for (let i = 0; i < faces.size(); ++i) {
52 let face = faces.get(i); 60 let face = faces.get(i);
53 let point1 = new cv.Point(face.x, face.y); 61 let point1 = new cv.Point(face.x, face.y);
54 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);
55 cv.rectangle(dst, point1, point2, [255, 0, 0, 255]); 63 cv.rectangle(dst, point1, point2, [255, 0, 0, 255]);
56 - // margin 44 64 + let margin_x = face.width / 5;
57 - let rect = new cv.Rect(Math.max(face.x - 22, 0), Math.max(face.y - 22, 0), face.width + 22, face.height + 22); 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);
58 let cropped = src.roi(rect); 67 let cropped = src.roi(rect);
59 cv.imshow(tempCanvas,cropped); 68 cv.imshow(tempCanvas,cropped);
60 } 69 }
61 - let preview = document.getElementById('preview');
62 - cv.imshow(preview, dst);
63 if (faces.size() == 1) 70 if (faces.size() == 1)
64 { 71 {
65 let sender = document.getElementById("sender"); 72 let sender = document.getElementById("sender");
66 sender.disabled = false; 73 sender.disabled = false;
67 } 74 }
68 - else if (faces.size() == 0) 75 + if (dst.cols > $(window).width())
69 - {
70 - alert('얼굴이 인식되지 않았습니다.');
71 - }
72 - else
73 { 76 {
74 - alert('하나의 얼굴만 등록해주세요.') 77 + let ratio = $(window).width() / parseFloat(dst.cols);
78 + let dsize = new cv.Size(dst.cols * ratio, dst.rows * ratio);
79 + cv.resize(dst, dst, dsize, 0, 0, cv.INTER_AREA);
75 } 80 }
81 + let preview = document.getElementById('preview');
82 + cv.imshow(preview, dst);
76 } 83 }
77 84
78 function submit() 85 function submit()
......