Toggle navigation
Toggle navigation
This project
Loading...
Sign in
공태현
/
healthcare-with-webcam
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
정지호
2022-06-07 16:26:12 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
95a6187e64d3f5f7f609b103b181bb59045d96a8
95a6187e
1 parent
1ee39185
Seperate css/html/js
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
95 deletions
views/squatPage/style.css → views/squatPage/squat.css
views/squatPage/squat.html
views/squatPage/squat.js
views/squatPage/s
tyle
.css
→
views/squatPage/s
quat
.css
View file @
95a6187
File moved
views/squatPage/squat.html
View file @
95a6187
...
...
@@ -4,108 +4,19 @@
<meta
charset=
"UTF-8"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<link
rel=
"stylesheet"
href=
"s
tyle
.css"
>
<link
rel=
"stylesheet"
href=
"s
quat
.css"
>
<title>
Squat Page
</title>
</head>
<body
bgcolor=
"#353535"
>
<div
class=
"Title"
>
Squat Page
</div>
<center><button
class=
"w-btn w-btn-indigo"
type=
"button"
onclick=
"init()"
>
START
</button></center>
<center><button
class=
"w-btn w-btn-indigo"
type=
"button"
onclick=
"init()"
>
WEBCAM
START
</button></center>
<div><canvas
id=
"canvas"
></canvas></div>
<div
id=
"label-container"
></div>
<center>
<iframe
width=
"560"
height=
"315"
src=
"https://www.youtube.com/embed/9WhpAVOSyl8?start=22"
title=
"YouTube video player"
frameborder=
"0"
allow=
"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>
</center>
<script
src=
"https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.3.1/dist/tf.min.js"
></script>
<script
src=
"https://cdn.jsdelivr.net/npm/@teachablemachine/pose@0.8/dist/teachablemachine-pose.min.js"
></script>
<script
type=
"text/javascript"
>
// More API functions here:
// https://github.com/googlecreativelab/teachablemachine-community/tree/master/libraries/pose
// the link to your model provided by Teachable Machine export panel
const
URL
=
"https://teachablemachine.withgoogle.com/models/xymjZj4q-/"
;
// 임시 URI - stand , squart, bent(허리 굽은 자세) 학습.
let
model
,
webcam
,
ctx
,
labelContainer
,
maxPredictions
;
async
function
init
()
{
const
modelURL
=
URL
+
"model.json"
;
const
metadataURL
=
URL
+
"metadata.json"
;
// load the model and metadata
// Refer to tmImage.loadFromFiles() in the API to support files from a file picker
// Note: the pose library adds a tmPose object to your window (window.tmPose)
model
=
await
tmPose
.
load
(
modelURL
,
metadataURL
);
maxPredictions
=
model
.
getTotalClasses
();
// Convenience function to setup a webcam
const
size
=
500
;
const
flip
=
true
;
// whether to flip the webcam
webcam
=
new
tmPose
.
Webcam
(
size
,
size
,
flip
);
// width, height, flip
await
webcam
.
setup
();
// request access to the webcam
await
webcam
.
play
();
window
.
requestAnimationFrame
(
loop
);
// append/get elements to the DOM
const
canvas
=
document
.
getElementById
(
"canvas"
);
canvas
.
width
=
size
;
canvas
.
height
=
size
;
ctx
=
canvas
.
getContext
(
"2d"
);
labelContainer
=
document
.
getElementById
(
"label-container"
);
for
(
let
i
=
0
;
i
<
maxPredictions
;
i
++
)
{
// and class labels
labelContainer
.
appendChild
(
document
.
createElement
(
"div"
));
}
}
async
function
loop
(
timestamp
)
{
webcam
.
update
();
// update the webcam frame
await
predict
();
window
.
requestAnimationFrame
(
loop
);
}
// 상태 : 서있는 상태로 초기화
let
status
=
"stand"
;
// 갯수 count
let
count
=
0
;
async
function
predict
()
{
// Prediction #1: run input through posenet
// estimatePose can take in an image, video or canvas html element
const
{
pose
,
posenetOutput
}
=
await
model
.
estimatePose
(
webcam
.
canvas
);
// Prediction 2: run input through teachable machine classification model
const
prediction
=
await
model
.
predict
(
posenetOutput
);
if
(
prediction
[
0
].
probability
.
toFixed
(
2
)
>
0.9
)
{
// 서있는 상태
if
(
status
==
"squat"
){
// 전에 스쿼트 상태였다면, 일어날 때 카운트를 하나 올려줘야 함.
count
++
;
var
audio
=
new
Audio
(
count
%
10
+
'.wav'
);
audio
.
play
();
console
.
log
(
count
);
}
status
=
"stand"
}
else
if
(
prediction
[
1
].
probability
.
toFixed
(
2
)
==
1.00
)
{
// 스쿼트 자세
status
=
"squat"
}
else
if
(
prediction
[
2
].
probability
.
toFixed
(
2
)
==
1.00
)
{
// 굽은 자세(잘못된 케이스)
if
(
status
==
"squart"
||
status
==
"stand"
)
{
// 굽은 자세로 잘못 수행하면, 소리 나도록
var
audio
=
new
Audio
(
'bad.mp3'
);
audio
.
play
();
}
status
=
"bent"
}
for
(
let
i
=
0
;
i
<
maxPredictions
;
i
++
)
{
const
classPrediction
=
prediction
[
i
].
className
+
": "
+
prediction
[
i
].
probability
.
toFixed
(
2
);
labelContainer
.
childNodes
[
i
].
innerHTML
=
classPrediction
;
}
// finally draw the poses
drawPose
(
pose
);
}
function
drawPose
(
pose
)
{
if
(
webcam
.
canvas
)
{
ctx
.
drawImage
(
webcam
.
canvas
,
0
,
0
);
// draw the keypoints and skeleton
if
(
pose
)
{
const
minPartConfidence
=
0.5
;
tmPose
.
drawKeypoints
(
pose
.
keypoints
,
minPartConfidence
,
ctx
);
tmPose
.
drawSkeleton
(
pose
.
keypoints
,
minPartConfidence
,
ctx
);
}
}
}
</script>
<!-- 유튜브 영상 띄우기 -->
<iframe
width=
"560"
height=
"315"
src=
"https://www.youtube.com/embed/9WhpAVOSyl8?start=22"
title=
"YouTube video player"
frameborder=
"0"
allow=
"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>
<script
src=
"./squat.js"
></script>
</body>
</html>
...
...
views/squatPage/squat.js
0 → 100644
View file @
95a6187
// More API functions here:
// https://github.com/googlecreativelab/teachablemachine-community/tree/master/libraries/pose
// the link to your model provided by Teachable Machine export panel
const
URL
=
"https://teachablemachine.withgoogle.com/models/xymjZj4q-/"
;
// 임시 URI - stand , squart, bent(허리 굽은 자세) 학습.
let
model
,
webcam
,
ctx
,
labelContainer
,
maxPredictions
;
async
function
init
()
{
const
modelURL
=
URL
+
"model.json"
;
const
metadataURL
=
URL
+
"metadata.json"
;
// load the model and metadata
// Refer to tmImage.loadFromFiles() in the API to support files from a file picker
// Note: the pose library adds a tmPose object to your window (window.tmPose)
model
=
await
tmPose
.
load
(
modelURL
,
metadataURL
);
maxPredictions
=
model
.
getTotalClasses
();
// Convenience function to setup a webcam
const
size
=
300
;
const
flip
=
true
;
// whether to flip the webcam
webcam
=
new
tmPose
.
Webcam
(
size
,
size
,
flip
);
// width, height, flip
await
webcam
.
setup
();
// request access to the webcam
await
webcam
.
play
();
webcam
.
style
window
.
requestAnimationFrame
(
loop
);
// append/get elements to the DOM
const
canvas
=
document
.
getElementById
(
"canvas"
);
canvas
.
width
=
size
;
canvas
.
height
=
size
;
ctx
=
canvas
.
getContext
(
"2d"
);
labelContainer
=
document
.
getElementById
(
"label-container"
);
for
(
let
i
=
0
;
i
<
maxPredictions
;
i
++
)
{
// and class labels
labelContainer
.
appendChild
(
document
.
createElement
(
"div"
));
}
}
async
function
loop
(
timestamp
)
{
webcam
.
update
();
// update the webcam frame
await
predict
();
window
.
requestAnimationFrame
(
loop
);
}
// 상태 : 서있는 상태로 초기화
let
status
=
"stand"
;
// 갯수 count
let
count
=
0
;
async
function
predict
()
{
// Prediction #1: run input through posenet
// estimatePose can take in an image, video or canvas html element
const
{
pose
,
posenetOutput
}
=
await
model
.
estimatePose
(
webcam
.
canvas
);
// Prediction 2: run input through teachable machine classification model
const
prediction
=
await
model
.
predict
(
posenetOutput
);
if
(
prediction
[
0
].
probability
.
toFixed
(
2
)
>
0.9
)
{
// 서있는 상태
if
(
status
==
"squat"
){
// 전에 스쿼트 상태였다면, 일어날 때 카운트를 하나 올려줘야 함.
count
++
;
var
audio
=
new
Audio
(
count
%
10
+
'.wav'
);
audio
.
play
();
console
.
log
(
count
);
}
status
=
"stand"
}
else
if
(
prediction
[
1
].
probability
.
toFixed
(
2
)
==
1.00
)
{
// 스쿼트 자세
status
=
"squat"
}
else
if
(
prediction
[
2
].
probability
.
toFixed
(
2
)
==
1.00
)
{
// 굽은 자세(잘못된 케이스)
if
(
status
==
"squart"
||
status
==
"stand"
)
{
// 굽은 자세로 잘못 수행하면, 소리 나도록
var
audio
=
new
Audio
(
'bad.mp3'
);
audio
.
play
();
}
status
=
"bent"
}
for
(
let
i
=
0
;
i
<
maxPredictions
;
i
++
)
{
const
classPrediction
=
prediction
[
i
].
className
+
": "
+
prediction
[
i
].
probability
.
toFixed
(
2
);
labelContainer
.
childNodes
[
i
].
innerHTML
=
classPrediction
;
}
// finally draw the poses
drawPose
(
pose
);
}
function
drawPose
(
pose
)
{
if
(
webcam
.
canvas
)
{
ctx
.
drawImage
(
webcam
.
canvas
,
0
,
0
);
// draw the keypoints and skeleton
if
(
pose
)
{
const
minPartConfidence
=
0.5
;
tmPose
.
drawKeypoints
(
pose
.
keypoints
,
minPartConfidence
,
ctx
);
tmPose
.
drawSkeleton
(
pose
.
keypoints
,
minPartConfidence
,
ctx
);
}
}
}
\ No newline at end of file
Please
register
or
login
to post a comment