Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김영곤
/
2020-02-OSS-TermProject
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Authored by
이재호
2020-12-07 03:06:50 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
722b884e0a304c381d0da2f39ee19efc24301009
722b884e
1 parent
2ca87581
modify model and webcam function
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
27 deletions
views/index.ejs
views/index.ejs
View file @
722b884
...
...
@@ -164,40 +164,43 @@
<script
src=
"https://cdn.jsdelivr.net/npm/@teachablemachine/image@0.8/dist/teachablemachine-image.min.js"
></script>
<script
src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"
></script>
<script
type=
"text/javascript"
>
// More API functions here:
// https://github.com/googlecreativelab/teachablemachine-community/tree/master/libraries/image
// More API functions here:
// https://github.com/googlecreativelab/teachablemachine-community/tree/master/libraries/image
// the link to your model provided by Teachable Machine export panel
const
URL
=
"https://teachablemachine.withgoogle.com/models/ujJHV9bKh/"
;
// the link to your model provided by Teachable Machine export panel
const
URL
=
"https://teachablemachine.withgoogle.com/models/ujJHV9bKh/"
;
let
model
,
webcam
,
labelContainer
,
maxPredictions
;
let
model
,
webcam
,
labelContainer
,
maxPredictions
;
//predic이전 값을 기억해주는 전역변수. -999로 초기화.
var
last_result_predict
=-
999
;
// Load the image model and setup the webcam
async
function
init
()
{
const
modelURL
=
URL
+
"model.json"
;
const
metadataURL
=
URL
+
"metadata.json"
;
// Load the image model and setup the webcam
window
.
onload
=
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
// or files from your local hard drive
// Note: the pose library adds "tmImage" object to your window (window.tmImage)
model
=
await
tmImage
.
load
(
modelURL
,
metadataURL
);
maxPredictions
=
model
.
getTotalClasses
();
// load the model and metadata
// Refer to tmImage.loadFromFiles() in the API to support files from a file picker
// or files from your local hard drive
// Note: the pose library adds "tmImage" object to your window (window.tmImage)
model
=
await
tmImage
.
load
(
modelURL
,
metadataURL
);
maxPredictions
=
model
.
getTotalClasses
();
// Convenience function to setup a webcam
const
flip
=
true
;
// whether to flip the webcam
webcam
=
new
tmImage
.
Webcam
(
200
,
20
0
,
flip
);
// width, height, flip
await
webcam
.
setup
();
// request access to the webcam
await
webcam
.
play
();
window
.
requestAnimationFrame
(
loop
);
// Convenience function to setup a webcam
const
flip
=
true
;
// whether to flip the webcam
webcam
=
new
tmImage
.
Webcam
(
550
,
55
0
,
flip
);
// width, height, flip
await
webcam
.
setup
();
// request access to the webcam
await
webcam
.
play
();
window
.
requestAnimationFrame
(
loop
);
// append elements to the DOM
document
.
getElementById
(
"webcam-container"
).
appendChild
(
webcam
.
canvas
);
labelContainer
=
document
.
getElementById
(
"label-container"
);
for
(
let
i
=
0
;
i
<
maxPredictions
;
i
++
)
{
// and class labels
labelContainer
.
appendChild
(
document
.
createElement
(
"div"
));
}
// append elements to the DOM
document
.
getElementById
(
"webcam-container"
).
appendChild
(
webcam
.
canvas
);
labelContainer
=
document
.
getElementById
(
"label-container"
);
for
(
let
i
=
0
;
i
<
maxPredictions
;
i
++
)
{
// and class labels
labelContainer
.
appendChild
(
document
.
createElement
(
"div"
));
}
}
async
function
loop
()
{
webcam
.
update
();
// update the webcam frame
...
...
Please
register
or
login
to post a comment