?? frontend.c
字號:
if ( mbarwidth > 2)
{
if ( mod_bar_cnt < MAX_MOD_BARS)
{
mod_bar_array[mod_bar_cnt].width = mbarwidth;
mod_bar_array[mod_bar_cnt].endx = mod_line_x[lpixel];
if (mod_bar_cnt > 0)
{
mod_bar_array[mod_bar_cnt].space_width =
(mod_bar_array[mod_bar_cnt].lpixel
- mod_bar_array[mod_bar_cnt-1].lpixel) -
mod_bar_array[mod_bar_cnt-1].width;
}
else
{
mod_bar_array[mod_bar_cnt].space_width = lpixel;
}
mod_bar_cnt += 1;
}
else
{
printf("Warning: More than 5 bars found in module at row = %d col = %d \n",
in_row, in_col );
}
}
if (debug) { printf("mod_pixel_cnt = %d \n", mod_pixel_cnt); }
if ( (mod_bar_cnt +1) < MAX_MOD_BARS)
{
mod_bar_array[mod_bar_cnt+1].space_width = mod_pixel_cnt -
mod_bar_array[mod_bar_cnt].lpixel
- mod_bar_array[mod_bar_cnt].width;
}
}
void get_bar()
{
int gbarwidth;
gbarwidth = 0;
if ( bar_cnt < MAX_BARS)
{
bar_array[bar_cnt].beginx = line_x[lpixel];
bar_array[bar_cnt].beginy = line_y[lpixel];
bar_array[bar_cnt].lpixel = lpixel;
}
else
{
printf("Too many bars across symbol \n");
exit(-1);
}
while(( line_data[lpixel] > line_threshold ) && ( lpixel < pixel_cnt))
{
lpixel += 1;
gbarwidth += 1;
}
if ( gbarwidth > 2)
{
if ( bar_cnt < MAX_BARS)
{
bar_array[bar_cnt].width = gbarwidth;
bar_array[bar_cnt].endx = line_x[lpixel];
bar_array[bar_cnt].endy = line_y[lpixel];
if (bar_cnt > 0)
{
bar_array[bar_cnt].space_width = (bar_array[bar_cnt].lpixel
- bar_array[bar_cnt-1].lpixel) -
bar_array[bar_cnt-1].width;
}
else
{
bar_array[bar_cnt].space_width = lpixel;
}
bar_cnt += 1;
}
else
{
printf("Too many bars across symbol\n");
exit(-1);
}
}
}
// look thru the out pix_out data and
// and find out where the left wide bar ends in the y direction
void find_left_highy(int iny)
{
int leftx;
int lefty;
int debug;
debug = 0;
leftx = save_line_data[save_line_cnt].beginwidth / 2;
lefty = iny;
if (debug)
{
printf("In find left highy , leftx, lefty = %d %d \n",
leftx, lefty );
}
if (debug) { printf("In find left highy, x,y = %d %d \n", leftx, lefty); }
while(( lefty > 0) && (( pix_out[leftx][lefty].greyval > dark_threshold) ||
( pix_out[leftx][lefty-1].greyval > dark_threshold)))
{
lefty -=1;
if ( debug)
{
printf("In find left highy , leftx = %d lefty = %d grey = %d \n",
leftx,lefty, pix_out[leftx][lefty].greyval);
}
}
left_highy = lefty;
left_highx = leftx;
if ( debug)
{
printf("In get left_highy , left_highx, left_highy = %d %d \n",
left_highx, left_highy );
}
}
// look thru the out pix data and
// and find out where the right wide bar ends in the y direction
void find_right_highy(int iny)
{
int rightx;
int righty;
int debug;
debug = 0;
rightx = save_line_data[save_line_cnt].endlpixel +
( save_line_data[save_line_cnt].endwidth / 2);
righty = iny;
if (debug)
{
printf("In find right highy , rightx, righty = %d %d \n",
rightx, righty );
}
if (debug) { printf("In find right highy, x,y = %d %d \n", rightx, righty); }
while(( righty > 0) && ((pix_out[rightx][righty].greyval > dark_threshold)
|| ( pix_out[rightx][righty-1].greyval > dark_threshold)))
{
righty -=1;
if (debug)
{
printf("In find right highy , rightx = %d righty = %d grey = %d\n",
rightx, righty, pix_out[rightx][righty].greyval);
}
}
right_highy = righty;
right_highx = rightx;
if ( debug)
{
printf("In get right_highy , right_highx, right_highy = %d %d \n",
right_highx, right_highy );
}
}
void decode_line()
{
int ii;
int end_bar;
int normal_xy_ind;
int dnormal_x, dnormal_y, normal_dir, normal_slope;
int kk;
int endratio2sp2;
int endratio3sp3;
int endratio4sp4;
int endratio5sp5;
int end_bar_found;
int b1wid;
float b0widthf;
float b1widthf;
float b2widthf;
float b3widthf;
float b1spwidthf;
float b2spwidthf;
float b3spwidthf;
float ratio_1to2;
float ratio_1to3;
float ratio_1to4;
float ratio_2to3;
float ratio_2to4;
float ratio_3to4;
float ratio_1to2sp;
float ratio_2to2sp;
float ratio_3to3sp;
float ratio_4to4sp;
float fig_of_merit;
int test_barwidth_low;
int test_barwidth_high;
int fig;
int debug;
debug = 0;
lpixel = 0;
bar_cnt = 0;
if ( debug)
{
printf("In decode line \n");
}
while( lpixel < pixel_cnt )
{
skip_underthress();
if ( lpixel < pixel_cnt)
{
get_bar();
}
}
for ( ii = 0; ii < bar_cnt; ii += 1)
{
if (debug)
{
printf("Bar data ii = %d width = %d space_width = %d lpixel = %d \n",ii,
bar_array[ii].width, bar_array[ii].space_width,
bar_array[ii].lpixel);
}
}
if ( bar_cnt > 2)
{
// save away bar information if more than 3 bars
save_line_data[save_line_cnt].barcnt = bar_cnt;
if ( bar_cnt < 8)
{
end_bar = bar_cnt;
}
else
{
end_bar = 8;
}
for ( ii = 0; ii < end_bar; ii += 1)
{
save_line_data[save_line_cnt].tbar[ii].width = bar_array[ii].width;
save_line_data[save_line_cnt].tbar[ii].space_width =
bar_array[ii].space_width;
save_line_data[save_line_cnt].tbar[ii].lpixel = bar_array[ii].lpixel;
}
// calculate merit value
if ( bar_array[ii].lpixel < b_box_xlen / 2)
{
b0widthf = (float) bar_array[0].width;
b1widthf = (float) bar_array[1].width;
b2widthf = (float) bar_array[2].width;
b3widthf = (float) bar_array[3].width;
b1spwidthf = (float) bar_array[1].space_width;
b2spwidthf = (float) bar_array[2].space_width;
b3spwidthf = (float) bar_array[2].space_width;
ratio_1to2 = b0widthf / b1widthf;
ratio_1to3 = b0widthf / b2widthf;
ratio_1to4 = b0widthf / b3widthf;
ratio_2to3 = b1widthf / b2widthf;
ratio_2to4 = b1widthf / b3widthf;
ratio_3to4 = b2widthf / b3widthf;
ratio_2to2sp = b1widthf/b1spwidthf;
ratio_3to3sp = b2widthf/b2spwidthf;
ratio_4to4sp = b3widthf/b3spwidthf;
ratio_1to2sp = b1widthf/b2spwidthf;
onewidthf = ( b1widthf + b2widthf + b3widthf)/3;
fig_of_merit = (float) (fabs( ratio_1to2 - 8.0) +
fabs( ratio_1to3 - 8.0) +
fabs( ratio_1to4 - 8.0) +
fabs( ratio_2to3 - 1.0) +
fabs( ratio_2to4 - 1.0) +
fabs( ratio_3to4 - 1.0) +
fabs( ratio_2to2sp - 1.0) +
fabs( ratio_3to3sp - 1.0) +
fabs( ratio_4to4sp - 1.0));
fig = (int) 100 * fig_of_merit;
fig = abs( fig );
}
else
{
fig = 1000; // way off value
}
if (debug) { printf(" fig = %d \n",fig); }
save_line_data[save_line_cnt].fig = fig;
normal_xy_ind = (bar_array[1].lpixel + bar_array[1].width)
+ (bar_array[1].width/ 4);
dnormal_x = save_line_data[save_line_cnt].line_x[normal_xy_ind];
dnormal_y = save_line_data[save_line_cnt].line_y[normal_xy_ind];
normal_slope = save_line_data[save_line_cnt].slope;
// dir of normal is negative of line dir
normal_dir = 0 - save_line_data[save_line_cnt].dir;
// normal slope is the same as line normal, but will
// be treated in draw normal as x/y not y/x
// draw normal line , grey data in norm_line_data
draw_normal(dnormal_x,dnormal_y,normal_slope, normal_dir, b_box_ylen/2);
normal_xy_ind = (bar_array[0].lpixel + bar_array[0].width/2);
dnormal_x = save_line_data[save_line_cnt].line_x[normal_xy_ind];
dnormal_y = save_line_data[save_line_cnt].line_y[normal_xy_ind];
normal_slope = save_line_data[save_line_cnt].slope;
if (( norm_fdark_ind == -1) || ( norm_fdark_ind > b_box_ylen/3))
{
if ( abs( fig ) < 1000)
{
find_height( dnormal_x, dnormal_y, normal_slope,
normal_dir, b_box_ylen);
normal_xy_ind = ( bar_array[0].lpixel);
dnormal_x = save_line_data[save_line_cnt].line_x[normal_xy_ind];
dnormal_y = save_line_data[save_line_cnt].line_y[normal_xy_ind];
if (debug) { printf("Looking for end bars \n"); }
end_bar_found = FALSE;
// try to find the end bars
for (kk = 3; kk < bar_cnt; kk += 1)
{
test_barwidth_low = bar_array[0].width - bar_array[1].width
- bar_array[1].width - bar_array[1].width;
test_barwidth_high = bar_array[0].width +
bar_array[1].width * 2;
if (debug) {
printf("t_barwidth_low = %d , t_barwidth_high = %d \n",
test_barwidth_low, test_barwidth_high);
printf("bar 0 width = %d bar 1 width = %d \n",
bar_array[0].width, bar_array[1].width );
printf("bar kk width = %d for kk = %d \n",
bar_array[kk].width, kk );
}
if(( bar_array[kk].width > test_barwidth_low) &&
( bar_array[kk].width < test_barwidth_high))
{
if (debug) { printf("Test 1 success, kk = %d \n",kk); }
if (debug) { printf("bar_cnt = %d \n", bar_cnt); }
if ( kk < bar_cnt - 4 ) // 4 more bars
{
endratio2sp2 = 10 * bar_array[kk+1].space_width
/ bar_array[kk+1].width;
endratio3sp3 = 10 * bar_array[kk+2].space_width
/ bar_array[kk+2].width;
endratio4sp4 = 10 * bar_array[kk+3].space_width
/ bar_array[kk+3].width;
endratio5sp5 = 10 * bar_array[kk+4].space_width
/ bar_array[kk+4].width;
if (debug)
{
printf("endratio2sp2 = %d \n",endratio2sp2);
printf("endratio3sp3 = %d \n",endratio3sp3);
printf("endratio4sp4 = %d \n",endratio4sp4);
printf("endratio5sp5 = %d \n",endratio5sp5);
}
if (( endratio2sp2 > 3) && ( endratio2sp2 < 18))
{
if (( endratio3sp3 >18) && ( endratio3sp3 < 49))
{
if ((endratio4sp4 > 3) && (endratio4sp4 < 18))
{
if ((endratio5sp5 >10)&&(endratio5sp5 < 30))
{
b1wid = bar_array[1].width;
if (( bar_array[kk+1].width/2 ) < b1wid )
{
if (( bar_array[kk+2].width/2)< b1wid)
{
if ((bar_array[kk+3].width/2) < b1wid)
{
if (debug) {
printf("End bar found at %d \n",
bar_array[kk].lpixel -
bar_array[0].lpixel);
}
end_bar_found = TRUE;
save_line_data[save_line_cnt].endlpixel
= bar_array[kk].lpixel
- bar_array[0].lpixel;
save_line_data[save_line_cnt].has_7111
= TRUE;
save_line_data[save_line_cnt].endwidth=
bar_array[kk].width;
save_line_data[save_line_cnt].beginwidth=
bar_array[0].width;
}
}
}
}
}
}
}
}
}
}
if (( fig < bestfig ) && ( end_bar_found == TRUE))
{
find_left_edge( dnormal_x, dnormal_y, normal_slope,
normal_dir, b_box_ylen/2 , b_box_xlen);
if (debug) { printf("Found left_edge finished \n"); }
fig_flag = TRUE;
best_normal_x = dnormal_x;
best_normal_y = dnormal_y;
best_normal_slope = normal_slope;
best_normal_dir = normal_dir;
bestfig = fig;
onewidth = ( int) onewidthf; // width of 1 unit
best_onewidth = onewidth;
if ( debug) {
printf("Setting best_onewidth = %d \n", best_onewidth); }
begin_left_col = bar_array[4].lpixel- bar_array[0].lpixel;
begin_right_bars = save_line_data[save_line_cnt].endlpixel;
best_begin_left_col = begin_left_col;
best_begin_right_bars = begin_right_bars;
num_sym_cols = ( begin_right_bars - begin_left_col)/
begin_left_col;
best_num_sym_cols = num_sym_cols;
onewf = (float) ( begin_left_col);
onewf = onewf / 17;
best_onewf = onewf;
if (debug)
{
printf("Setting best_onewf = %f \n", best_onewf);
}
if (debug) { printf("About to call find_left_highy \n"); }
find_left_highy(b_box_ylen/2);
find_right_highy(b_box_ylen/2);
if ( (right_highx - left_highx) != 0)
{
pix_slope = ( 1000 * ( right_highy - left_highy)) /
( right_highx - left_highx);
}
else
{
printf("No change in x direction for symbol \n");
exit(0);
}
best_pix_slope = pix_slope;
best_pixel_out_xlen = pixel_out_xlen;
best_pixel_out_ylen = pixel_out_ylen;
final_pix( pixel_out_xlen, pixel_out_ylen);
if (debug) {
printf("New best fig = %d onewidth = %d \n",fig,onewidth);
}
}
}
}
save_line_cnt += 1;
} // more than 3 bars
}
// threshold the line data
//
//
void smooth_line()
{
int jj;
int pixel_new;
int debug;
debug = 0;
for(jj = 0; jj < pixel_cnt; jj += 1)
{
if ( line_data[jj] > line_threshold )
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -