I'm capturing fingerprints using a device called Secugen Pro 20, it has its own SDK for Linux, and i want to capture the fingerprint image and save it as any image format.
They have this typedef unsigned char BYTE;
I declared my imageBuffer
BYTE *CurrentImageBuffer;
Then i allocate memory to it using the devices specs
CurrentImageBuffer = malloc(device_info.ImageWidth*device_info.ImageHeight);
And at some point at my code i capture image and pass CurrentImageBuffer
as argument to the capture function:
SGFPM_GetImageEx(m_hFPM, CurrentImageBuffer, GET_IMAGE_TIMEOUT, NULL, GET_IMAGE_DESIRED_QUALITY)
Thats what the variable looks right after this line of code ( i can confirm that it captured a finger):
I just don't understand how to proceed creating an image from this buffer, as it doesn't look like a ByteArray
I don't even know if thats the right place to get my image from, but that looks like the right place because its a buffer, right?.
OBS: I'm new to C
The easiest way to get an image is to make a NetPBM PGM image - see Wikipedia NetPBM page.
So, if your image is say 640 px wide by 480 px tall, you would get a buffer from your SDK with 307,200 bytes and you would write that to a file and check it has the correct length. Call that
image.raw
.Now you just need a PGM header, and as your image is greyscale and binary, you need a
P5
header.So, in Terminal you can put a header on:
If you are unfamiliar with that syntax, you can get the same with:
And you can view that image with
feh
,gimp
, Photoshop etc.If you want to make it into a BMP, or JPEG, or PNG, use ImageMagick which is installed on most Linux distros and is available for macOS and Windows:
or
If your version of ImageMagick is v6 or older, use
convert
in place ofmagick
:This is a small sample program to write an 8-bit graylevel image into a Windows BMP file:
The sample image provides some kind of gradients horizontally and vertically. I've chosen a width of 6 intentionally to check/show that row alignment is done properly.
The implementation is based on the description in Wikipedia BMP file format.
To keep it short, I encoded the simplest format – the ancient
BITMAPCOREHEADER
of Windows 2.0 and OS/2 1.x. (MS Paint can load this as well as the Windows 10 preview. I tested with GIMP which loaded as well without any complaints.)This is how it looks in GIMP:
If you have correctly captured the image in CurrentImageBuffer, you can write this as raw file using the code fragment below:
As I have used the same environment, I am sending the above fragment from my working codebase. Actually, raw file is later converted to template which is later used for matching / identification and not directly used for viewing etc. Variable rawFileName stores the name of the file as char array (string) where this buffer is stored.