Commit 59bc9f94 authored by Matthias Wenzl's avatar Matthias Wenzl
Browse files

initial commit

parents
*~
*.bak
*.bin
*.elf
*.o
This repository contains your start files when implementing the finger print reader.
You must alter the uc-firmware - and port the fp.py program to c/c++.
Don't forget the integration of the fvs suite in your verification chain.
\ No newline at end of file
#
# (C) Samuel Wambera for DIScoVER, 2016
# Read an image from the fingerprint reader and store it as bitmap
#
import spidev
from PIL import Image
from time import *
from copy import deepcopy
def fp_read():
spi = spidev.SpiDev(0,0)
spi.max_speed_hz = 2000000
im = Image.new('L', (320,240))
print "time: " + str(localtime()[3:6])
spi.open(0,0)
count = 0
while(1):
var = raw_input("get fp? [Y/n]: ")
if var == "n":
break
while (1):
if spi.readbytes(1)[0] == 4:
break
print "starting"
spi.writebytes([0x01])
print "waiting for finish"
start_cond = spi.readbytes(1)
while (start_cond[0] != 255):
start_cond = spi.readbytes(1)
print "time: " + str(localtime()[3:6])
pixels = im.load()
print "start-byte received, getting image now"
for y in range(0, 240):
px = spi.readbytes(320)
for x in range(0, 320):
pixels[x, 239-y] = px[x]
if spi.readbytes(1)[0] != 255:
spi.close()
return "communication-error"
print "got image, saving"
im.save("original"+str(count)+".bmp", "BMP", quality=100)
count += 1
print "time: " + str(localtime()[3:6])
spi.close()
if __name__ == "__main__":
fp_read()
CC=gcc
CFLAGS=-O2 -I include
LFLAGS= -lm
GDBFLAGS=-O0 -g -I include
FVSCFILES=export.c floatfield.c image.c imageenhance.c imagemanip.c img_base.c import.c matching.c minutia.c
FVSHFILES=include/export.h include/floatfield.h include/fvs.h include/fvstypes.h include/image.h include/imagemanip.h include/img_base.h include/import.h include/matching.h include/minutia.h
all: fvs_main
fvs_main: fvs_main.c $(FVSCFILES) $(FVSHFILES)
$(CC) $(CFLAGS) fvs_main.c $(FVSCFILES) -o bin/fvs_main $(LFLAGS) -O `pkg-config --cflags --libs MagickCore`
gdb: fvs_main.c $(FVSCFILES) $(FVSHFILES)
$(CC) $(GDBFLAGS) fvs_main.c $(FVSCFILES) -o bin/fvs_gdb $(LFLAGS) -O `pkg-config --cflags --libs MagickCore`
clean:
rm -f bin/fvs_main
/*########################################################################
The contents of this file are subject to the Mozilla Public License
Version 1.0(the "License"); You may NOT use this file except in
compliance with the License. You may obtain a copy of the License at
http:// www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
the License for the specific language governing rights and limitations
under the License.
The Initial Developer of the Original Code is Shivang Patel.
Copyright(C) 2002. All Rights Reserved.
Authors: Shivang Patel
Jaap de Haan(jdh)
Matthias Wenzl (mw)
Changes: jdh -> Added support for ImageMagick that enables
to export files to more than 40 formats.
mw -> Removed deprecated.
########################################################################*/
#include "import.h"
#include <stdio.h>
#include <string.h>
#include <magick/api.h>
/* imports a fingeprint image from a file */
FvsError_t FvsImageExport(const FvsImage_t image, const FvsString_t filename)
{
ExceptionInfo exception;
Image* magicimage;
ImageInfo* magicinfo;
FvsError_t ret = FvsOK;
FvsByte_t* buffer;
FvsInt_t pitch;
FvsInt_t height;
FvsInt_t width;
FvsInt_t i;
/* get buffer, size and pitch from the input image */
buffer = ImageGetBuffer(image);
pitch = ImageGetPitch(image);
height = ImageGetHeight(image);
width = ImageGetWidth(image);
/* Init Magick environment */
MagickCoreGenesis(".",MagickFalse);
//InitializeMagick(".");
GetExceptionInfo(&exception);
/* Create an empty imageinfo */
magicinfo = CloneImageInfo((ImageInfo*)NULL);
magicinfo->depth = 8;
/* create image */
magicimage = ConstituteImage(width, height, "I", CharPixel, buffer, &exception);
if (exception.severity!=UndefinedException)
CatchException(&exception);
if (magicimage!=(Image*)NULL)
{
/* copy the data */
for (i=0; i<height; i++)
{
ImportImagePixels(magicimage, 0, i, width, 1, "I", CharPixel,
buffer+i*pitch);
}
/* save the image to file */
(void)strcpy(magicimage->filename, filename);
magicimage->colorspace = GRAYColorspace;
magicimage->depth = 8;
WriteImage(magicinfo, magicimage);
/* dump info for debugging purposes */
/* DescribeImage(magicimage, stdout, 0); */
DestroyImage(magicimage);
}
else
ret = FvsFailure;
/* do cleanup */
DestroyImageInfo(magicinfo);
DestroyExceptionInfo(&exception);
MagickCoreTerminus();
return ret;
}
#if 0
/* The WAND interface is pretty buggy... use the old API */
/* exports a fingeprint image to a file */
FvsError_t FvsImageExport(const FvsImage_t image, const FvsString_t filename)
{
MagickWand* wand;
FvsByte_t* buffer;
FvsByte_t* out;
FvsInt_t pitch;
FvsInt_t height;
FvsInt_t width;
FvsError_t ret = FvsOK;
FvsInt_t i;
/* Init Magick */
wand = NewMagickWand();
if (wand!=NULL)
{
/* extract parameters */
buffer = ImageGetBuffer(image);
width = ImageGetWidth(image);
height = ImageGetHeight(image);
pitch = ImageGetPitch(image);
/* allocate a new buffer for the pixel data */
out = (FvsByte_t*)malloc(width*height);
if (out!=NULL)
{
for (i=0; i<height; i++)
memcpy(out+i*width, buffer+i*pitch, width);
/* out now contains the picture data in a contiguous buffer */
MagickSetSize(wand, width, height);
MagickSetImagePixels(wand, 0, 0, width, height, "I", CharPixel, out);
/* write data */
MagickWriteImage(wand, filename);
free(out);
}
else
ret = FvsMemory;
/* do cleanup */
DestroyMagickWand(wand);
}
else
ret = FvsMemory;
return ret;
}
#endif
/*########################################################################
*
* Copyright(C) 2002-2007. All Rights Reserved.
*
* Authors: Shivang Patel
* Jaap de Haan(jdh)
*
* Changes: jdh -> Added support for ImageMagick that enables
* to export files to more than 40 formats.
* This is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2, or (at your option) any later
* version.
*
* This is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License with
* the fvs source package as the
* file COPYING. If not, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
########################################################################*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "floatfield.h"
/*!
A fingerprint floating point field structure.
*/
typedef struct iFvsFloatField_t
{
FvsFloat_t *pimg; /* floating point field array */
FvsInt_t w; /* width of field */
FvsInt_t h; /* height of field */
FvsInt_t pitch; /* pitch */
} iFvsFloatField_t;
FvsFloatField_t FloatFieldCreate()
{
iFvsFloatField_t* p = NULL;
p = (FvsFloatField_t)malloc(sizeof(iFvsFloatField_t));
if (p!=NULL)
{
p->h = 0;
p->w = 0;
p->pitch = 0;
p->pimg = NULL;
}
return (FvsFloatField_t)p;
}
void FloatFieldDestroy(FvsFloatField_t field)
{
iFvsFloatField_t* p = NULL;
if (field==NULL)
return;
p = field;
(void)FloatFieldSetSize(field, 0, 0);
free(p);
}
FvsError_t FloatFieldSetSize(FvsFloatField_t img, const FvsInt_t width, const FvsInt_t height)
{
iFvsFloatField_t* field = (iFvsFloatField_t*)img;
FvsError_t nRet = FvsOK;
FvsInt_t newsize = (FvsInt_t)(width*height*sizeof(FvsFloat_t));
/* special case for zero size */
if (newsize==0)
{
if (field->pimg!=NULL)
{
free(field->pimg);
field->pimg = NULL;
field->w = 0;
field->h = 0;
field->pitch = 0;
}
return FvsOK;
}
if ((FvsInt_t)(field->h*field->w*sizeof(FvsFloat_t)) != newsize)
{
free(field->pimg);
field->w = 0;
field->h = 0;
field->pitch = 0;
/* This allocates the amount of memory need for the field structure */
field->pimg = (FvsFloat_t*)malloc((size_t)newsize);
}
if (field->pimg == NULL)
nRet = FvsMemory;
else
{
field->h = height;
field->w = width;
field->pitch = width;
}
return nRet;
}
FvsError_t FloatFieldCopy(FvsFloatField_t destination, const FvsFloatField_t source)
{
iFvsFloatField_t* dest = (iFvsFloatField_t*)destination;
iFvsFloatField_t* src = (iFvsFloatField_t*)source;
FvsError_t nRet = FvsOK;
nRet = FloatFieldSetSize(dest, src->w, src->h);
if (nRet==FvsOK)
memcpy(dest->pimg, src->pimg, src->h*src->w*sizeof(FvsFloat_t));
return nRet;
}
FvsError_t FloatFieldClear(FvsFloatField_t img)
{
return FloatFieldFlood(img, 0.0);
}
FvsError_t FloatFieldFlood(FvsFloatField_t img, const FvsFloat_t value)
{
iFvsFloatField_t* field = (iFvsFloatField_t*)img;
FvsError_t nRet = FvsOK;
FvsInt_t i;
if (field->pimg!=NULL)
{
for (i=0; i<field->h*field->w; i++)
field->pimg[i] = value;
}
return nRet;
}
/* set a pixel value in the picture */
void FloatFieldSetValue(FvsFloatField_t img, const FvsInt_t x, const FvsInt_t y, const FvsFloat_t val)
{
iFvsFloatField_t* field = (iFvsFloatField_t*)img;
int address = y * field->w + x;
field->pimg[address] = val;
}
/* This function returns the pixel for the x and y value */
FvsFloat_t FloatFieldGetValue(FvsFloatField_t img, const FvsInt_t x, const FvsInt_t y)
{
iFvsFloatField_t* field = (iFvsFloatField_t*)img;
/* position in array */
int address = y * field->pitch + x;
return field->pimg[address];
}
/* returns a pointer to the field buffer */
FvsFloat_t* FloatFieldGetBuffer(FvsFloatField_t img)
{
iFvsFloatField_t* field = (iFvsFloatField_t*)img;
return field->pimg;
}
/* retrieve width and height */
FvsInt_t FloatFieldGetWidth(const FvsFloatField_t img)
{
iFvsFloatField_t* field = (iFvsFloatField_t*)img;
return field->w;
}
FvsInt_t FloatFieldGetHeight(const FvsFloatField_t img)
{
iFvsFloatField_t* field = (iFvsFloatField_t*)img;
return field->h;
}
/* get the pitch pixel(x,y) pos is at x + y * pitch */
FvsInt_t FloatFieldGetPitch(const FvsFloatField_t img)
{
iFvsFloatField_t* field = (iFvsFloatField_t*)img;
return field->pitch;
}
/*########################################################################
*
* Copyright(C) 2002-2012. All Rights Reserved.
*
* Authors: Shivang Patel
* Jaap de Haan(jdh)
* Peter Tummeltshammer(petertu)
* Matthias Wenzl (mw)
*
* Changes: jdh -> Added support for ImageMagick that enables
* to export files to more than 40 formats.
* Changes: petertu -> Modified import.c and export.c
* -> added function ImageEnhanceThinned()
* Changes: mw -> Changed deprecated and adapted for dvp lu
*
* This is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2, or (at your option) any later
* version.
*
* This is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License with
* the fvs source package as the
* file COPYING. If not, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
########################################################################*/
#include "fvs.h"
int main(int argc, char *argv[])
{
FvsImage_t image1;
FvsImage_t image2;
FvsImage_t mask;
FvsImage_t temp1;
FvsImage_t temp2;
FvsFloatField_t direction;
FvsMinutiaSet_t minutia_original;
FvsMinutiaSet_t minutia;
FvsFloat_t pgoodness;
FvsFloatField_t frequency;
/* check if all parameters are there */
if (argc!=3)
{
printf("Usage:\n %s input_image original_image\n", argv[0]);
return -1;
}
mask = ImageCreate();
image1 = ImageCreate();
image2 = ImageCreate();
temp1 = ImageCreate();
temp2 = ImageCreate();
direction = FloatFieldCreate();
frequency = FloatFieldCreate();
minutia = MinutiaSetCreate(100);
minutia_original = MinutiaSetCreate(100);
if (mask!=NULL && image1!=NULL && image2!=NULL && temp1!=NULL && temp2!=NULL && direction!=NULL && minutia!=NULL && frequency!=NULL)
{
fprintf(stdout, "Importing image\n");
(void) FvsImageImport(image1, argv[1]);
ImageCopy(temp1, image1);
fprintf(stdout, "Softening mean\n");
(void)ImageSoftenMean(image1, 3);
fprintf(stdout, "Normalizing image\n");
(void)ImagePixelNormalize(image1, 9);
//creates a fixed-size mask, which is needed to ignore the
//mostly unusable border areas in an image
fprintf(stdout, "Creating the mask\n");
(void)FingerprintGetFixedMask(image1, mask, 6);
fprintf(stdout, "Determining the ridge direction\n");
(void)FingerprintGetDirection(image1, direction, 5, 4);
//apply mask to image
(void)ImageLogical(image1,mask,FvsLogicalAnd);
fprintf(stdout, "Determining the ridge frequency\n");
(void)FingerprintGetFrequency(image1, direction, frequency);
fprintf(stdout, "Enhancing the fingerprint image\n");
(void)ImageEnhanceGabor(image1, direction, frequency, mask, 4.0);
// (void)FvsImageExport(image1, "gabor.bmp");
//Binarize the image
fprintf(stdout, "Binarizing\n");
(void)ImageBinarize(image1, (FvsByte_t)0x80);
//Thinning: Fist the standard fvs algorithm (ImageThinHitMiss) is used, then the
//ImageEnhanceThinned algorithm written by petertu is applied
fprintf(stdout, "Thinning\n");
(void)ImageThinHitMiss(image1);
(void)ImageEnhanceThinned(image1,direction);
(void)FvsImageExport(image1, "thin1.bmp");
//Detecting the minutia in the fingerprint and writing them to minutia list
fprintf(stdout, "Detecting minutia\n");
(void)MinutiaSetExtract(minutia, image1, direction, mask);
//This function draws the minutias as small vectors.
//the contents of "image" are erased first
// fprintf(stdout, "Drawing minutia\n");
// (void)ImageClear(image);
//(void)ImageFlood(image, 255);
// (void)MinutiaSetDraw(minutia, temp1);
// (void)FvsImageExport(temp, "minutias.bmp");
fprintf(stdout, "Importing original image\n");
(void) FvsImageImport(image2, argv[2]);
ImageCopy(temp2, image2);
fprintf(stdout, "Softening mean\n");
(void)ImageSoftenMean(image2, 3);
// (void)FvsImageExport(image, "1_softened.bmp");
fprintf(stdout, "Normalizing image\n");
(void)ImagePixelNormalize(image2, 9);
// (void)FvsImageExport(image, "2_normalized.bmp");
//creates a fixed-size mask, which is needed to ignore the
//mostly unusable border areas in an image
fprintf(stdout, "Creating the mask\n");
(void)FingerprintGetFixedMask(image2, mask, 6);
// (void)FvsImageExport(image, "3_mask.bmp");
fprintf(stdout, "Determining the ridge direction\n");