Coder Social home page Coder Social logo

dpar39 / ppp Goto Github PK

View Code? Open in Web Editor NEW
162.0 4.0 35.0 595.18 MB

A passport photo ID creation tool

License: GNU General Public License v3.0

CMake 0.99% Python 8.46% C++ 36.98% JavaScript 0.88% HTML 28.91% TypeScript 17.34% Makefile 1.60% Java 0.16% Shell 0.68% SCSS 0.78% Starlark 1.61% Ruby 0.04% C 1.53% Dockerfile 0.05%

ppp's Introduction

Photo ID Creator - A tool to prepare photo IDs

build status Buy me a coffee

This project implements a web-based application to create photographs in compliance with many ID forms and documents such as passports, visas, licenses, etc. The application takes as input a photograph of a person's face and automatically applies resizing and rotation to comply with the specified photo ID requirement. Then, the user can generate a tiled photo for a given print format such as 4x6" or 5x7" and have it printed at home or at your nearest photo center.

History of the project

I started this project several years ago with the dream of covering the gaps of existing web-based and Android/iOS apps that can produce valid photos for IDs and official applications. Being an immigrant, firstly in Australia, then in the USA, meant that I often found myself needing passport-sized photos for myself and my family members. Of course, this is a service that is offered in many places, but it is never cheap, especially for people starting from the ground up in a new country, possibly without a job, or with a large family. Traditional photo ID services also have the inconvenience of a trip to your nearest location. This is usually not a big deal, but what about parents with babies or people with disability or mobility problems?

Over the years, the tech stack I've used in this project has changed significantly, but the goal has always been the same: provide a free client-side application that people can use to prepare their own photographs. Firstly, I always wanted it to be a tool where personal data (i.e. the user's photographs) never leave their PC or phone, unless they explicitly decide to print it online or share the result electronically. Secondly, I want the workflow to be so simple that if you are capable of taking a picture of someone's face with your phone and know what type of document you need (e.g. a US Passport), the app should take care of the rest with just a couple of clicks.

Obviously, not all photos taken at home with a smartphone camera will have the quality to meet photo ID requirements, but if you are on the budget and/or have the time to ensure you capture a picture of yourself with good resolution, proper focus and illumination, then this app will do the maths to prepare an output tiled photo ready to be printed for much less than a dollar at your closest photo center.

Tech stack of the application

The application is made out out two components, a C++ library compiled to WebAssembly and a front-end application developed using Ionic with Angular backend in TypeScript.

Image processing algorithms of the application are developed in modern C++ and compiled to WebAssembly with Emscripten. The C++ code lives inside folder libppp and is built using Bazel. Originally, all C++ code was building with CMake, but since the app now uses MediaPipe, it only made sense to move the build system to Bazel given the complexities of porting MediaPipe to a CMake-based build system.

Libraries used in C++ code:

  • OpenCV (core, imgproc, imgcodecs, objdetect, etc.)
  • MediaPipe and its dependencies (TensorFlow Lite)
  • Google Test

The front-end of the application is built using

  • Ionic Framework with Angular
  • Interact.js (for gesture handling)
  • ngx-color-picker (color picker component)
  • flag-icons (icons of country flags)

Getting started with the code

You'll need a POSIX system with Docker and bash available (WSL2, Linux or Mac). See section Installing WSL2 on Windows if you need help setting it up.

Then, either you install NPM or run the following by opening the folder in VSCode using DevContainers.

# build the webassembly package
npm run wasm:all

# Start the app in development mode
cd webapp && npm install && npm start

Installing WLS2 on Windows

To setup WSL2 with docker, run the following steps in a Powershell or CMD as Administrator.

:: Check for wsl updates
wsl --update

:: Install Ubuntu 22.04
wsl --install Ubuntu-22.04

Now inside WSL install docker and exit:

echo $(whoami) ALL=\(root\) NOPASSWD:ALL | sudo tee /etc/sudoers.d/$(whoami)
printf '[boot]\nsystemd=true\n' | sudo tee /etc/wsl.conf
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce -y
sudo usermod -aG docker $USER
sudo service docker start
sudo reboot

If everything worked well, then you should be able to run in CMD or Powershell:

wsl -d Ubuntu-22.04 docker run hello-world

If you want to do Typescript/Javascript development directly on Windows, install Node.js and NPM on Windows. With Powershell this can be achieved via winget install OpenJS.NodeJS.LTS --accept-source-agreements.

Cropping to photo standard sizes

In order to crop and scale the face of the person to a particular photo ID requirement, the following approach was investigated. Given the set of detected facial landmarks A, B, C and D, we would like to estimate P and Q with accuracy that is sufficient to ensure that the face in the output photo fall within the limits of the size requirements. In other words, the estimated location of the crown (P’) and chin point (Q’) should be such that the distance P’Q’ scaled by the distance between the ideal location of the crown (P) and chin point (Q) falls within the tolerance range allowed in photo ID specifications. For instance, for the case of Australian passport, the allowed scale drift range is ±5.88% given that the face height (chin to crown) must be between 32mm and 36mm: $\dfrac{1}{2} \times \dfrac{36 - 32}{0.5 \times (32+36)} = \pm 5.88$%.

To develop and validate the proposed approach, facial landmarks from the SCFace database were used. The SCFace database contains images for 130 different subjects and frontal images of each individual were carefully annotated by the Biometric Recognition Group - ATVS at Escuela Politecnica Superior of the Universidad Autonoma de Madrid [ATVS]. The procedure to estimate P’ and Q’ from A, B, C and D is as follow: Firstly, points M and N are found as the center of segments AB and CD respectively. P’ and Q’ are expected to fall in the line that passes through M and N. Then using a normalization distance KK = |AB| + |MN| and scale constants α and β, we estimate P’Q’ = αKK and M’Q’ = βKK. From the dataset α and β were adjusted to minimize the estimation error of P' and Q'. Having estimated positions P' and Q' allows us to crop to most photo ID standards defined throughout the world.

ppp's People

Contributors

dpar39 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ppp's Issues

ISSUE IN WEB APP

ERROR in src/app/about/about.page.ts:2:44 - error TS2307: Cannot find module 'src/environments/app-build-info'.

2 import { AppBuildInfo, appBuildInfo } from 'src/environments/app-build-info';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Webapp Issues

I'm getting the following error on the webapp.


charles.henry@PRIVATE MINGW64 ~/PassPortPhotoApp/webapp (master)
$ ng serve
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2019-02-28T03:22:23.927Z
Hash: 04a2f11cada0a3b80a0f
Time: 5270ms
chunk {main} main.js, main.js.map (main) 1.98 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 709 bytes [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 5.22 kB [entry] [rendered]
chunk {scripts} scripts.js, scripts.js.map (scripts) 87 kB  [rendered]
chunk {styles} styles.js, styles.js.map (styles) 76.8 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 335 kB [initial] [rendered]

ERROR in node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ';' expected.
node_modules/rxjs/internal/types.d.ts(81,74): error TS1005: ';' expected.
node_modules/rxjs/internal/types.d.ts(81,77): error TS1109: Expression expected.

i 「wdm」: Failed to compile.

Allow reusing system libraries

Currently the build system vendors opencv, dlib, googletest. It would be nice to allow reusing system libraries for this.
The build system could use an overhaul in general.

Add a sponsor / donate button

I would love to donate / sponsor something. This saved me a lot of time. Thank you so much for making available for free.

Unable to build CLI

Hi,

I'm unable to build the CLI as described in the README. I have Python 3.10.2, CMake 3.22.2, and Visual C++ Redistributable 2015-2022 x64 installed. When attempting to build, I run into the following issue.

Despite troubleshooting, I end up in the same place every time:

Traceback (most recent call last):
  File "build.py", line 942, in <module>
    BUILDER = Builder()
  File "build.py", line 931, in __init__
    self.build_dlib()
  File "build.py", line 421, in build_dlib
    self.build_cmake_lib(dlib_extract_dir, cmake_extra_defs, ['install'], True)
  File "build.py", line 521, in build_cmake_lib
    self.run_cmd(cmake_cmd)
  File "build.py", line 219, in run_cmd
    cwd=cwd, input=input)
  File "build.py", line 143, in run_cmd
    cmd_all = [self._vcvarsbat, vs_arch[self._arch_name]] + \
AttributeError: 'ShellRunner' object has no attribute '_vcvarsbat'

Carify LICENSE

Under what license is this published / may it be distributed or reused?

Webapp no loading

Hello.
Thanks for this code, the idea is great.
I have uploaded to my webhosting, but the HTML index file won't load at all.
am new into this so i dont know if there is anything wrong am doing.

is there a documentation or help to let us know how to upload and work the HTML or how to make the android app for this?

Thanks

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.