Skip to content

Commit

Permalink
Wait for stream before running recognizeForVideo
Browse files Browse the repository at this point in the history
  • Loading branch information
mmounirf committed Mar 28, 2024
1 parent d0c8bb8 commit 443b14d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function App() {
}`}
>
<Webcam
videoConstraints={{ width: 400, height: 300, facingMode: "user" }}
width={400}
height={300}
ref={(webCamRef) => {
Expand Down
20 changes: 11 additions & 9 deletions src/lib/Recognizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,19 @@ export default class Recognizer {
private async init(): Promise<void> {
this.recognizer = await GestureRecognizer.createFromOptions(this.vision, this.options);

const updateResults = async () => {
if (this.recognizer) {
this.results = await this.recognizer.recognizeForVideo(this.videoElement, Date.now());
if (this.resultsCallback) {
this.resultsCallback(this.results);
if (this.videoElement.duration) {
const updateResults = async () => {
if (this.recognizer) {
this.results = await this.recognizer.recognizeForVideo(this.videoElement, Date.now());
if (this.resultsCallback) {
this.resultsCallback(this.results);
}
}
}
requestAnimationFrame(updateResults);
};
requestAnimationFrame(updateResults);
};

updateResults();
updateResults();
}
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ main {
video {
position: relative;
border-radius: 40px;
width: 400px;
height: 300px;
}
}

Expand Down

0 comments on commit 443b14d

Please sign in to comment.