-
Notifications
You must be signed in to change notification settings - Fork 0
/
recog.c
67 lines (58 loc) · 1.29 KB
/
recog.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "image.h"
#include "font.h"
#include <stdio.h>
#include <string.h>
static int font_array[50];
void recognize_init()
{
memset(&font_array[0], 0, sizeof(font_array));
}
int recognize_font(struct image *block, struct image *font, int range)
{
int i, ret = 0;
unsigned int weight = ~0U, w;
struct image *tmpblk = image_new(BLOCK_X, BLOCK_Y);
int from, stop;
if (range == 0) {
from = 0;
stop = 25;
} else {
from = 24;
stop = 50;
}
for (i = from; i < stop; ++i) {
// for (i = 0; i < 50; ++i) {
if (font_array[i] == 1)
continue;
font_getimage(font, tmpblk, i);
w = image_weight(tmpblk, block);
// printf("[%d] weight: %d\n", i, w);
if (w < weight) {
weight = w;
ret = i;
}
}
// printf("[%d] = %d\n", ret+1, w);
image_destroy(tmpblk);
font_array[ret] = 1;
return ret;
}
void recognize(struct image *image, struct image *font, struct Glyph *glyph, int range)
{
int i, j, number;
struct Glyph *glyptr;
struct image *outblk = image_new(BLOCK_X, BLOCK_Y);
for (j = 0; j < 5; ++j) {
for (i = 0; i < 5; ++i) {
image_getblock(image, outblk, i, j);
number = recognize_font(outblk, font, range);
glyptr = glyph + (number);
glyptr->number = number+1;
glyptr->x = i;
glyptr->y = j;
printf("%02d ", number+1);
}
printf("\n");
}
image_destroy(outblk);
}