Skip to content

Commit

Permalink
Update demos
Browse files Browse the repository at this point in the history
1. disable eye detection
2. set capture size by screen size
  • Loading branch information
huningxin committed Aug 11, 2017
1 parent 62e26a5 commit ab18474
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 14 deletions.
2 changes: 1 addition & 1 deletion samples/face-detection-wasm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div id="container">
<canvas class="center-block" id="canvasOutput" width=320 height=240></canvas>
</div>
<div class="text-center">
<div class="invisible">
<input type="checkbox" id="face" name="classifier" value="face" checked>
<label for="face">face</label>
<input type="checkbox" id="eye" name="cascade" value="eye">
Expand Down
11 changes: 9 additions & 2 deletions samples/face-detection-wasm/js/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
let videoWidth, videoHeight;

let qvga = {width: {exact: 320}, height: {exact: 240}};

let vga = {width: {exact: 640}, height: {exact: 480}};

let resolution = window.innerWidth < 640 ? qvga : vga;

// whether streaming video from the camera.
let streaming = false;

Expand All @@ -13,7 +19,7 @@ let detectEye = document.getElementById('eye');

function startCamera() {
if (streaming) return;
navigator.mediaDevices.getUserMedia({video: true, audio: false})
navigator.mediaDevices.getUserMedia({video: resolution, audio: false})
.then(function(s) {
stream = s;
video.srcObject = s;
Expand Down Expand Up @@ -93,7 +99,8 @@ function processVideo() {
size = faceMat.size();
} else {
cv.pyrDown(grayMat, faceMat);
cv.pyrDown(faceMat, faceMat);
if (videoWidth > 320)
cv.pyrDown(faceMat, faceMat);
size = faceMat.size();
}
faceClassifier.detectMultiScale(faceMat, faceVect);
Expand Down
2 changes: 1 addition & 1 deletion samples/face-detection/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div id="container">
<canvas class="center-block" id="canvasOutput" width=320 height=240></canvas>
</div>
<div class="text-center">
<div class="invisible">
<input type="checkbox" id="face" name="classifier" value="face" checked>
<label for="face">face</label>
<input type="checkbox" id="eye" name="cascade" value="eye">
Expand Down
11 changes: 9 additions & 2 deletions samples/face-detection/js/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
let videoWidth, videoHeight;

let qvga = {width: {exact: 320}, height: {exact: 240}};

let vga = {width: {exact: 640}, height: {exact: 480}};

let resolution = window.innerWidth < 640 ? qvga : vga;

// whether streaming video from the camera.
let streaming = false;

Expand All @@ -13,7 +19,7 @@ let detectEye = document.getElementById('eye');

function startCamera() {
if (streaming) return;
navigator.mediaDevices.getUserMedia({video: true, audio: false})
navigator.mediaDevices.getUserMedia({video: resolution, audio: false})
.then(function(s) {
stream = s;
video.srcObject = s;
Expand Down Expand Up @@ -93,7 +99,8 @@ function processVideo() {
size = faceMat.size();
} else {
cv.pyrDown(grayMat, faceMat);
cv.pyrDown(faceMat, faceMat);
if (videoWidth > 320)
cv.pyrDown(faceMat, faceMat);
size = faceMat.size();
}
faceClassifier.detectMultiScale(faceMat, faceVect);
Expand Down
14 changes: 10 additions & 4 deletions samples/video-processing-wasm/js/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// In this case, We set width 320, and the height will be computed based on the input stream.
let width = 320;
let width = 0;
let height = 0;

let qvga = {width: {exact: 320}, height: {exact: 240}};

let vga = {width: {exact: 640}, height: {exact: 480}};

let resolution = window.innerWidth < 640 ? qvga : vga;

// whether streaming video from the camera.
let streaming = false;

Expand All @@ -11,7 +16,7 @@ let vc = null;

function startCamera() {
if (streaming) return;
navigator.mediaDevices.getUserMedia({video: true, audio: false})
navigator.mediaDevices.getUserMedia({video: resolution, audio: false})
.then(function(s) {
stream = s;
video.srcObject = s;
Expand All @@ -23,7 +28,8 @@ function startCamera() {

video.addEventListener("canplay", function(ev){
if (!streaming) {
height = video.videoHeight / (video.videoWidth/width);
height = video.videoHeight;
width = video.videoWidth;
video.setAttribute("width", width);
video.setAttribute("height", height);
streaming = true;
Expand Down
14 changes: 10 additions & 4 deletions samples/video-processing/js/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// In this case, We set width 320, and the height will be computed based on the input stream.
let width = 320;
let width = 0;
let height = 0;

let qvga = {width: {exact: 320}, height: {exact: 240}};

let vga = {width: {exact: 640}, height: {exact: 480}};

let resolution = window.innerWidth < 640 ? qvga : vga;

// whether streaming video from the camera.
let streaming = false;

Expand All @@ -11,7 +16,7 @@ let vc = null;

function startCamera() {
if (streaming) return;
navigator.mediaDevices.getUserMedia({video: true, audio: false})
navigator.mediaDevices.getUserMedia({video: resolution, audio: false})
.then(function(s) {
stream = s;
video.srcObject = s;
Expand All @@ -23,7 +28,8 @@ function startCamera() {

video.addEventListener("canplay", function(ev){
if (!streaming) {
height = video.videoHeight / (video.videoWidth/width);
height = video.videoHeight;
width = video.videoWidth;
video.setAttribute("width", width);
video.setAttribute("height", height);
streaming = true;
Expand Down

0 comments on commit ab18474

Please sign in to comment.