?? frontend.c
字號:
{
for ( jj = 0; jj < width; jj += 1)
{
if ( ii + jj < MAX_Y_PIXEL)
{
pixel_array[beginx][ii+jj].greyval = 510;
}
}
}
}
}
if (( beginy - endy ) == 0) // horizontal
{
if ( endx > beginx )
{
for ( ii = beginx; ii < endx; ii += 1)
{
for ( jj = 0; jj < width; jj += 1)
{
if ( ii + jj < MAX_X_PIXEL)
{
pixel_array[ii + jj ][beginy].greyval = 510;
}
}
}
}
else
{
for ( ii = endx; ii < beginx; ii += 1)
{
for ( jj = 0; jj < width; jj += 1)
{
if ( ii + jj < MAX_X_PIXEL)
{
pixel_array[ii + jj][beginy].greyval = 510;
}
}
}
}
}
}
//
// Search thru all the dark squares found and find the
// min and max of the x and y directions to make a box
void find_dark_sq_box()
{
int ii;
int debug;
min_box_x = MAX_X_PIXEL;
min_box_y = MAX_Y_PIXEL;
max_box_x = 0;
max_box_y = 0;
debug = 0;
for (ii = 0; ii < dark_sqindex; ii += 1)
{
if ( dark_squares[ii].xloc > max_box_x)
{
max_box_x = dark_squares[ii].xloc;
}
if ( dark_squares[ii].yloc > max_box_y)
{
max_box_y = dark_squares[ii].yloc;
}
if ( dark_squares[ii].xloc < min_box_x)
{
min_box_x = dark_squares[ii].xloc;
}
if ( dark_squares[ii].yloc < max_box_y)
{
min_box_y = dark_squares[ii].yloc;
}
}
min_box_x = min_box_x - box_x_incr;
min_box_y = min_box_y - box_y_incr;
max_box_x = max_box_x + box_x_incr;
max_box_y = max_box_y + box_y_incr;
if (debug)
{
printf("In find dark square bounding box \n");
printf(" min x,y = %d %d \n", min_box_x, min_box_y);
printf(" max x,y = %d %d \n", max_box_x, max_box_y);
}
// draw a box around the dark squares and put this in pixel_array
// then you can dump out the pixel_array and see how good it is
if ( debug)
{
draw_pixel_line( 4, max_box_x, max_box_y, min_box_x, max_box_y );
draw_pixel_line( 4, max_box_x, max_box_y, max_box_x, min_box_y );
draw_pixel_line( 4, min_box_x, min_box_y, max_box_x, min_box_y );
draw_pixel_line( 4, min_box_x, min_box_y, min_box_x, max_box_y );
}
} // find dark square box
// expand the box around the symbol by 25 %
// may not be necessary...
void expand_dark_box25()
{
int x_length;
int y_length;
int new_x_len;
int new_y_len;
int new_min_x;
int new_min_y;
int new_max_x;
int new_max_y;
x_length = max_box_x - min_box_x;
if ( x_length < ( MAX_X_PIXEL / 50) )
{
printf("Symbol too small or missing \n");
}
y_length = max_box_y - min_box_y;
if ( y_length < ( MAX_Y_PIXEL / 50) )
{
printf("Symbol too small or missing \n");
}
// expand by 25%
new_x_len = x_length + (x_length / 4);
new_y_len = y_length + (y_length / 4);
new_min_x = max_box_x - ( x_length / 2 ) - new_x_len;
new_min_y = max_box_y - ( y_length / 2 ) - new_y_len;
if ( new_min_x > 0)
{
new_max_x = new_min_x + new_x_len;
}
if ( new_min_y > 0)
{
new_max_y = new_min_y + new_y_len;
}
if ( new_min_x < 0)
{
// could try to expand by 10 % here
new_min_x = min_box_x;
}
if ( new_min_y < 0)
{
// could try to expand by 10 % here
new_min_y = min_box_y;
}
if ( new_max_x > MAX_X_PIXEL)
{
// could try to expand by 10 % here
new_max_x = max_box_x;
}
if ( new_min_y > MAX_Y_PIXEL)
{
// could try to expand by 10 % here
new_max_y = max_box_y;
}
b_box_maxx = new_max_x;
b_box_maxy = new_max_y;
b_box_minx = new_min_x;
b_box_miny = new_min_y;
b_box_xlen = ( b_box_maxx - b_box_minx);
b_box_ylen = ( b_box_maxy - b_box_miny);
}
void get_box_len()
{
int x_length;
int y_length;
int new_x_len;
int new_y_len;
int new_min_x;
int new_min_y;
int new_max_x;
int new_max_y;
int debug;
debug = 0;
x_length = max_box_x - min_box_x;
if ( x_length < ( MAX_X_PIXEL / 50) )
{
printf("Symbol too small or missing \n");
}
y_length = max_box_y - min_box_y;
if ( y_length < ( MAX_Y_PIXEL / 50) )
{
printf("Symbol too small or missing \n");
}
new_x_len = x_length ;
new_y_len = y_length ;
new_min_x = min_box_x;
new_min_y = min_box_y;
new_max_x = max_box_x;
new_max_y = max_box_y;
b_box_maxx = new_max_x;
b_box_maxy = new_max_y;
b_box_minx = new_min_x - (x_length / 20);
if ( b_box_minx < (min_box_x / 2))
{
b_box_minx = (min_box_x / 2);
}
b_box_miny = new_min_y;
b_box_xlen = ( b_box_maxx - b_box_minx);
b_box_ylen = ( b_box_maxy - b_box_miny);
if (debug)
{
printf("End get_box_length \n");
}
}
// get 3 points on the left edge of the bounding box
// one at upper left
// one at center
// one at bottom left
// use these as starting points for the line scan
//
void get_scan_points()
{
int debug;
debug = 0;
scan_upleft_x = b_box_minx;
scan_upleft_y = b_box_maxy;
scan_cenleft_x = b_box_minx;
scan_cenleft_y = b_box_maxy - (b_box_ylen/2);
scan_lowleft_x = b_box_minx;
scan_lowleft_y = b_box_miny;
if (debug) { printf(" In scan points upper left = %d %d \n",
scan_upleft_x, scan_upleft_y);
printf(" In scan points center left = %d %d \n",
scan_cenleft_x, scan_cenleft_y);
printf(" In scan points lower left = %d %d \n",
scan_lowleft_x, scan_lowleft_y);
}
}
void get_pixel(int inx, int iny)
{
if ( pixel_cnt < MAX_LINE_PIXEL)
{
line_data[pixel_cnt] = pixel_array[inx][iny].greyval;
line_x[pixel_cnt]= inx;
line_y[pixel_cnt]= iny;
pixel_cnt += 1;
}
else
{
printf("Too many pixels in this line \n");
}
}
// get pixel used when taking the normal to the line
//
void get_pixel_norm(int inx, int iny)
{
int debug;
debug = 0;
if ( pixel_cnt < MAX_LINE_PIXEL)
{
norm_line_data[pixel_cnt] = pixel_array[inx][iny].greyval;
normal_x[pixel_cnt] = inx;
normal_y[pixel_cnt] = iny;
if (debug)
{
if ( pixel_cnt == 0)
{
if (debug ) {
printf("at 0 normal_x , normal_y = %d %d \n", normal_x[0],
normal_y[0]);
}
}
}
pixel_cnt += 1;
}
}
// get pixel used when taking a line from the pix_out data
// for final processing
//
void get_pixel_post(int inx, int iny)
{
int debug;
debug = 0;
if ( post_pixel_cnt < MAX_LINE_PIXEL)
{
if ( ( inx > 0 ) && ( iny > 0))
{
if ( ( inx < pixel_out_xlen ) && ( iny < pixel_out_ylen))
{
post_line_data[post_pixel_cnt] = pix_out[inx][iny].greyval;
post_x[post_pixel_cnt] = inx;
post_y[post_pixel_cnt] = iny;
}
else
{
post_line_data[post_pixel_cnt] = 0;
}
}
else
{
post_line_data[post_pixel_cnt] = 0;
post_x[post_pixel_cnt] = -1;
post_y[post_pixel_cnt] = -1;
}
if (debug)
{
if ( post_pixel_cnt == 0)
{
printf("at 0 post_x , post_y = %d %d \n", post_x[0],
post_y[0]);
}
}
post_pixel_cnt += 1;
}
}
void save_line()
{
int jj;
if ( save_line_cnt < MAX_LINE_SCANS )
{
save_line_data[save_line_cnt].pixelcnt = pixel_cnt;
save_line_data[save_line_cnt].has_8111 = FALSE;
save_line_data[save_line_cnt].has_7111 = FALSE;
save_line_data[save_line_cnt].slope = slope;
save_line_data[save_line_cnt].dir = dir;
for ( jj= 0; jj < pixel_cnt; jj += 1)
{
save_line_data[save_line_cnt].line_vals[jj]= line_data[jj];
// printf("line_data,jj=%d = %d \n",jj,line_data[jj]);
save_line_data[save_line_cnt].line_x[jj] = line_x[jj];
save_line_data[save_line_cnt].line_y[jj] = line_y[jj];
}
}
else
{
printf("Internal error: Too many left probe lines = %d\n", save_line_cnt);
printf("Allowed max = %d \n",MAX_LINE_SCANS);
}
}
void skip_underthress()
{
while(( line_data[lpixel] < line_threshold ) && ( lpixel < pixel_cnt))
{
lpixel += 1;
barwidth += 1;
}
}
// called by analyzer module , used to get the bar
// widths in the module using the best xlines in
// the column
int get_mod_xline(int yval, int rowin , int colin)
{
int good_space;
int kk;
int debug;
int mid_point;
int bit_int;
int space_min;
int space_max;
int bit[20];
int this_mod_index;
debug = 0;
good_space = TRUE;
space_min = (best_onewidth * 3 ) / 4;
space_max = (( int)( best_onewf * 6)) / 4;
bit[0] = 0;
for ( kk = 1; kk < vert_line_cnt; kk += 1)
{
bit[kk] = 0;
if ( (pix_col_xline[kk] - pix_col_xline[kk-1]) < space_min)
{
good_space = FALSE;
if (debug) { printf("Good space failed : too narrow \n"); }
}
if ( (pix_col_xline[kk] - pix_col_xline[kk-1]) > space_max)
{
good_space = FALSE;
if (debug) { printf("Good space failed : too wide\n"); }
}
if ( debug)
{
printf("kk = %d pix_col_xline[kk] = %d \n", kk, pix_col_xline[kk]);
}
}
xline_mod_index = -1;
this_mod_index = -1;
if (( vert_line_cnt > 15) && ( good_space == TRUE))
{
for ( kk = 0; kk < vert_line_cnt ; kk += 1)
{
if ( kk > 0)
{
mid_point = ( pix_col_xline[kk] + pix_col_xline[kk-1] ) / 2;
}
else
{
mid_point = pix_col_xline[kk] / 2;
}
bit[kk] = test_black( mid_point, yval ,1);
if (debug)
{
printf("mid_point = %d yval = %d kk = %d \n",
mid_point, yval, kk );
}
}
bit_int = bits_to_symbol( bit );
if (debug) { printf("xline bit_int = %x \n", bit_int); }
this_mod_index = find_index(bit_int,2, rowin, colin);
if ( this_mod_index != -1 )
{
if (debug) { printf("This mod index = %d \n", this_mod_index); }
xline_mod_index = this_mod_index;
return(0);
}
else
{
return(-1);
}
}
else
{
return(-1);
}
}
// called by analyzer module , used to get the bar
// widths in the module
void get_mod_bar(int in_row, int in_col )
{
int mbarwidth;
int debug;
debug = 0;
if ( debug) { printf("In get_mod_bar \n"); }
mbarwidth = 0;
if ( mod_bar_cnt < MAX_MOD_BARS)
{
mod_bar_array[mod_bar_cnt].beginx = mod_line_x[lpixel];
mod_bar_array[mod_bar_cnt].lpixel = lpixel;
}
while(( mod_line_data[lpixel] > line_threshold ) && ( lpixel < mod_pixel_cnt))
{
lpixel += 1;
mbarwidth += 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -