“face-api-test-html” by Theresa
https://openprocessing.org/sketch/2080635
License CreativeCommons Attribution NonCommercial ShareAlike
https://creativecommons.org/licenses/by-nc-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Forks of this sketch will no longer be attributed to this sketch.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
CC Attribution NonCommercial ShareAlike
face-api-test-html
xxxxxxxxxx
//https://www.youtube.com/watch?v=3yqANLRWGLo
let faceapi;
let detections = [];
let video;
let canvas;
function setup() {
canvas = createCanvas(480, 360);
canvas.id("canvas");
video = createCapture(VIDEO);// Creat the video: ビデオオブジェクトを作る
video.id("video");
video.size(width, height);
const faceOptions = {
withLandmarks: true,
withExpressions: true,
withDescriptors: true,
minConfidence: 0.5
};
//Initialize the model: モデルの初期化
faceapi = ml5.faceApi(video, faceOptions, faceReady);
}
function faceReady() {
faceapi.detect(gotFaces);// Start detecting faces: 顔認識開始
}
// Got faces: 顔を検知
function gotFaces(error, result) {
if (error) {
console.log(error);
return;
}
detections = result; //Now all the data in this detections: 全ての検知されたデータがこのdetectionの中に
// console.log(detections);
clear();//Draw transparent background;: 透明の背景を描く
drawBoxs(detections);//Draw detection box: 顔の周りの四角の描画
drawLandmarks(detections);//// Draw all the face points: 全ての顔のポイントの描画
drawExpressions(detections, 20, 250, 14);//Draw face expression: 表情の描画
faceapi.detect(gotFaces);// Call the function again at here: 認識実行の関数をここでまた呼び出す
}
function drawBoxs(detections){
if (detections.length > 0) {//If at least 1 face is detected: もし1つ以上の顔が検知されていたら
for (f=0; f < detections.length; f++){
let {_x, _y, _width, _height} = detections[f].alignedRect._box;
stroke(44, 169, 225);
strokeWeight(1);
noFill();
rect(_x, _y, _width, _height);
}
}
}
function drawLandmarks(detections){
if (detections.length > 0) {//If at least 1 face is detected: もし1つ以上の顔が検知されていたら
for (f=0; f < detections.length; f++){
let points = detections[f].landmarks.positions;
for (let i = 0; i < points.length; i++) {
stroke(44, 169, 225);
strokeWeight(3);
point(points[i]._x, points[i]._y);
}
}
}
}
function drawExpressions(detections, x, y, textYSpace){
if(detections.length > 0){//If at least 1 face is detected: もし1つ以上の顔が検知されていたら
let {neutral, happy, angry, sad, disgusted, surprised, fearful} = detections[0].expressions;
textFont('Helvetica Neue');•
textSize(14);
noStroke();
fill(44, 169, 225);
text("neutral: " + nf(neutral*100, 2, 2)+"%", x, y);
text("happiness: " + nf(happy*100, 2, 2)+"%", x, y+textYSpace);
text("anger: " + nf(angry*100, 2, 2)+"%", x, y+textYSpace*2);
text("sad: "+ nf(sad*100, 2, 2)+"%", x, y+textYSpace*3);
text("disgusted: " + nf(disgusted*100, 2, 2)+"%", x, y+textYSpace*4);
text("surprised: " + nf(surprised*100, 2, 2)+"%", x, y+textYSpace*5);
text("fear: " + nf(fearful*100, 2, 2)+"%", x, y+textYSpace*6);
}else{//If no faces is detected: 顔が1つも検知されていなかったら
text("neutral: ", x, y);
text("happiness: ", x, y + textYSpace);
text("anger: ", x, y + textYSpace*2);
text("sad: ", x, y + textYSpace*3);
text("disgusted: ", x, y + textYSpace*4);
text("surprised: ", x, y + textYSpace*5);
text("fear: ", x, y + textYSpace*6);
}
}
See More Shortcuts
Please verify your email to comment
Verify Email