justadudewhohacks / face-api.js

JavaScript API for face detection and face recognition in the browser and nodejs with tensorflow.js
MIT License
16.73k stars 3.72k forks source link

Typescript compiler errors #546

Open MitchellMonaghan opened 4 years ago

MitchellMonaghan commented 4 years ago

Am I dumb or am I missing something? I followed the documentation for usage with node but this produces many typescript compiler errors even tho the code functions.

The following produces the errors below

const { Canvas, Image, ImageData } = canvas

faceapi.env.monkeyPatch({
  Canvas,
  Image,
  ImageData
})
Type 'typeof Canvas' is not assignable to type '{ new (): HTMLCanvasElement; prototype: HTMLCanvasElement; }'.

Types of property 'prototype' are incompatible.

Type 'Canvas' is missing the following properties from type 'HTMLCanvasElement': toBlob, transferControlToOffscreen, addEventListener, removeEventListener, and 239 more.ts(2322)
types.d.ts(6, 5): The expected type comes from property 'Canvas' which is declared here on type 'Partial<Environment>'

Also

const img = await canvas.loadImage('./temp/Thumbnail1.png')
const fullFaceDescriptions = await faceapi.detectAllFaces(img).withFaceLandmarks().withFaceDescriptors()
Argument of type 'Image' is not assignable to parameter of type 'TNetInput'.

Type 'Image' is not assignable to type 'HTMLImageElement'.ts(2345)

Why use typescript at all if I have to use // @ts-ignore everywhere to remove compiler errors? Or am I missing something? Thanks.

"typescript": "3.7.5"

justadudewhohacks commented 4 years ago

The thing is that utilizing node-canvas is more of "a hack" to make it work in nodejs, so you might have to cast to "any" here and there:

faceapi.env.monkeyPatch({
  Canvas,
  Image,
  ImageData
} as any)

faceapi.detectAllFaces(img)

By the way tfjs-node provides the necessary utility to read and write images so you do not necessarily have to use node-canvas anymore.

mdjfs commented 3 years ago

The thing is that utilizing node-canvas is more of "a hack" to make it work in nodejs, so you might have to cast to "any" here and there:

faceapi.env.monkeyPatch({
  Canvas,
  Image,
  ImageData
} as any)

faceapi.detectAllFaces(img)

By the way tfjs-node provides the necessary utility to read and write images so you do not necessarily have to use node-canvas anymore.

Hi! I'm trying to read/write images with the tjfs-node utility but I got an error when I run it:

image

The error occurs between lines 90-91:

image

Amazing library, if you have any idea of that error and you can help me I would be grateful

mdjfs commented 3 years ago

The thing is that utilizing node-canvas is more of "a hack" to make it work in nodejs, so you might have to cast to "any" here and there:

faceapi.env.monkeyPatch({
  Canvas,
  Image,
  ImageData
} as any)

faceapi.detectAllFaces(img) By the way tfjs-node provides the necessary utility to read and write images so you do not necessarily have to use node-canvas anymore.

Hi! I'm trying to read/write images with the tjfs-node utility but I got an error when I run it:

image

The error occurs between lines 90-91:

image

Amazing library, if you have any idea of that error and you can help me I would be grateful

Solved. I just update the face api version ^0.22.2