From af5609aa88b46f0393f6815f0c6d96d9b90afbac Mon Sep 17 00:00:00 2001 From: Yeok-c Date: Fri, 7 May 2021 20:19:38 +0800 Subject: [PATCH 1/6] 1 --- js/pose.js | 2 +- pose.html | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/js/pose.js b/js/pose.js index baaeb5b..9cb909d 100644 --- a/js/pose.js +++ b/js/pose.js @@ -61,7 +61,7 @@ function onResultsPose(results) { } const pose = new Pose({locateFile: (file) => { - return `https://cdn.jsdelivr.net/npm/@mediapipe/pose@0.2/${file}`; + return `https://cdn.jsdelivr.net/npm/@mediapipe/pose@0.3/${file}`; }}); pose.onResults(onResultsPose); diff --git a/pose.html b/pose.html index 89e9f44..136a35e 100644 --- a/pose.html +++ b/pose.html @@ -9,7 +9,7 @@ - + @@ -20,20 +20,20 @@ - + - + - + - +
- +
@@ -85,7 +85,7 @@
- +
From 659867ab5fd0dc22595e6d1027ae28ea7df93f38 Mon Sep 17 00:00:00 2001 From: Yeok-c Date: Fri, 7 May 2021 20:29:51 +0800 Subject: [PATCH 2/6] 2 --- js/pose.js | 2 +- pose.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/pose.js b/js/pose.js index 9cb909d..baaeb5b 100644 --- a/js/pose.js +++ b/js/pose.js @@ -61,7 +61,7 @@ function onResultsPose(results) { } const pose = new Pose({locateFile: (file) => { - return `https://cdn.jsdelivr.net/npm/@mediapipe/pose@0.3/${file}`; + return `https://cdn.jsdelivr.net/npm/@mediapipe/pose@0.2/${file}`; }}); pose.onResults(onResultsPose); diff --git a/pose.html b/pose.html index 136a35e..73e16b9 100644 --- a/pose.html +++ b/pose.html @@ -9,7 +9,7 @@ - + From 6b2ff29da6f3202a4c619f4654b6a9352298a795 Mon Sep 17 00:00:00 2001 From: Yeok-c Date: Sat, 8 May 2021 19:21:15 +0800 Subject: [PATCH 3/6] Revert "1" This reverts commit af5609aa88b46f0393f6815f0c6d96d9b90afbac. --- pose.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pose.html b/pose.html index 73e16b9..89e9f44 100644 --- a/pose.html +++ b/pose.html @@ -20,20 +20,20 @@ - +
- + - + - +
- +
@@ -85,7 +85,7 @@
- +
From 87d902bc77a519447a8d82f0a2cb72dffa76a45e Mon Sep 17 00:00:00 2001 From: Yeok-c Date: Sat, 8 May 2021 19:21:19 +0800 Subject: [PATCH 4/6] Revert "2" This reverts commit 659867ab5fd0dc22595e6d1027ae28ea7df93f38. --- js/pose.js | 2 +- pose.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/pose.js b/js/pose.js index baaeb5b..9cb909d 100644 --- a/js/pose.js +++ b/js/pose.js @@ -61,7 +61,7 @@ function onResultsPose(results) { } const pose = new Pose({locateFile: (file) => { - return `https://cdn.jsdelivr.net/npm/@mediapipe/pose@0.2/${file}`; + return `https://cdn.jsdelivr.net/npm/@mediapipe/pose@0.3/${file}`; }}); pose.onResults(onResultsPose); diff --git a/pose.html b/pose.html index 89e9f44..3ea917e 100644 --- a/pose.html +++ b/pose.html @@ -9,7 +9,7 @@ - + From 0c7a12c836ae0b8def366c906da14507622b06e1 Mon Sep 17 00:00:00 2001 From: Yeok-c Date: Tue, 11 May 2021 02:24:50 +0800 Subject: [PATCH 5/6] Added detection Version 1 --- js/pose.js | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++- pose.html | 97 +++++++++++++++-------------------- 2 files changed, 186 insertions(+), 58 deletions(-) diff --git a/js/pose.js b/js/pose.js index 9cb909d..4eca74b 100644 --- a/js/pose.js +++ b/js/pose.js @@ -15,9 +15,145 @@ function zColor(data) { return `rgba(0, ${255 * z}, ${255 * (1 - z)}, 1)`; } + +var prev_nose; +var previous_wrist_left; +var previous_wrist_right; + + function onResultsPose(results) { document.body.classList.add('loaded'); fpsControl.tick(); + + var wrist_right = results.poseLandmarks[16]; + var wrist_left = results.poseLandmarks[15]; + var nose = results.poseLandmarks[0]; + var shoulder_right = results.poseLandmarks[11]; + var shoulder_left = results.poseLandmarks[12]; + + var hip_right = results.poseLandmarks[23]; + var knee_right = results.poseLandmarks[25]; + var ankle_right = results.poseLandmarks[27]; + + var hip_left = results.poseLandmarks[24]; + var knee_left = results.poseLandmarks[26]; + var ankle_left = results.poseLandmarks[28]; + + var standing; + var moving; + var sleeping; + + //Scale all variables according to shoulder width + + //Detect if Person (if less than 50% confidence on landmarks above hips, assume no person) + textContent=document.getElementsByClassName("pose_results")[0]; + var j; + var visibility_count = 0; + for(j = 0; j < 25; j++){ + if(results.poseLandmarks[j].visibility > 0.7) visibility_count++; + } + if(visibility_count > 15) textContent.innerHTML = 'visible nodes: ' + visibility_count + ' -> Able to determine posture'; + else textContent.innerHTML = 'visible nodes: ' + visibility_count + ' -> Unable to determine posture!'; + + //STATICS ------------------------------ + + //Lie down detection + textContent=document.getElementsByClassName("pose_results")[1]; + //var scale = Math.sqrt((shoulder_right.y-shoulder_left.y)**2 + (shoulder_right.x-shoulder_left.x)**2) + var shoulder_average = (shoulder_left.y + shoulder_right.y) / 2; + var hip_average = (hip_left.y + hip_right.y) / 2; + //var difference = (hip_average - shoulder_average) / scale; + var difference = (hip_average - shoulder_average); + //textContent.innerHTML = difference; + + if(difference> 0.1){ + textContent.innerHTML = 'Not lying down, difference: ' + difference ; + standing = 1; + sleeping = 0; + } else { + textContent.innerHTML = 'Lying down, difference: ' + difference; + standing = 0; + sleeping = 1; + } + + //Sitting vs standing detection - bent knees + textContent=document.getElementsByClassName("pose_results")[2]; + var knee_average = (knee_left.y + knee_right.y) / 2; + var hip_average = (hip_left.y + hip_right.y) / 2; + difference = knee_average - hip_average; + if(difference> 0.1){ + textContent.innerHTML = 'Not sitting, difference: ' + difference; + standing = 1; + } else { + textContent.innerHTML = 'Sitting, difference: ' + difference; + standing = 0; + } + + //Sitting vs standing detection - bent knees + textContent=document.getElementsByClassName("pose_results")[3]; + var left_hand_difference = nose.y - wrist_left.y; + var right_hand_difference = nose.y - wrist_right.y; + textContent.innerHTML = 'Right hand raised: ' + right_hand_difference; + + + + textContent.innerHTML = 'No hand raised'; + if(sleeping == 0){ + if(right_hand_difference > 0){ + textContent.innerHTML = 'Right hand raised: ' + right_hand_difference; + } + if(left_hand_difference > 0){ + textContent.innerHTML = 'left hand raised: ' + left_hand_difference; + } + if(right_hand_difference > 0 && left_hand_difference > 0){ + textContent.innerHTML = 'Both hands raised'; + } + } + + //------------------------------------- + + //MOVING------------------------------- + /* + //Hand movement detection (exercise) + textContent=document.getElementsByClassName("pose_results")[3]; + var avg_hand_movement = (DISTANCE(wrist_left.x, wrist_left.y, previous_wrist_left.x, previous_wrist_left.y) + DISTANCE(wrist_right.x, wrist_right.y, previous_wrist_right.x, previous_wrist_right.y)) / 2; + + previous_wrist_right.x = wrist_right.x; + previous_wrist_left.x = wrist_left.x; + previous_wrist_right.y = wrist_right.y; + previous_wrist_left.y = wrist_left.y; + + if(standing == 1){ + if(avg_hand_movement> 0.3){ + textContent.innerHTML = 'Exercising, Hand Movement: ' + avg_hand_movement; + } + else { + textContent.innerHTML = 'Not exercising, Hand Movement: ' + avg_hand_movement; + } + } else { + textContent.innerHTML = 'Not exercising, Hand Movement: ' + avg_hand_movement; + } +*/ +/* + //Walking fast detection + textContent=document.getElementsByClassName("pose_results")[4]; + var shoulder_average_movement = DISTANCE(shoulder_average, previous_shoulder_average); + if(sleeping == 0){ + if(difference> 0.3){ + textContent.innerHTML = 'Hand Movement: ' + difference + ' -> exercising'; + } + else { + textContent.innerHTML = 'Hand Movement: ' + difference + ' -> not exercising'; + } + } else { + textContent.innerHTML = 'Hand Movement: ' + difference + ' -> not exercising'; + } + */ + + //----------------------------------- + + + //console.log(results.poseLandmarks[0]); canvasCtx5.save(); canvasCtx5.clearRect(0, 0, out5.width, out5.height); @@ -60,8 +196,14 @@ function onResultsPose(results) { canvasCtx5.restore(); } + +function DISTANCE(ax, bx, ay, by) +{ + return Math.sqrt((ax-bx)**2 + (ay-by)**2); +} + const pose = new Pose({locateFile: (file) => { - return `https://cdn.jsdelivr.net/npm/@mediapipe/pose@0.3/${file}`; + return `https://cdn.jsdelivr.net/npm/@mediapipe/pose@0.2/${file}`; }}); pose.onResults(onResultsPose); @@ -74,8 +216,9 @@ const camera = new Camera(video5, { }); camera.start(); + new ControlPanel(controlsElement5, { - selfieMode: true, + selfieMode: false, upperBodyOnly: false, smoothLandmarks: true, minDetectionConfidence: 0.5, diff --git a/pose.html b/pose.html index 3ea917e..71df169 100644 --- a/pose.html +++ b/pose.html @@ -9,81 +9,65 @@ - - - - - - -
- +
+ +
- - -
-
-

- Webcam Input -

-
- -
-
-
-
+

Mediapipe Pose Detection

+
-
+
+ +
+
+

+ Detection Results +

+
+

Initializing

+
+ +
+

Initializing

+
+ +
+

Initializing

+
+ +
+

Initializing

+
+ + +
+
+
@@ -92,6 +76,7 @@ + From 9558121d04c73ad7ea33787390f4945186d66781 Mon Sep 17 00:00:00 2001 From: Yeok-c Date: Tue, 19 Sep 2023 22:33:00 +0800 Subject: [PATCH 6/6] Updated SD branch --- js/pose.js | 2 +- pose - Copy.html | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 pose - Copy.html diff --git a/js/pose.js b/js/pose.js index 4eca74b..441ba87 100644 --- a/js/pose.js +++ b/js/pose.js @@ -153,7 +153,7 @@ function onResultsPose(results) { //----------------------------------- - //console.log(results.poseLandmarks[0]); + console.log(results.poseLandmarks[0]); canvasCtx5.save(); canvasCtx5.clearRect(0, 0, out5.width, out5.height); diff --git a/pose - Copy.html b/pose - Copy.html new file mode 100644 index 0000000..5520a3c --- /dev/null +++ b/pose - Copy.html @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + +
+
+

+ Mediapipe Pose Detection +

+
+ + +
+
+
+ +
+
+

+ Detection Results +

+
+

Initializing

+
+ +
+

Initializing

+
+ +
+

Initializing

+
+ +
+

Initializing

+
+ + +
+
+ +
+ +
+
+
+ + + + + + \ No newline at end of file