EX#1 let video; function setup() { createCanvas(640, 480); //畫面長寬比 video = createCapture(VIDEO); //載入鏡頭 video.hide(); //隱藏第2畫面 } function draw() { image(video,0,0);//設定顯示畫面 } ===================================================================== EX#2 let video; let poseNet; function setup() { createCanvas(640, 480); //畫面長寬比 video = createCapture(VIDEO); //載入鏡頭 video.hide(); //隱藏第2畫面 poseNet = ml5.poseNet(video, modelLoaded);//引入posenet poseNet.on('pose',getPoses);//載入posenet姿勢辨識 } function getPoses(poses){ console.log(poses);//輸出辨識之姿勢資料 } function modelLoaded() { console.log('poseNet ready');//確認posenet引入 } function draw() { image(video,0,0);//設定顯示畫面 } ====================================================================== EX#3 let video; let poseNet; let pose; let skeleton; function setup() { createCanvas(640, 480); //畫面長寬比 video = createCapture(VIDEO); //載入鏡頭 video.hide(); //隱藏第2畫面 poseNet = ml5.poseNet(video, modelLoaded);//引入posenet poseNet.on('pose',getPoses);//載入posenet姿勢辨識 } function getPoses(poses){ //console.log(poses);//輸出辨識之姿勢資料 if (poses.length > 0){ pose = poses[0].pose;//確認有1個pose以上的話將主要辨識的pose設定出來 skeleton =poses[0].skeleton;//確認有1個pose以上的話將pose骨架設定出來 } } function modelLoaded() { console.log('poseNet ready');//確認posenet引入 } function draw() { image(video,0,0);//設定顯示畫面 if(pose){ for(let i=0;i 0){ pose = poses[0].pose;//確認有1個pose以上的話將主要辨識的pose設定出來 skeleton =poses[0].skeleton;//確認有1個pose以上的話將pose骨架設定出來 if(state=='collecting'){//確認判斷點為蒐集狀態 let inputs=[];//設定資料儲存陣列 for(let i=0;i 0){ pose = poses[0].pose;//確認有1個pose以上的話將主要辨識的pose設定出來 skeleton =poses[0].skeleton;//確認有1個pose以上的話將pose骨架設定出來 } } function modelLoaded() { console.log('poseNet ready');//確認posenet引入 } function draw() { translate(video.width,0);//將畫面向右移到視窗外 scale(-1,1);//將畫面朝x軸往回擴1倍 image(video,0,0,video.width,video.height);//設定顯示畫面配合攝影機全域 if(pose){ for(let i=0;i 0){ pose = poses[0].pose;//確認有1個pose以上的話將主要辨識的pose設定出來 skeleton =poses[0].skeleton;//確認有1個pose以上的話將pose骨架設定出來 } } function modelLoaded() { console.log('poseNet ready');//確認posenet引入 } function draw() { push();//區隔畫面設定 translate(video.width,0);//將畫面向右移到視窗外 scale(-1,1);//將畫面朝x軸往回擴1倍 image(video,0,0,video.width,video.height);//設定顯示畫面配合攝影機全域 if(pose){ for(let i=0;i 0){ pose = poses[0].pose;//確認有1個pose以上的話將主要辨識的pose設定出來 skeleton =poses[0].skeleton;//確認有1個pose以上的話將pose骨架設定出來 } } function modelLoaded() { console.log('poseNet ready');//確認posenet引入 } function draw() { push();//區隔畫面設定 translate(video.width,0);//將畫面向右移到視窗外 scale(-1,1);//將畫面朝x軸往回擴1倍 image(video,0,0,video.width,video.height);//設定顯示畫面配合攝影機全域 if(pose){ image(img,pose.nose.x-30, pose.nose.y+10,img.width / 8, img.height / 8);//顯示圖片在鼻子中央 for(let i=0;i{ if(isNaN(time)){ reject(new Error('delay requires valid numer.')); }else{ setTimeout(resolve,time); } }) } async function keyPressed(){ // if(key=='s'){ // brain.saveData(); // }else{ // targetLabel = key; // console.log(targetLabel); // setTimeout(function(){ // console.log('collecting'); // state = 'collecting'; // setTimeout(function(){ // console.log('not collecting'); // state = 'waiting'; // },10000); // },10000); // } if(key=='Enter'){ await delay(3000); console.log('start the motion'); state='waiting'; modelReady(); } } function setup() { createCanvas(640, 480); video = createCapture(VIDEO); video.hide(); poseNet = ml5.poseNet(video, modelLoaded); poseNet.on('pose',getPoses); let options ={ input: 34, outputs: 3, task: 'classification', debug: true } brain=ml5.neuralNetwork(options); const modelInfo = { model: 'model/model.json', metadata: 'model/model_meta.json', weights: 'model/model.weights.bin', }; brain.load(modelInfo, modelReady); //brain.loadData('hand.json',dataReady); } async function modelReady(){ if(state=='waiting'){ flot=getRandom(3);//設定亂數 if(flot==0){ poseLabel='put down';//設定畫面顯示確認姿勢 await delay(5000);//等待5秒開始辨識 check='d';//設定姿勢註解確認 state='classify';//設定判斷點區分辨識與非辨識狀態 classifyPose(); }else if(flot==1){ poseLabel='right hand'; await delay(5000); check='r'; state='classify'; classifyPose(); }else if(flot==2){ poseLabel='left hand'; await delay(5000); check='l'; state='classify'; classifyPose(); } } } async function classifyPose(){ if(pose){ let inputs=[]; for(let i=0;i 0){ pose = poses[0].pose; skeleton =poses[0].skeleton; // if(state=='collecting'){ // let inputs=[]; // for(let i=0;i