Comments (5)
Hello @JunzhuoZhang
The code excerpt you have provided seems OK, however, it is only preliminary analysis considering the excerpt only contains few lines of code. What can be the issue is that requestAnimationFrame()
is not included in the code. So, when the app might be started, the very first frame might not have a hand and it gives blank array.
Subsequent frames may have a hand once you lift it up, but, the subsequent frames were not being requested to be processed by the detector if requestAnimationFrame()
is not being called at the end of detection after canvasContext.restore()
is called.
For a demo purpose, please check out this minimal code
from mediapipe.
Hi, this is my predictWebCam code, I still get empty array:
predictWebcam enter {"landmarks":[],"worldLandmarks":[],"handednesses":[],"handedness":[]}"
async predictWebcam() { // Now let's start detecting the stream. let nowInMs = performance.now(); const video: HTMLVideoElement = document.getElementById('myCamera') as HTMLVideoElement; // this.lastVideoTime = this.mediaView.currentTime; VCLogger.info(
predictWebcam sec ${this.mediaView}`, this.tag);
if (video.currentTime > 0 && video.currentTime !== this.lastVideoTime) {
this.lastVideoTime = video.currentTime;
this.results = this.handLandmarker.detectForVideo(video, nowInMs);
}
VCLogger.info(`predictWebcam enter ${JSON.stringify(this.results)}`, this.tag);
this.canvasCtx.save();
this.canvasCtx.clearRect(0, 0, 1920, 1080);
this.canvasElement.style.width = video.videoWidth.toString();
this.canvasElement.style.height = video.videoHeight.toString();
this.canvasElement.width = video.videoWidth;
this.canvasElement.height = video.videoHeight;
const drawingUtils = new DrawingUtils(this.canvasCtx);
if (this.results.landmarks) {
for (const landmarks of this.results.landmarks) {
drawingUtils.drawConnectors(landmarks, HandLandmarker.HAND_CONNECTIONS, {
color: '#00FF00',
lineWidth: 5
});
drawingUtils.drawLandmarks(landmarks, { color: '#FF0000', lineWidth: 2 });
}
}
this.canvasCtx.restore();
// Call this function again to keep predicting when the browser is ready.
window.requestAnimationFrame(this.predictWebcam);
}
`
from mediapipe.
Okay so there were few changes that needed to be done in the code provided:
- Since the example app provided didn't use any framework, use of
this
was not required. Hence removedthis
keyword. This is only for the example app. Appears you are using a framework so no issues. if (video.currentTime > 0 && video.currentTime !== this.lastVideoTime) {
This condition prohibits theresults
variable to be populated on the first time. Change it to compare onlyif (video.currentTime !== this.lastVideoTime) {
drawConnectors
anddrawLandmarks
functions take CanvasCtx as the first argument, not the landmarks.HAND_CONNECTIONS
is not available in HandLandmarker. It comes from@mediapipe/hands
Modified function for your code:
async function predictWebcam() { // Now let's start detecting the stream.
let nowInMs = performance.now();
const video: HTMLVideoElement = document.getElementById('webcam') as HTMLVideoElement;
// this.lastVideoTime = this.mediaView.currentTime; VCLogger.info(predictWebcam sec ${this.mediaView}`, this.tag);
if (video.currentTime !== lastVideoTime) {
lastVideoTime = video.currentTime;
results = handLandmarker.detectForVideo(video, nowInMs);
}
VCLogger.info(`predictWebcam enter ${JSON.stringify(this.results)}`, tag);
canvasCtx.save();
canvasCtx.clearRect(0, 0, 1920, 1080);
canvasElement.style.width = video.videoWidth.toString();
canvasElement.style.height = video.videoHeight.toString();
canvasElement.width = video.videoWidth;
canvasElement.height = video.videoHeight;
// const drawingUtils = new DrawingUtils(canvasCtx);
if (results.landmarks) {
for (const landmarks of results.landmarks) {
drawConnectors(canvasCtx, landmarks,HAND_CONNECTIONS, {
color: '#00FF00',
lineWidth: 5
});
drawLandmarks(canvasCtx, landmarks, { color: '#FF0000', lineWidth: 2 });
}
}
canvasCtx.restore();
// Call function again to keep predicting when the browser is ready.
window.requestAnimationFrame(predictWebcam);
}
from mediapipe.
Related Issues (20)
- ValidatedGraphConfig Initialization Failed HOT 13
- Example of using Web Worker for FaceLandmarker HOT 1
- Providing loading progress for the Web version API for Wasm and Model card HOT 3
- PoseLandmarker and GestureRecognizer can take 30+ seconds to load in the first time. HOT 2
- Why can't use holistic landmarker in C++ ? HOT 1
- Failed access to mp.tasks.vision.holistic HOT 3
- Input rotated video to Face Landmarks model HOT 6
- Unable to set mp_pose in my Apple Silicon Mac HOT 4
- Mediapipe and autopy version on python 3.8 HOT 2
- MediaPipe Holistic Landmarker in Python null_ptr exception HOT 9
- face_mesh model triggers infrared mode on webcam HOT 3
- Expose device index to user for AudioRecorder class HOT 1
- Compile issue HOT 5
- Attribute Error in vision.ObjectDetector HOT 6
- The multi-class selfie segmenter does not run in GPU delegate mode on the Android Chrome browser. HOT 1
- The multi-class selfie segmenter does not run in GPU delegate mode on the Android Chrome browser. HOT 2
- Pose landmarker detect_for_video runs extremly slow
- MediaPipe WebApp using WASM HOT 2
- Issue with WebAssembly LinkError after updating @mediapipe/tasks-vision package to 0.10.10 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mediapipe.