2007-10-26 23:06:53 +00:00
|
|
|
/*
|
|
|
|
* Example libfprint image capture program
|
|
|
|
* Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <libfprint/fprint.h>
|
|
|
|
|
|
|
|
struct fp_dscv_dev *discover_device(struct fp_dscv_dev **discovered_devs)
|
|
|
|
{
|
2007-12-01 13:00:33 +00:00
|
|
|
struct fp_dscv_dev *ddev = discovered_devs[0];
|
|
|
|
struct fp_driver *drv;
|
|
|
|
if (!ddev)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
drv = fp_dscv_dev_get_driver(ddev);
|
|
|
|
printf("Found device claimed by %s driver\n", fp_driver_get_full_name(drv));
|
2007-10-26 23:06:53 +00:00
|
|
|
return ddev;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
int r = 1;
|
|
|
|
struct fp_dscv_dev *ddev;
|
|
|
|
struct fp_dscv_dev **discovered_devs;
|
|
|
|
struct fp_dev *dev;
|
|
|
|
struct fp_img *img = NULL;
|
|
|
|
|
2018-05-24 10:42:47 +00:00
|
|
|
setenv ("G_MESSAGES_DEBUG", "all", 0);
|
|
|
|
setenv ("LIBUSB_DEBUG", "3", 0);
|
|
|
|
|
2007-10-26 23:06:53 +00:00
|
|
|
r = fp_init();
|
|
|
|
if (r < 0) {
|
|
|
|
fprintf(stderr, "Failed to initialize libfprint\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
discovered_devs = fp_discover_devs();
|
|
|
|
if (!discovered_devs) {
|
|
|
|
fprintf(stderr, "Could not discover devices\n");
|
2007-11-13 14:32:31 +00:00
|
|
|
goto out;
|
2007-10-26 23:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ddev = discover_device(discovered_devs);
|
|
|
|
if (!ddev) {
|
2018-03-11 12:44:31 +00:00
|
|
|
fp_dscv_devs_free(discovered_devs);
|
2007-10-26 23:06:53 +00:00
|
|
|
fprintf(stderr, "No devices detected.\n");
|
2007-11-13 14:32:31 +00:00
|
|
|
goto out;
|
2007-10-26 23:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dev = fp_dev_open(ddev);
|
|
|
|
fp_dscv_devs_free(discovered_devs);
|
|
|
|
if (!dev) {
|
|
|
|
fprintf(stderr, "Could not open device.\n");
|
2007-11-13 14:32:31 +00:00
|
|
|
goto out;
|
2007-10-26 23:06:53 +00:00
|
|
|
}
|
|
|
|
|
2007-11-02 17:04:19 +00:00
|
|
|
if (!fp_dev_supports_imaging(dev)) {
|
|
|
|
fprintf(stderr, "this device does not have imaging capabilities.\n");
|
2007-10-26 23:06:53 +00:00
|
|
|
goto out_close;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Opened device. It's now time to scan your finger.\n\n");
|
|
|
|
|
2007-11-02 17:04:19 +00:00
|
|
|
r = fp_dev_img_capture(dev, 0, &img);
|
2007-10-26 23:06:53 +00:00
|
|
|
if (r) {
|
|
|
|
fprintf(stderr, "image capture failed, code %d\n", r);
|
|
|
|
goto out_close;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = fp_img_save_to_file(img, "finger.pgm");
|
|
|
|
if (r) {
|
|
|
|
fprintf(stderr, "img save failed, code %d\n", r);
|
|
|
|
goto out_close;
|
|
|
|
}
|
|
|
|
|
2007-10-27 11:07:11 +00:00
|
|
|
fp_img_standardize(img);
|
|
|
|
r = fp_img_save_to_file(img, "finger_standardized.pgm");
|
2007-10-27 14:16:54 +00:00
|
|
|
fp_img_free(img);
|
2007-10-27 11:07:11 +00:00
|
|
|
if (r) {
|
|
|
|
fprintf(stderr, "standardized img save failed, code %d\n", r);
|
|
|
|
goto out_close;
|
|
|
|
}
|
|
|
|
|
2007-10-26 23:06:53 +00:00
|
|
|
r = 0;
|
|
|
|
out_close:
|
|
|
|
fp_dev_close(dev);
|
2007-11-13 14:32:31 +00:00
|
|
|
out:
|
|
|
|
fp_exit();
|
2007-10-26 23:06:53 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|