Na primeira edicao do programa Conectado da TV Serpro, discuto sobre o funcionamento do banco de dados espaciais PostGIS. Biometric technologies are increasingly used in civilian applications. One example is that in the 2014 elections, 21.6 million Brazilians (15% of the country's voters) in 762 municipalities (including 15 capitals) should use biometrics in electronic voting machines in order to reduce the risk of errors, fraud and slowness.In India a government pioneering initiative promises to create the largest biometric database in the world. In the country there are over half a billion people who lack any kind of identification, making it impossible for them to receive government aid, open bank accounts, apply for loans, get a driver's license, among others. Expecting to register the biometric data of more than one million people a day, the project hopes to have by the end of 2014 the records of all 1.2 billion Indians in its database.Thus, while scratching on the subject, I found out that the sourcecodes of biometric routines from FBI/NIST are public. Such routines are the heart of AFIS (Automatic Fingerprint & Identification System), among which two algorithms stand out: the characteristics extractor (feature extractor) and the comparator of minutiae (matcher).After studying this NIST code (in C language), I decided to create support for such features natively on my favorite DBMS, PostgreSQL. And so it was born pgAFIS (Automated Fingerprint Identification System support for PostgreSQL), an extension capable of providing feature extraction and minutiae comparison from SQL statements within PostgreSQL.But how does that work in practice?Well, let's start by data modeling. You'll need to create in the database a table in which information of fingerprints will be stored, as described below: Table "public.fingerprints" Column | Type | Modifiers --------+--------------+----------- id | character(5) | not null pgm | bytea | wsq | bytea | mdt | bytea | xyt | text | Indexes: "fingerprints_pkey" PRIMARY KEY, btree (id)"pgm" stores fingerprints raw images (PGM)"wsq" stores fingerprints images in a compressed form (WSQ)"mdt" stores fingerprints templates in XYTQ type in a binary format (MDT)"xyt" stores fingerprints minutiae data in textual formThe data type used in these columns is "bytea" (an array of bytes), similar to BLOB in other DBMSs. PGM and WSQ formats are open and well-known in the market. On the other hand, MDT is a format I created. :D Therefore, fingerprints images may be obtained in raw format and stored on "pgm" column in that table. PGM format is a kind of bitmap, where there is no compression. Fingerprint readers usually store image files using this format. Now pgAFIS comes into play! A particular function is able to convert the binary data from a PGM content into a WSQ format (a kind of JPEG created by NIST/FBI). This is done by running this SQL statement: UPDATE fingerprintsSET wsq = cwsq(pgm, 2.25, 300, 300, 8, null);The second step where pgAFIS acts is the extraction of the fingerprints local characteristics (the minutiae) from the WSQ content. The result is the information in XYTQ type (i.e., horizontal and vertical coordinates, slope angle and quality) of each minutia.