finder_scan: Improve capstone detection on small images
When using small captured images, I somehow frequently see failures to recognize a capstone due to rounding errors. eg. when pb[] = {2 3 8 3 2}. This commit tries to improve it by using fixed-point arithmetics. The scaling factor was chosen somehow arbitrary. A moderate scaling should be enough.
This commit is contained in:
parent
734258c775
commit
65379a7c39
1 changed files with 4 additions and 3 deletions
|
@ -438,17 +438,18 @@ static void finder_scan(struct quirc *q, unsigned int y)
|
||||||
run_count++;
|
run_count++;
|
||||||
|
|
||||||
if (!color && run_count >= 5) {
|
if (!color && run_count >= 5) {
|
||||||
|
const int scale = 16;
|
||||||
static const unsigned int check[5] = {1, 1, 3, 1, 1};
|
static const unsigned int check[5] = {1, 1, 3, 1, 1};
|
||||||
unsigned int avg, err;
|
unsigned int avg, err;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int ok = 1;
|
int ok = 1;
|
||||||
|
|
||||||
avg = (pb[0] + pb[1] + pb[3] + pb[4]) / 4;
|
avg = (pb[0] + pb[1] + pb[3] + pb[4]) * scale / 4;
|
||||||
err = avg * 3 / 4;
|
err = avg * 3 / 4;
|
||||||
|
|
||||||
for (i = 0; i < 5; i++)
|
for (i = 0; i < 5; i++)
|
||||||
if (pb[i] < check[i] * avg - err ||
|
if (pb[i] * scale < check[i] * avg - err ||
|
||||||
pb[i] > check[i] * avg + err)
|
pb[i] * scale > check[i] * avg + err)
|
||||||
ok = 0;
|
ok = 0;
|
||||||
|
|
||||||
if (ok)
|
if (ok)
|
||||||
|
|
Loading…
Reference in a new issue