Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read properties of undefined (reading 'ccall') #5804

Closed
akau16 opened this issue Jan 5, 2025 · 6 comments
Closed
Assignees
Labels
platform:javascript MediaPipe Javascript issues task:gesture recognition Issues related to hand gesture recognition: Identify and recognize hand gestures type:support General questions

Comments

@akau16
Copy link

akau16 commented Jan 5, 2025

I had a web Project that use Emscripten to build c++ Code and use "Module.ccall.." to call my c++ function, now I want to add MediaPipe's Gesture recognition to my Project using JavaScript, but I have to called "GestureRecognizer.createFromOptions.." 2~3 times, the process will go ahead is the first problem, and the second is after process can go ahead, but when I call "Module.ccall..", it will show message "Uncaught TypeError: Cannot read properties of undefined (reading 'ccall')", some one can help? Thanks!, the code is bellow:

import { FilesetResolver, GestureRecognizer } from "https://cdn.jsdelivr.net/npm/@mediapipe/[email protected]";

async function startGestureDetection() {

    const videoElement = document.getElementById('webcam');
    const canvasElement = document.getElementById('webcam_preview');
    const canvasCtx = canvasElement.getContext('2d');


    videoStream = await navigator.mediaDevices.getUserMedia({ video: true });
    videoElement.srcObject = videoStream;

    try {
        console.log("[ges] FilesetResolver: ", FilesetResolver);
        const vision = await FilesetResolver.forVisionTasks(
            "https://cdn.jsdelivr.net/npm/@mediapipe/[email protected]/wasm"
        );
        console.log("[ges] vision: ", vision);

        console.log("[ges] GestureRecognizer: ", GestureRecognizer);
        gestureRecognizer = await GestureRecognizer.createFromOptions(vision, {
            baseOptions: {
               ,
                modelAssetPath: "./models/gesture_recognizer.task",
                delegate: "GPU"
            },
            runningMode: "VIDEO"
        });
    } catch (error) {
        console.error("Error initializing hand detection:", error);
    }

    console.log("[ges][startGestureDetection] gestureRecognizer: ", gestureRecognizer);

    videoElement.addEventListener('loadeddata', async () => {
        while (isGestureDetectionActive) {

            const results = await gestureRecognizer.recognizeForVideo(videoElement, performance.now());

            canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height);
            canvasCtx.drawImage(videoElement, 0, 0, canvasElement.width, canvasElement.height);

            if (results.gestures.length > 0) {
                const categoryName = results.gestures[0][0].categoryName;
                const categoryScore = parseFloat(results.gestures[0][0].score * 100).toFixed(2);
                canvasCtx.fillStyle = 'red';
                canvasCtx.font = '20px Arial';
                canvasCtx.fillText(`${categoryName} (${categoryScore})`, 10, 30);
            }
            await new Promise(requestAnimationFrame);
        }
    });
}
@akau16 akau16 added the type:others issues not falling in bug, perfromance, support, build and install or feature label Jan 5, 2025
@kuaashish kuaashish added type:support General questions task:gesture recognition Issues related to hand gesture recognition: Identify and recognize hand gestures platform:javascript MediaPipe Javascript issues and removed type:others issues not falling in bug, perfromance, support, build and install or feature labels Jan 6, 2025
@kuaashish
Copy link
Collaborator

Hi @akau16,

We have a newer version available (0.10.20). Could you please try it and let us know if you encounter the same issue with newer version as well?

Thank you!!

@kuaashish kuaashish added the stat:awaiting response Waiting for user response label Jan 6, 2025
@akau16
Copy link
Author

akau16 commented Jan 6, 2025

Hi @kuaashish ,
I encountered the same issue with 0.10.20 version, somebody tell me It may be caused by the the same main function name in our both wasm file. Is this true?

Thank you!

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Waiting for user response label Jan 6, 2025
@kuaashish
Copy link
Collaborator

Hi @akau16,

Based on our team's input, it seems, intentionally running two WASM modules and encountering issues as a result.

We do not believe this is related to main code. Rather, it appears that the Module variable is being overwritten when MediaPipe loads. Here are two potential solutions:

Make the WASM module modular: Use the flags -s MODULARIZE=1 and -s EXPORT_NAME='SomeUniqueName' to prevent conflicts between multiple WASM modules.

Save the WASM to a separate variable: Instead of using the global Module variable (which can be overwritten), save the WASM to a different variable. For example, before running MediaPipe, they can load the WASM with const myWasm = Module; and then use myWasm throughout the rest of the code instead of Module.

Thank you!!

@kuaashish kuaashish added the stat:awaiting response Waiting for user response label Jan 10, 2025
Copy link

This issue has been marked stale because it has no recent activity since 7 days. It will be closed if no further activity occurs. Thank you.

@github-actions github-actions bot added the stale label Jan 18, 2025
Copy link

This issue was closed due to lack of activity after being marked stale for past 7 days.

Copy link

Are you satisfied with the resolution of your issue?
Yes
No

@kuaashish kuaashish removed stat:awaiting response Waiting for user response stale labels Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:javascript MediaPipe Javascript issues task:gesture recognition Issues related to hand gesture recognition: Identify and recognize hand gestures type:support General questions
Projects
None yet
Development

No branches or pull requests

2 participants