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

CanvasRenderingContext2D is not defined in DrawingUtils constructor #5284

Open
ddgg-el opened this issue Apr 1, 2024 · 2 comments · May be fixed by #5489
Open

CanvasRenderingContext2D is not defined in DrawingUtils constructor #5284

ddgg-el opened this issue Apr 1, 2024 · 2 comments · May be fixed by #5489
Assignees
Labels
os:macOS Issues on MacOS platform:javascript MediaPipe Javascript issues stat:awaiting googler Waiting for Google Engineer's Response task:pose landmarker Issues related to Pose Landmarker: Find people and body positions type:support General questions

Comments

@ddgg-el
Copy link

ddgg-el commented Apr 1, 2024

Have I written custom code (as opposed to using a stock example script provided in MediaPipe)

Yes

OS Platform and Distribution

macOS 12.6

MediaPipe Tasks SDK version

npm package version 0.10.12

Task name (e.g. Image classification, Gesture recognition etc.)

Pose Landmarker

Programming Language and version (e.g. C++, Python, Java)

Typescript

Describe the actual behavior

Instanciating a DrawingUtils with an OffscreenCanvasRenderingContext2D as cpuContext in Worker returns an Uncaught ReferenceError: CanvasRenderingContext2D is not defined

Describe the expected behaviour

a DrawingUtils is properly Instantiated

Standalone code/steps you may have used to try to get what you need

//index.ts
const canvasCamera = document.getElementById("output_canvas") as HTMLCanvasElement
const offscreenVideoCanvas:OffscreenCanvas = canvasCamera.transferControlToOffscreen()
poseWorker.postMessage({canvas: offscreenVideoCanvas}, [offscreenVideoCanvas])


// pose pose_worker.ts
self.onmessage = (e) => {
    if ("canvas" in e.data ) {
        canvasCamera = e.data.canvas as OffscreenCanvas
	canvasCtxVideo = canvasCamera.getContext("2d") as OffscreenCanvasRenderingContext2D
	painter = new DrawingUtils(canvasCtxVideo)
    }
}

Other info / Complete Logs

Uncaught ReferenceError: CanvasRenderingContext2D is not defined
    at new Ra (vision_bundle.mjs:1:58732)
    at self.onmessage (pose_worker.ts:29:13)
@kuaashish kuaashish added os:macOS Issues on MacOS platform:javascript MediaPipe Javascript issues type:support General questions task:pose landmarker Issues related to Pose Landmarker: Find people and body positions labels Apr 3, 2024
@kuaashish kuaashish added the stat:awaiting googler Waiting for Google Engineer's Response label Apr 8, 2024
@JDBar
Copy link

JDBar commented May 23, 2024

I've got a goofy workaround, which is to define CanvasRenderingContext2D in the web worker scope.

declare let self: WorkerGlobalScope &
	typeof globalThis & {
		CanvasRenderingContext2D: typeof OffscreenCanvasRenderingContext2D;
	};
self.CanvasRenderingContext2D = OffscreenCanvasRenderingContext2D;

DrawingUtils seems perfectly happy with this.

bc-lee added a commit to bc-lee/mediapipe that referenced this issue Jun 19, 2024
Without this commit, the DrawingUtils constructor fails in Web Workers
because the CanvasRenderingContext2D is not available in the worker
context.
This commit adds a check whether the CanvasRenderingContext2D is
defined before using it.

Fixes google-ai-edge#5284
@bc-lee bc-lee linked a pull request Jun 19, 2024 that will close this issue
@kuaashish
Copy link
Collaborator

Hi @ddgg-el,

Could you please confirm if this is still an issue? A newer version of MediaPipe is available—could you check and let us know if it resolves the problem? If the issue is resolved, please inform us.

Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os:macOS Issues on MacOS platform:javascript MediaPipe Javascript issues stat:awaiting googler Waiting for Google Engineer's Response task:pose landmarker Issues related to Pose Landmarker: Find people and body positions type:support General questions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants