整个tomoe手写识别流程都实现了,就是到下面这个识别函数的时候,速度不够快!
求高手指教!
(PS:linux PC 平台的,没问题! 就是移植到mips 开发板,就有问题!)
static GPtrArray *
get_candidates (GList *points, GPtrArray *cands) //用points对应cands查找数据
{
GPtrArray *rtn_cands;
guint cand_index = 0;
guint strk_index = 0;
gint i_nop = 0; /* input stroke number of points */
tomoe_metric *i_met = NULL; /* input stroke metrics */
gint d_nop = 0; /* dict stroke number of points */
TomoePoint *pi0, *pil;
rtn_cands = g_ptr_array_new ();
i_nop = g_list_length (points);
stroke_calculate_metrics (points, &i_met);
pi0 = (TomoePoint *) g_list_nth_data (points, 0); //每笔首坐标(x,y)
pil = (TomoePoint *) g_list_nth_data (points, i_nop - 1); //每笔末坐标(x,y)
for (cand_index = 0; cand_index < cands->len; cand_index++) { //笔画循环查找
gboolean match_flag = FALSE;
cand_priv *cand_p;
GArray *tmp = NULL;
TomoeChar *lttr;
TomoeWriting *writing;
TomoeCandidate *cand;
GList *writing_strokes, *list;
guint stroke_num;
cand_p = g_ptr_array_index (cands, cand_index);
tmp = _g_array_copy_int_value (cand_p->adapted_strokes);
cand = TOMOE_CANDIDATE (cand_p->cand);
lttr = tomoe_candidate_get_char (cand);
writing = tomoe_char_get_writing (lttr);
writing_strokes = (GList *) tomoe_writing_get_strokes (writing);
stroke_num = g_list_length (writing_strokes);
for (list = writing_strokes, strk_index = 0;
list;
list = g_list_next (list), strk_index++) {//用每一个笔画对应xml文件
GList *writing_points;
TomoePoint *pw0, *pw1, *pwl;
gint d1 = 0, d2 = 0;
gint d3 = 0, d4 = 0;
gint score1 = 0, score2 = 0;
gint score3 = 0;
gdouble d_angle = 0;
/* if the stroke index is already appended to, the value is ignored */
if (_g_array_has_this_int_value (tmp, strk_index))
continue;
writing_points = (GList *) list->data;
d_nop = g_list_length (writing_points);
/*
* Distance between the point and begining point.
* Distance between the point and ending point.
* Number of characteristic points.
*/
pw0 = (TomoePoint *) g_list_nth_data (writing_points, 0);
d1 = dist_tomoe_points (pi0, pw0);
pwl = (TomoePoint *) g_list_nth_data (writing_points, d_nop - 1);
d2 = dist_tomoe_points (pil, pwl);
score3 = (d1 + d2);
tomoe_candidate_set_score (
cand,
tomoe_candidate_get_score (cand) + score3);
if (d1 > LIMIT_LENGTH ||
d2 > LIMIT_LENGTH ||
abs (d_nop - i_nop) > 3) {
continue;
}
d3 = i_met[0].d;
pw1 = (TomoePoint *) g_list_nth_data (writing_points, 1);
d_angle = atan2 (pw1->y - pw0->y, pw1->x - pw0->x);
d4 = dist_tomoe_points (pw0, pw1);
/* threshold is (angle of bigining line) % 45[degree] (PI/4)*/
if (d3 > LIMIT_LENGTH &&
d4 > LIMIT_LENGTH &&
abs (d_angle - i_met[0].angle) > M_PI_4) {
continue;
}
/*
* Distance and angle of each characteristic points:
* (Compare handwriting data with dictionary data)
*/
score1 = match_input_to_dict (points, writing_points);
if (score1 < 0) {
tomoe_candidate_set_score (
cand,
tomoe_candidate_get_score (cand) * 2);
continue;
}
tomoe_candidate_set_score (
cand,
tomoe_candidate_get_score (cand) + score1);
/*
* Distance and angle of each characteristic points:
* (Compare dictionary data with handwriting data)
*/
score2 = match_dict_to_input (writing_points, points);
/* score2 = match_input_to_dict (writing_points, points); */
if (score2 < 0) {
tomoe_candidate_set_score (
cand,
tomoe_candidate_get_score (cand) * 2);
continue;
}
tomoe_candidate_set_score (
cand_p->cand,
tomoe_candidate_get_score (cand) + score2);
g_array_append_val (cand_p->adapted_strokes, strk_index);
match_flag = TRUE;
list = NULL;
}
if (match_flag) {
g_ptr_array_add (rtn_cands, cand_p);
}
g_array_free (tmp, TRUE);
//if (rtn_cands->len >= 220) break;
}
free (i_met);
return rtn_cands;
}
速度不够快,加快时钟频率,优化程序结构 加个时间计数的代码 看看运行需要多长时间