Could you try attached patch?
On Thu, Dec 22, 2016 at 10:24 AM, Carson Reinke <[email protected]> wrote:
> Thanks Vasily and all your work on this.
>
> I actually had the raw image dumped in fpi_assemble_lines instead and there
> is no more distortion. I tried to debug the exact issue but the code kind
> of makes my head spin. I think maybe not all images should be processed
> through this function, instead only "fast swipe" images that are shorter
> than a certain tolerance should be. Just a thought. If I come up with
> something, I'll send it over.
>
> On Fri, Dec 16, 2016 at 7:12 PM, Vasily Khoruzhick <[email protected]>
> wrote:
>>
>> Hi Carson,
>>
>> All related code is in libfprint/assembling.c, you're probably
>> interested in fpi_assemble_lines().
>>
>> Regards,
>> Vasily
>>
>> On Fri, Dec 16, 2016 at 1:17 PM, Carson Reinke <[email protected]> wrote:
>> > I seem to be having the same issue as reported by other awhile ago here:
>> > https://github.com/ars3niy/fprint_vfs5011/issues/9. The head from
>> > master
>> > seems to work better, but still quite a bit of distortion.
>> >
>> > I believe this from trying to normalize the image from fast swipes. Can
>> > anyone point me in a direction on where this is done?
>> >
>> > _______________________________________________
>> > fprint mailing list
>> > [email protected]
>> > https://lists.freedesktop.org/mailman/listinfo/fprint
>> >
>
>
From 0bb137cd68b1d17f8cb9c8cb66a5b41f097c6c99 Mon Sep 17 00:00:00 2001
From: Vasily Khoruzhick <[email protected]>
Date: Tue, 27 Dec 2016 19:04:32 -0800
Subject: [PATCH] lib: do horizontal search for line assembly
---
libfprint/assembling.c | 54 ++++++++++++++++++++++-----------------
libfprint/assembling.h | 2 +-
libfprint/drivers/upeksonly.c | 4 +--
libfprint/drivers/vfs0050.c | 2 +-
libfprint/drivers/vfs5011.c | 28 ++++++++++++++------
libfprint/drivers/vfs5011_proto.h | 1 +
6 files changed, 56 insertions(+), 35 deletions(-)
diff --git a/libfprint/assembling.c b/libfprint/assembling.c
index 1052f99..c44fea6 100644
--- a/libfprint/assembling.c
+++ b/libfprint/assembling.c
@@ -354,6 +354,7 @@ struct fp_img *fpi_assemble_lines(struct fpi_line_asmbl_ctx *ctx,
float y = 0.0;
int line_ind = 0;
int *offsets = (int *)g_malloc0((lines_len / 2) * sizeof(int));
+ int *dxes = (int *)g_malloc0((lines_len / 2) * sizeof(int));
unsigned char *output = g_malloc0(ctx->line_width * ctx->max_height);
struct fp_img *img;
@@ -363,24 +364,29 @@ struct fp_img *fpi_assemble_lines(struct fpi_line_asmbl_ctx *ctx,
for (i = 0; (i < lines_len - 1) && row1; i += 2) {
int bestmatch = i;
int bestdiff = 0;
- int j, firstrow, lastrow;
+ int bestdx = 0;
+ int j, firstrow, lastrow, dx;
firstrow = i + 1;
lastrow = min(i + ctx->max_search_offset, lines_len - 1);
row2 = g_slist_next(row1);
for (j = firstrow; j <= lastrow; j++) {
- int diff = ctx->get_deviation(ctx,
- row1,
- row2);
- if ((j == firstrow) || (diff < bestdiff)) {
- bestdiff = diff;
- bestmatch = j;
+ for (dx = -7; dx < 8; dx++) {
+ int diff = ctx->get_deviation(ctx,
+ row1,
+ row2, dx);
+ if ((j == firstrow) || (diff < bestdiff)) {
+ bestdiff = diff;
+ bestmatch = j;
+ bestdx = dx;
+ }
}
row2 = g_slist_next(row2);
}
offsets[i / 2] = bestmatch - i;
- fp_dbg("%d", offsets[i / 2]);
+ dxes[i / 2] = bestdx;
+ fp_dbg("offset: %d, dx: %d", offsets[i / 2], dxes[i / 2]);
row1 = g_slist_next(row1);
if (row1)
row1 = g_slist_next(row1);
@@ -394,22 +400,23 @@ struct fp_img *fpi_assemble_lines(struct fpi_line_asmbl_ctx *ctx,
row1 = lines;
for (i = 0; i < lines_len - 1; i++, row1 = g_slist_next(row1)) {
int offset = offsets[i/2];
- if (offset > 0) {
- float ynext = y + (float)ctx->resolution / offset;
- while (line_ind < ynext) {
- if (line_ind > ctx->max_height - 1)
- goto out;
- interpolate_lines(ctx,
- row1, y,
- g_slist_next(row1),
- ynext,
- output + line_ind * ctx->line_width,
- line_ind,
- ctx->line_width);
- line_ind++;
- }
- y = ynext;
+ float dy = (float)ctx->resolution / offset;
+ float ynext;
+ fp_dbg("dy: %f", (double)dy);
+ ynext = y + dy;
+ while (line_ind < ynext) {
+ if (line_ind > ctx->max_height - 1)
+ goto out;
+ interpolate_lines(ctx,
+ row1, y,
+ g_slist_next(row1),
+ ynext,
+ output + line_ind * ctx->line_width,
+ line_ind,
+ ctx->line_width);
+ line_ind++;
}
+ y = ynext;
}
out:
img = fpi_img_new(ctx->line_width * line_ind);
@@ -417,6 +424,7 @@ out:
img->width = ctx->line_width;
img->flags = FP_IMG_V_FLIPPED;
g_memmove(img->data, output, ctx->line_width * line_ind);
+ g_free(dxes);
g_free(offsets);
g_free(output);
return img;
diff --git a/libfprint/assembling.h b/libfprint/assembling.h
index 3bcab2f..072c3c7 100644
--- a/libfprint/assembling.h
+++ b/libfprint/assembling.h
@@ -53,7 +53,7 @@ struct fpi_line_asmbl_ctx {
unsigned median_filter_size;
unsigned max_search_offset;
int (*get_deviation)(struct fpi_line_asmbl_ctx *ctx,
- GSList *line1, GSList *line2);
+ GSList *line1, GSList *line2, int dx);
unsigned char (*get_pixel)(struct fpi_line_asmbl_ctx *ctx,
GSList *line,
unsigned x);
diff --git a/libfprint/drivers/upeksonly.c b/libfprint/drivers/upeksonly.c
index e4dce7c..6f07760 100644
--- a/libfprint/drivers/upeksonly.c
+++ b/libfprint/drivers/upeksonly.c
@@ -118,7 +118,7 @@ struct sonly_dev {
/* Calculade squared standand deviation of sum of two lines */
static int upeksonly_get_deviation2(struct fpi_line_asmbl_ctx *ctx,
- GSList *line1, GSList *line2)
+ GSList *line1, GSList *line2, int dx)
{
unsigned char *buf1 = line1->data, *buf2 = line2->data;
int res = 0, mean = 0, i;
@@ -162,7 +162,7 @@ static unsigned char upeksonly_get_pixel(struct fpi_line_asmbl_ctx *ctx,
static struct fpi_line_asmbl_ctx assembling_ctx = {
.max_height = 1024,
.resolution = 8,
- .median_filter_size = 25,
+ .median_filter_size = 13,
.max_search_offset = 30,
.get_deviation = upeksonly_get_deviation2,
.get_pixel = upeksonly_get_pixel,
diff --git a/libfprint/drivers/vfs0050.c b/libfprint/drivers/vfs0050.c
index 31d793c..b7bcf47 100644
--- a/libfprint/drivers/vfs0050.c
+++ b/libfprint/drivers/vfs0050.c
@@ -190,7 +190,7 @@ static unsigned char vfs0050_get_pixel(struct fpi_line_asmbl_ctx *ctx,
/* Deviation getter for fpi_assemble_lines */
static int vfs0050_get_difference(struct fpi_line_asmbl_ctx *ctx,
- GSList * line_list_1, GSList * line_list_2)
+ GSList * line_list_1, GSList * line_list_2, int dx)
{
struct vfs_line *line1 = line_list_1->data;
struct vfs_line *line2 = line_list_2->data;
diff --git a/libfprint/drivers/vfs5011.c b/libfprint/drivers/vfs5011.c
index 5aaccc1..4b39e82 100644
--- a/libfprint/drivers/vfs5011.c
+++ b/libfprint/drivers/vfs5011.c
@@ -253,13 +253,19 @@ static void usb_exchange_async(struct fpi_ssm *ssm,
/* ====================== utils ======================= */
/* Calculade squared standand deviation of sum of two lines */
-static int vfs5011_get_deviation2(struct fpi_line_asmbl_ctx *ctx, GSList *row1, GSList *row2)
+static int vfs5011_get_deviation2(struct fpi_line_asmbl_ctx *ctx,
+ GSList *row1, GSList *row2, int dx)
{
unsigned char *buf1, *buf2;
int res = 0, mean = 0, i;
- const int size = 64;
+ const int size = VFS5011_SHORT_LINE_WIDTH;
- buf1 = row1->data + 56;
+ if (dx > 7)
+ dx = 7;
+ if (dx < -7)
+ dx = -7;
+
+ buf1 = row1->data + 56 + dx;
buf2 = row2->data + 168;
for (i = 0; i < size; i++)
@@ -357,12 +363,13 @@ static int process_chunk(struct vfs5011_data *data, int transferred)
fp_dbg("process_chunk: got %d bytes", transferred);
int lines_captured = transferred/VFS5011_LINE_SIZE;
int i;
+ int sq_diff_norm = 0;
for (i = 0; i < lines_captured; i++) {
unsigned char *linebuf = data->capture_buffer
+ i * VFS5011_LINE_SIZE;
- if (fpi_std_sq_dev(linebuf + 8, VFS5011_IMAGE_WIDTH)
+ if (fpi_std_sq_dev(linebuf + 168, VFS5011_SHORT_LINE_WIDTH)
< DEVIATION_THRESHOLD) {
if (data->lines_captured == 0)
continue;
@@ -383,11 +390,16 @@ static int process_chunk(struct vfs5011_data *data, int transferred)
return 1;
}
+ if (data->lastline != NULL) {
+ sq_diff_norm = fpi_mean_sq_diff_norm(data->lastline + 8,
+ linebuf + 8,
+ VFS5011_IMAGE_WIDTH);
+ sq_diff_norm += fpi_mean_sq_diff_norm(data->lastline + 168,
+ linebuf + 168,
+ VFS5011_SHORT_LINE_WIDTH);
+ }
if ((data->lastline == NULL)
- || (fpi_mean_sq_diff_norm(
- data->lastline + 8,
- linebuf + 8,
- VFS5011_IMAGE_WIDTH) >= DIFFERENCE_THRESHOLD)) {
+ || sq_diff_norm >= DIFFERENCE_THRESHOLD) {
data->lastline = g_malloc(VFS5011_LINE_SIZE);
data->rows = g_slist_prepend(data->rows, data->lastline);
g_memmove(data->lastline, linebuf, VFS5011_LINE_SIZE);
diff --git a/libfprint/drivers/vfs5011_proto.h b/libfprint/drivers/vfs5011_proto.h
index 8cd0ea8..d162d47 100644
--- a/libfprint/drivers/vfs5011_proto.h
+++ b/libfprint/drivers/vfs5011_proto.h
@@ -3,6 +3,7 @@
#define VFS5011_LINE_SIZE 240
#define VFS5011_IMAGE_WIDTH 160
+#define VFS5011_SHORT_LINE_WIDTH 64
enum {
VFS5011_DEFAULT_WAIT_TIMEOUT = 3000,
--
2.11.0
_______________________________________________
fprint mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/fprint