Giter VIP home page Giter VIP logo

facesdk-web-js-client's Introduction

Regula FaceSDK js client for the browser and node.js based on axios

npm version npm type definitions documentation OpenAPI

Face recognition as easy as reading two bytes.

  • Face Matching - Compare the person holding the ID to the person pictured in the ID document (1:1)
  • Face Recognition - Find the person by his or her photo in databases / lists (1:N)
  • Liveness Detection - Perform liveness check using a selfie taken with the user’s smartphone.

If you have any problems with or questions about this client, please contact us through a GitHub issue. You are invited to contribute new features, fixes, or updates, large or small; We are always thrilled to receive pull requests, and do our best to process them as fast as we can. See dev guide.

Install package

npm install @regulaforensics/facesdk-webclient

Example of Face Matching

Performing request:

const face1 = fs.readFileSync('face1.jpg').buffer;
const face2 = fs.readFileSync('face2.jpg').buffer;

const sdk = new FaceSdk({ basePath: 'http://localhost:41101' });

const response = await sdk.matchingApi.match({
    images: [
        { type: ImageSource.LIVE, data: face1, index: 1 },
        { type: ImageSource.DOCUMENT_RFID, data: face2, index: 2 }
    ]
  });

Parsing results:

for (const result of response.results) {
    console.log(`pair(${result.firstIndex},${result.secondIndex})   similarity: ${result.similarity}`)
}

You can find more detailed guide and run this sample in example folder.

Compatibility

Language level

  • ES5, ES6.Promises - depends on a native ES6 Promise implementation to be supported. If your environment doesn't support ES6 Promises, you can polyfill.

Module system

  • CommonJS
  • ES6 module system

Definitions

  • TypeScript's definitions should be automatically resolved via package.json. (Reference)

facesdk-web-js-client's People

Contributors

actions-user avatar alexsatsukevich avatar alshund avatar andreipaulau avatar dangost avatar dependabot[bot] avatar dzmitrysmaliakou avatar gubinalexander avatar hleb-albau avatar ikliashchou avatar inspector-code avatar ivan-gil avatar kirylkovaliov avatar sergeyilchenko avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

facesdk-web-js-client's Issues

cjs FaceSdk cannot read property 'encode' of undefined

Expected behavior

  • Retrieve matching results from Regula Face API

Current behavior

  • Got a runtime error from Regula face SDK

NB

  • I get this error only when using cjs, but with esm it works just fine!

Code sample

const { FaceSdk } = require("@regulaforensics/facesdk-webclient");

async function match() {
  try {
    const sdk = new FaceSdk({ basePath: process.env.REGULA_FACE_API_BASE_URL });

    const face1 = fs.readFileSync("face1.jpg").buffer;
    const face2 = fs.readFileSync("face2.jpg").buffer;

    const response = await sdk.matchingApi.match({
      images: [{ data: face1 }, { data: face2 }]
    });
  
    console.log(response);
  } catch (error) {
    console.log(error);
  }
}

Stack trace

TypeError: Cannot read property 'encode' of undefined
    at MatchingApi.match (/home/node/app/node_modules/@regulaforensics/facesdk-webclient/dist/cjs-es5/ext/matching-api.js:33:59)

Trying to figure out the issue

It works with this change!!

filename: node_modules/@regulaforensics/facesdk-webclient/dist/cjs-es5/ext/matching-api.js
line: 33

- image.data = base64_arraybuffer_1.default.encode(image.data);
+ image.data = base64_arraybuffer_1.encode(image.data);

Liveness detection

There doesn't seem to be any example to perform a liveness check using an uploaded image. I also looked through the code and couldn't find any reference either.

Breaking in compile time

I'm using @regulaforensics/facesdk-webclient module in the nestJS application.
Recently I faced a compile-time issue in my dependency.

Version used - "@regulaforensics/facesdk-webclient": "^5.1.1",

Command - npm run build
Expected - It should be successfully executed
Actual - node_modules/@regulaforensics/facesdk-webclient/src/ext/person-api.ts:14:13 - error TS2532: Object is possibly 'undefined'.

14 if (imageFields.image.content && typeof imageFields.image.content !== "string") {
~~~~~~~~~~~~~~~~~
node_modules/@regulaforensics/facesdk-webclient/src/ext/person-api.ts:14:49 - error TS2532: Object is possibly 'undefined'.

14 if (imageFields.image.content && typeof imageFields.image.content !== "string") {
~~~~~~~~~~~~~~~~~
node_modules/@regulaforensics/facesdk-webclient/src/ext/person-api.ts:15:13 - error TS2532: Object is possibly 'undefined'.

15 imageFields.image.content = converter.encode(imageFields.image.content)
~~~~~~~~~~~~~~~~~
node_modules/@regulaforensics/facesdk-webclient/src/ext/person-api.ts:15:58 - error TS2532: Object is possibly 'undefined'.

15 imageFields.image.content = converter.encode(imageFields.image.content)
~~~~~~~~~~~~~~~~~
node_modules/@regulaforensics/facesdk-webclient/src/ext/search-api.ts:9:13 - error TS2532: Object is possibly 'undefined'.

9 if (searchRequest.image.content && typeof searchRequest.image.content !== "string") {
~~~~~~~~~~~~~~~~~~~
node_modules/@regulaforensics/facesdk-webclient/src/ext/search-api.ts:9:51 - error TS2532: Object is possibly 'undefined'.

9 if (searchRequest.image.content && typeof searchRequest.image.content !== "string") {
~~~~~~~~~~~~~~~~~~~
node_modules/@regulaforensics/facesdk-webclient/src/ext/search-api.ts:10:13 - error TS2532: Object is possibly 'undefined'.

10 searchRequest.image.content = converter.encode(searchRequest.image.content)
~~~~~~~~~~~~~~~~~~~
node_modules/@regulaforensics/facesdk-webclient/src/ext/search-api.ts:10:60 - error TS2532: Object is possibly 'undefined'.

10 searchRequest.image.content = converter.encode(searchRequest.image.content)
~~~~~~~~~~~~~~~~~~~

Found 8 error(s).

Screenshot 2023-06-14 at 6 32 58 PM

When I skip NullChecks in my tsconfig.json it works. But it should not be needed for this library.

Getting Error while running this code

(node:2325) UnhandledPromiseRejectionWarning: Error: Request failed with status code 404
at createError (/mnt/d/OCR/Regula/FaceSDK-web-js-client-master/node_modules/axios/lib/core/createError.js:16:15)
at settle (/mnt/d/OCR/Regula/FaceSDK-web-js-client-master/node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (/mnt/d/OCR/Regula/FaceSDK-web-js-client-master/node_modules/axios/lib/adapters/http.js:260:11)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1327:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
(Use node --trace-warnings ... to show where the warning was created)
(node:2325) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:2325) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.