static void ewin_cb_export_clicked(GtkWidget *widget, gpointer data) { struct fp_img *scan = NULL; int finger = GPOINTER_TO_INT(data); int r; char path[2048]; sprintf(path,"captured_%d.pgm",finger); if (!fp_dev_supports_imaging(fpdev)) { fprintf(stderr, "this device does not have imaging capabilities.\n"); return; } r = fp_dev_img_capture(fpdev,0,&scan); if (r != 0) { fprintf(stderr,"Image Capture Failed: %d\n",r); fp_img_free(scan); return; } fp_img_standardize(scan); r = fp_img_save_to_file(scan,path); fp_img_free(scan); if (r != 0) { fprintf(stderr,"Image Save Failed: %d\n",r); } return; }
static void verify_cb(struct fp_dev *dev, int result, struct fp_img *img, void *user_data) { GtkWidget *dialog; int r; destroy_scan_finger_dialog(GTK_WIDGET(user_data)); vwin_vfy_status_verify_result(result); fp_img_free(img_normal); img_normal = NULL; fp_img_free(img_bin); img_bin = NULL; if (img) { img_normal = img; img_bin = fp_img_binarize(img); vwin_img_draw(); } dialog = run_please_wait_dialog("Ending verification..."); r = fp_async_verify_stop(dev, verify_stopped_cb, dialog); if (r < 0) gtk_widget_destroy(dialog); }
/**Capture an image, standardize and binarize it, and write it to a file*/ void image_save_binarized(char* filename){ struct fp_img* img = image_get(); fp_img_standardize(img); struct fp_img* img_binarized = fp_img_binarize(img); image_writefile(img_binarized, filename); fp_img_free(img); //free it fp_img_free(img_binarized); }
void fpi_imgdev_image_captured(struct fp_img_dev *imgdev, struct fp_img *img) { struct fp_print_data *print; int r; fp_dbg(""); if (imgdev->action_state != IMG_ACQUIRE_STATE_AWAIT_IMAGE) { fp_dbg("ignoring due to current state %d", imgdev->action_state); return; } if (imgdev->action_result) { fp_dbg("not overwriting existing action result"); return; } r = sanitize_image(imgdev, &img); if (r < 0) { imgdev->action_result = r; fp_img_free(img); goto next_state; } fp_img_standardize(img); imgdev->acquire_img = img; r = fpi_img_to_print_data(imgdev, img, &print); if (r < 0) { fp_dbg("image to print data conversion error: %d", r); imgdev->action_result = FP_ENROLL_RETRY; goto next_state; } else if (img->minutiae->num < MIN_ACCEPTABLE_MINUTIAE) { fp_dbg("not enough minutiae, %d/%d", img->minutiae->num, MIN_ACCEPTABLE_MINUTIAE); fp_print_data_free(print); /* depends on FP_ENROLL_RETRY == FP_VERIFY_RETRY */ imgdev->action_result = FP_ENROLL_RETRY; goto next_state; } imgdev->acquire_data = print; switch (imgdev->action) { case IMG_ACTION_ENROLL: imgdev->action_result = FP_ENROLL_COMPLETE; break; case IMG_ACTION_VERIFY: verify_process_img(imgdev); break; case IMG_ACTION_IDENTIFY: identify_process_img(imgdev); break; default: BUG(); break; } next_state: imgdev->action_state = IMG_ACQUIRE_STATE_AWAIT_FINGER_OFF; dev_change_state(imgdev, IMGDEV_STATE_AWAIT_FINGER_OFF); }
static void vwin_clear(void) { fp_img_free(img_normal); img_normal = NULL; fp_img_free(img_bin); img_bin = NULL; fp_print_data_free(enroll_data); enroll_data = NULL; gtk_image_clear(GTK_IMAGE(vwin_verify_img)); gtk_widget_set_sensitive(vwin_img_save_btn, FALSE); gtk_list_store_clear(GTK_LIST_STORE(vwin_fingmodel)); gtk_label_set_text(GTK_LABEL(vwin_vfy_status), NULL); gtk_label_set_text(GTK_LABEL(vwin_minutiae_cnt), NULL); gtk_widget_set_sensitive(vwin_fingcombo, FALSE); gtk_widget_set_sensitive(vwin_vfy_button, FALSE); }
static void generic_acquire_stop(struct fp_img_dev *imgdev) { imgdev->action_state = IMG_ACQUIRE_STATE_DEACTIVATING; dev_deactivate(imgdev); fp_print_data_free(imgdev->acquire_data); fp_img_free(imgdev->acquire_img); imgdev->acquire_data = NULL; imgdev->acquire_img = NULL; imgdev->action_result = 0; }
static int capture(struct fp_img_dev *dev, gboolean unconditional, struct fp_img **ret) { int i; int r; struct fp_img *img; unsigned char *data; unsigned char *ptr; r = aes_write_regv(dev, init_reqs, G_N_ELEMENTS(init_reqs)); if (r < 0) return r; img = fpi_img_new_for_imgdev(dev); data = g_malloc(DATA_BUFLEN); ptr = data; /* See the timeout explanation in the uru4000 driver for the reasoning * behind this silly loop. */ retry: r = usb_bulk_read(dev->udev, EP_IN, data, DATA_BUFLEN, 1000); if (r == -ETIMEDOUT) goto retry; if (r < 0) { fp_err("data read failed, error %d", r); goto err; } else if (r < DATA_BUFLEN) { fp_err("short data read (%d)", r); r = -EIO; goto err; } for (i = 0; i < NR_SUBARRAYS; i++) { fp_dbg("subarray header byte %02x", *ptr); ptr++; aes_assemble_image(ptr, 96, 16, img->data + (i * 96 * 16)); ptr += SUBARRAY_LEN; } img->flags = FP_IMG_COLORS_INVERTED | FP_IMG_V_FLIPPED | FP_IMG_H_FLIPPED; *ret = img; g_free(data); return 0; err: g_free(data); fp_img_free(img); return r; }
static void loopsm_complete(struct fpi_ssm *ssm) { struct fp_img_dev *dev = ssm->priv; struct v5s_dev *vdev = dev->priv; int r = ssm->error; fpi_ssm_free(ssm); fp_img_free(vdev->capture_img); vdev->capture_img = NULL; vdev->loop_running = FALSE; if (r) fpi_imgdev_session_error(dev, r); if (vdev->deactivating) fpi_imgdev_deactivate_complete(dev); }
int verify(struct fp_dev *dev, struct fp_print_data *data) { int r; do { struct fp_img *img = NULL; sleep(1); printf("\nScan your finger now.\n"); r = fp_verify_finger_img(dev, data, &img); if (img) { fp_img_save_to_file(img, "verify.pgm"); printf("Wrote scanned image to verify.pgm\n"); fp_img_free(img); } if (r < 0) { printf("verification failed\n"); return r; } } while (1); }
int verify(struct fp_dev *dev, struct fp_print_data *data) { do { struct fp_img *img = NULL; sleep(1); printf("\nScan your finger now.\n"); int r = fp_verify_finger_img(dev, data, &img); if (img) { fp_img_save_to_file(img, "verify.pgm"); printf("Wrote scanned image to verify.pgm\n"); fp_img_free(img); } if (r < 0) { printf("verification failed with error %d :(\n", r); return r; } switch (r) { case FP_VERIFY_NO_MATCH: printf("NO MATCH!\n"); return 0; case FP_VERIFY_MATCH: printf("MATCH!\n"); return 0; case FP_VERIFY_RETRY: printf("Scan didn't quite work. Please try again.\n"); break; case FP_VERIFY_RETRY_TOO_SHORT: printf("Swipe was too short, please try again.\n"); break; case FP_VERIFY_RETRY_CENTER_FINGER: printf("Please center your finger on the sensor and try again.\n"); break; case FP_VERIFY_RETRY_REMOVE_FINGER: printf("Please remove finger from the sensor and try again.\n"); break; } } while (1); }
struct fp_print_data * enroll (struct fp_dev *dev) { struct fp_print_data *enrolled_print = NULL; int r; printf ("You will need to successfully scan your finger %d times to " "complete the process.\n", fp_dev_get_nr_enroll_stages (dev)); do { struct fp_img *img = NULL; sleep (1); printf ("\nScan your finger now.\n"); r = fp_enroll_finger_img (dev, &enrolled_print, &img); if (img) { fp_img_save_to_file (img, "enrolled.pgm"); printf ("Wrote scanned image to enrolled.pgm\n"); fp_img_free (img); } if (r < 0) { printf ("Enroll failed with error %d\n", r); return NULL; } switch (r) { case FP_ENROLL_COMPLETE: printf ("Enroll complete!\n"); break; case FP_ENROLL_FAIL: printf ("Enroll failed, something wen't wrong :(\n"); return NULL; case FP_ENROLL_PASS: printf ("Enroll stage passed. Yay!\n"); break; case FP_ENROLL_RETRY: printf ("Didn't quite catch that. Please try again.\n"); break; case FP_ENROLL_RETRY_TOO_SHORT: printf ("Your swipe was too short, please try again.\n"); break; case FP_ENROLL_RETRY_CENTER_FINGER: printf ("Didn't catch that, please center your finger on the " "sensor and try again.\n"); break; case FP_ENROLL_RETRY_REMOVE_FINGER: printf ("Scan failed, please remove your finger and then try " "again.\n"); break; } } while (r != FP_ENROLL_COMPLETE); if (!enrolled_print) { fprintf (stderr, "Enroll complete but no print?\n"); return NULL; } printf ("Enrollment completed!\n\n"); return enrolled_print; }
void fpi_imgdev_image_captured(struct fp_img_dev *imgdev, struct fp_img *img) { struct fp_print_data *print; int r; fp_dbg(""); if (imgdev->action_state != IMG_ACQUIRE_STATE_AWAIT_IMAGE) { fp_dbg("ignoring due to current state %d", imgdev->action_state); return; } if (imgdev->action_result) { fp_dbg("not overwriting existing action result"); return; } r = sanitize_image(imgdev, &img); if (r < 0) { imgdev->action_result = r; fp_img_free(img); goto next_state; } fp_img_standardize(img); imgdev->acquire_img = img; if (imgdev->action != IMG_ACTION_CAPTURE) { r = fpi_img_to_print_data(imgdev, img, &print); if (r < 0) { fp_dbg("image to print data conversion error: %d", r); imgdev->action_result = FP_ENROLL_RETRY; goto next_state; } else if (img->minutiae->num < MIN_ACCEPTABLE_MINUTIAE) { fp_dbg("not enough minutiae, %d/%d", img->minutiae->num, MIN_ACCEPTABLE_MINUTIAE); fp_print_data_free(print); /* depends on FP_ENROLL_RETRY == FP_VERIFY_RETRY */ imgdev->action_result = FP_ENROLL_RETRY; goto next_state; } } imgdev->acquire_data = print; switch (imgdev->action) { case IMG_ACTION_ENROLL: if (!imgdev->enroll_data) { imgdev->enroll_data = fpi_print_data_new(imgdev->dev); } BUG_ON(g_slist_length(print->prints) != 1); /* Move print data from acquire data into enroll_data */ imgdev->enroll_data->prints = g_slist_prepend(imgdev->enroll_data->prints, print->prints->data); print->prints = g_slist_remove(print->prints, print->prints->data); fp_print_data_free(imgdev->acquire_data); imgdev->acquire_data = NULL; imgdev->enroll_stage++; if (imgdev->enroll_stage == imgdev->dev->nr_enroll_stages) imgdev->action_result = FP_ENROLL_COMPLETE; else imgdev->action_result = FP_ENROLL_PASS; break; case IMG_ACTION_VERIFY: verify_process_img(imgdev); break; case IMG_ACTION_IDENTIFY: identify_process_img(imgdev); break; case IMG_ACTION_CAPTURE: imgdev->action_result = FP_CAPTURE_COMPLETE; break; default: BUG(); break; } next_state: imgdev->action_state = IMG_ACQUIRE_STATE_AWAIT_FINGER_OFF; dev_change_state(imgdev, IMGDEV_STATE_AWAIT_FINGER_OFF); }
/**Capture an image, standardize it, and write it to a file*/ void image_save(char* filename){ struct fp_img* img = image_get(); fp_img_standardize(img); image_writefile(img, filename); fp_img_free(img); //free it }