📄 test.cpp
字号:
/*#############################################################################
* 文件名:fvs_enhancer.c
* 功能: 指纹图像增强
* modified by PRTsinghua@hotmail.com
#############################################################################*/
extern "C"
{
#include "fvs.h"
#include <stdlib.h>
}
#include <time.h>
#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
static FvsError_t OverlayDirection(FvsImage_t image, const FvsFloatField_t field)
{
FvsError_t nRet = FvsOK;
FvsInt_t w = ImageGetWidth (image);
FvsInt_t h = ImageGetHeight(image);
FvsInt_t pitch, dirp;
FvsFloat_t theta, c, s;
FvsByte_t* p;
FvsFloat_t* orientation;
FvsInt_t x, y, size, i, j, l;
size = 8;
(void)ImageLuminosity(image, 168);
pitch = ImageGetPitch (image);
p = ImageGetBuffer(image);
orientation = FloatFieldGetBuffer(field);
dirp = FloatFieldGetPitch(field);
if (p==NULL || orientation==NULL)
return FvsMemory;
for (y = size; y < h-size; y+=size-2)
for (x = size; x < w-size; x+=size-2)
{
theta = orientation[x+y*dirp];
c = cos(theta);
s = sin(theta);
for (l = 0; l < size; l++)
{
i = (FvsInt_t)(x + size/2 - l*s);
j = (FvsInt_t)(y + size/2 + l*c);
p[i+j*pitch] = 0;
}
}
return nRet;
}
int main(int argc, char *argv[])
{
FvsImage_t mask;
FvsImage_t image;
FvsImage_t directionimage;
FvsFloatField_t direction;
FvsFloatField_t frequency;
FvsFloat_t radius = 4.0;
FvsByte_t bmfh[14];
BITMAPINFOHEADER bmih;
RGBQUAD rgbq[256];
char filename[30];
clock_t start,finish;
if (argc<2 || argc>3)
{
printf("Usage: fvs input.bmp [radius]\n");
return -1;
}
if (argc==3)
radius = atof(argv[2]);
mask = ImageCreate();
image = ImageCreate();
directionimage = ImageCreate();
direction = FloatFieldCreate();
frequency = FloatFieldCreate();
if (mask!=NULL && image!=NULL && direction!=NULL && frequency!=NULL && directionimage!=NULL)
{
fprintf(stdout, "Opening file %s...\n", argv[1]);
if(FvsOK!= FvsImageImport(image, argv[1],bmfh,&bmih,rgbq))
return -1 ;
FvsInt_t w = ImageGetWidth (image);
FvsInt_t h = ImageGetHeight(image);
ImageSetSize(directionimage, w, h);
ImageSoftenMean(image, 3);
ImageNormalize(image, 100, 10000);
fprintf(stdout, "1/4 Determining the ridge direction\n");
start=clock();
(void)FingerprintGetDirection(image, direction, 7, 8);
finish=clock();
cout<<"\tElapsed time for the ridge direction : "<<finish-start<<"ms\n";
fprintf(stdout, "2/4 Determining the ridge frequency\n");
start=clock();
(void)FingerprintGetFrequency1(image, direction, frequency);
finish=clock();
cout<<"\tElapsed time for the ridge frequency: "<<finish-start<<"ms\n";
fprintf(stdout, "3/4 Creating the mask\n");
start=clock();
(void)FingerprintGetMask(image, direction, frequency, mask);
finish=clock();
cout<<"\tElapsed time for the mask: "<<finish-start<<"ms\n";
fprintf(stdout, "4/4 Enhancing the fingerprint image\n");
start=clock();
(void)ImageEnhanceGabor(image, direction, frequency, mask, radius);
finish=clock();
cout<<"\tElapsed time for Enhancing the image: "<<finish-start<<"ms\n";
fprintf(stdout, "Creating a new image with the direction\n");
(void)OverlayDirection(directionimage, direction);
fprintf(stdout, "Saving file ...\n");
strcpy(filename,argv[1]);
strcat(filename,"_dir.bmp");
(void)FvsImageExport(directionimage, filename,bmfh,&bmih,rgbq);
strcpy(filename,argv[1]);
strcat(filename,"_mask.bmp");
(void)FvsImageExport(mask, filename,bmfh,&bmih,rgbq);
strcpy(filename,argv[1]);
strcat(filename,"_enh.bmp");
(void)FvsImageExport(image, filename,bmfh,&bmih,rgbq);
}
fprintf(stdout, "Cleaning up and exiting...\n");
FloatFieldDestroy(frequency);
FloatFieldDestroy(direction);
ImageDestroy(image);
ImageDestroy(mask);
ImageDestroy(directionimage);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -