import React, { Component } from 'react';
import * as faceapi from 'face-api.js'
class camera extends Component{
constructor(props) {
super(props);
this.videoTag = React.createRef()
this.state={
video:null
}
this.detect=this.detect.bind(this);
}
componentDidMount() {
// getting access to webcam
navigator.mediaDevices
.getUserMedia({video: true})
.then(stream =>
this.videoTag.current.srcObject = stream,
this.detect()
)
.catch(console.log);
}
detect=async ()=>{
const videoTag=document.getElementById('videoTag');
console.log("geeting")
const canvas=document.getElementById('myCanvas');
await faceapi.nets.ssdMobilenetv1.loadFromUri('/models')
faceapi.nets.ssdMobilenetv1.loadFromUri('./models')
const displaySize = { width: videoTag.width, height: videoTag.height }
faceapi.matchDimensions(canvas, displaySize)
setInterval(async () => {
const detections = await faceapi.detectAllFaces(videoTag)
console.log(detections.length);
const resizedDetections = faceapi.resizeResults(detections, displaySize)
canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height)
faceapi.draw.drawDetections(canvas, resizedDetections)
}, 200)
}
render() {
return(
<div>
<video id="videoTag"
ref={this.videoTag}
width={500}
height={500}
autoPlay
></video>
<canvas id="myCanvas"
height={500}
width={500}></canvas>
</div>
);
}
}
export default camera;
while loading ssd mobilenet model in react this error is geeting
Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
please check wheather i've had mistaken or missing something
Check you have copied the models correctly. It happened to me. Maybe you copied the json incorrectly.
Also check the network tab an make sure the uris your models are fetched from are correct.
Most helpful comment
Check you have copied the models correctly. It happened to me. Maybe you copied the json incorrectly.