Code Monkey home page Code Monkey logo

ocr-cnh-2-json's Introduction

ocr-cnh-2-json

OCR for Brazilian CNH (driver's license) to JSON object. It will try to read all the driver's license data, and allows you to compare/match by the similarity of a selfie against the document photo.

Getting started

The simplest way to get started with this project in 2 steps:

Build the docker container

docker build -t ocr-cnh .

It may take a while as the Dockerfile compiles and install several OS native libraries to run the service.

Run the container

After the building, just run an instance of the container by executing:

docker run -it -d -p 8080:8080 ocr-cnh

You can check if the container is running accordingly by executing the docker ps. Don't forget take a look at the logs (docker logs {container_name_or_id})

Ready to go!

At this point you're ready to go. Just access http://localhost:8080 and you should see a nice and friendly form to test it :)

Using the service

As said, this is a very simple service, with a even simpler use dynamic:

  • You send (upload within a POST multipart/form-data request) the document (CNH) image;
  • The service will return you a JSON with the document information (or not - it depends on the quality of the document and image)

Usage example (in JavaScript)

The following code snippet examplifies how to use the API:

import fetch from 'fetch';

let formData = new FormData();
let fileField = document.querySelector('input[type="file"]');
let file = fileField.files[0]

if (!file) alert('ERROR: Select a file.')

formData.append('file', file);

try {
    const rawResponse = await fetch('/cnh.json', { method: 'POST', body: formData });
    const response = rawResponse.json();
    console.log(response);
} catch (error) {
    console.error(error);
}

This request will return a JSON with the following format:

{
	"nome": "XXXXXXXXXXXXXXX",
	"cpf": "XXXXXXXX",
	"dt_nasc": "XXXXXXXX",
	"rg": "XXXXXXXX",
	"rg_emissor": "XXXXXXXX",
	"rg_uf": "XXXXXXXX",
	"numero": "XXXXXXXX",
	"cidade": "XXXXXXXX",
	"uf": "XXXXXXXX",
	"pai": "XXXXXXXX",
	"mae": "XXXXXXXX",
	"emissao": "XXXXXXXX",
	"validade": "XXXXXXXX",
	"avatar": "XXXXXXXX"
}

Contributors

Contributors.

ocr-cnh-2-json's People

Contributors

gabfr avatar stackchain avatar

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.