You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using WebView to use this library, but
it does not recognize a phone camera as a webcam,
and log says "Could not open your camera. You may have denied access."
while this app has a permission to the camera.
Is there a way that I can use teachable machine on Android?
This is a code I used on Android :
<div>Teachable Machine Pose Model</div><buttontype='button'onclick='init()'>Start</button><div><canvasid='canvas'></canvas></div>
<divid='label-container'></div><scriptsrc="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script><scriptsrc="https://cdn.jsdelivr.net/npm/@teachablemachine/[email protected]/dist/teachablemachine-pose.min.js"></script><scripttype="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 = '{{URL}}';
let model, webcam, ctx, labelContainer, maxPredictions;
async function init() {constmodelURL=URL+'model.json';constmetadataURL=URL+'metadata.json';// load the model and metadata// Refer to tmPose.loadFromFiles() in the API to support files from a file pickermodel=awaittmPose.load(modelURL,metadataURL);maxPredictions=model.getTotalClasses();// Convenience function to setup a webcamconstflip=true;// whether to flip the webcamwebcam=newtmPose.Webcam(200,200,flip);// width, height, flipawaitwebcam.setup();// request access to the webcamwebcam.play();window.requestAnimationFrame(loop);// append/get elements to the DOMconstcanvas=document.getElementById('canvas');canvas.width=200;canvas.height=200;ctx=canvas.getContext('2d');labelContainer=document.getElementById('label-container');for(leti=0;i<maxPredictions;i++){// and class labelslabelContainer.appendChild(document.createElement('div'));}}asyncfunctionloop(timestamp){webcam.update();// update the webcam frameawaitpredict();window.requestAnimationFrame(loop);}
async function predict() {// Prediction #1: run input through posenet// estimatePose can take in an image, video or canvas html elementconst{pose,posenetOutput} = await model.estimatePose(webcam.canvas);
// Prediction 2: run input through teachable machine classification model
const prediction = await model.predict(posenetOutput);
for (let i = 0; i <maxPredictions;i++){constclassPrediction=prediction[i].className+': '+prediction[i].probability.toFixed(2);labelContainer.childNodes[i].innerHTML=classPrediction;}// finally draw the posesdrawPose(pose);}functiondrawPose(pose){ctx.drawImage(webcam.canvas,0,0);// draw the keypoints and skeletonif(pose){constminPartConfidence=0.5;tmPose.drawKeypoints(pose.keypoints,minPartConfidence,ctx);tmPose.drawSkeleton(pose.keypoints,minPartConfidence,ctx);}}
</script>
The text was updated successfully, but these errors were encountered:
I am using WebView to use this library, but
it does not recognize a phone camera as a webcam,
and log says "Could not open your camera. You may have denied access."
while this app has a permission to the camera.
Is there a way that I can use teachable machine on Android?
This is a code I used on Android :
The text was updated successfully, but these errors were encountered: