/* * ***************************************************************** * * * * * Copyright (c) Fast Corporation, 1997 * * * * * * All Rights Reserved. Unpublished rights reserved under * * * the copyright laws of the Japan. * * * * * * The software contained on this media is proprietary to * * * and embodies the confidential technology of Fast * * * Corporation. Possession, use, duplication or * * * dissemination of the software and media is authorized only * * * pursuant to a valid written license from Fast Corporation. * * * * * ***************************************************************** */ /* CSC90X プロジェクションによるトンボマーク中心計測 PRJTOMBO.C */ /*[作成者]H.Yagi */ /* 目的: 関数: 履歴: Ver 1.0 97/08/29 注記:m_menu.h,xx.hをインクルードして下さい。 m_menu.c,m_note.c,xxcomm.c,xxgraph.c,xxedge.cをリンクして下さい。 */ /* * Include compiler runtime library */ #include #include /* * Include CSC90X library */ #include "f_stdlib.h" #include "f_time.h" #include "f_gui.h" #include "f_stdio.h" #include "f_graph.h" #include "f_image.h" #include "f_pinf.h" #include "f_video.h" #include "f_system.h" #include "f_gray.h" #include "f_filter.h" #include "f_file.h" #include "f_em.h" #include "xx.h" /* * Include CSC90X common local */ #include "m_menu.h" /* * プロトタイプ宣言 */ void main( void ); void main_menu_disp( void ); void disp_help( void ); void set( void ); void pdm_wind_set( int, int, int, PARADIGM * ); void pdm_set_file_name( int, int, PARADIGM * ); void exec( void ); void bibun( int *, int *, int ); void pause( void ); int tonbo_xy( int, int, int, int, int *, int *, int, double *, double * ); void pre_proc( int ); void set_file( void ); void cut_space( char *, char * ); void fs0_freeze( int ); extern int message_note( void ); /* * メニュー項目 */ #define LANG_N 2 #define MAIN_MENU_N 4 static const char *str_main_menu[MAIN_MENU_N][LANG_N] = { { " SET ", " 設 定 " }, { " EXEC ", " 実 行 " }, { " PROC3 ", " 処理3 " }, { " PROC4 ", " 処理4 " } }; #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 typedef struct { int xs; /* X始点 */ int ys; /* Y始点 */ int xe; /* X終点 */ int ye; /* Y終点 */ } WIND_T; typedef enum { DIRECTION_XY, DIRECTION_X, DIRECTION_Y } dummy1; #define CAMERA 2 #define FILENAME_SAIZE 12 char grayfile[FILENAME_SAIZE+1]; int pad_level; static PVAL value[10]; static char ss[70]; int mem_no; WIND_T wind; /*処理範囲 */ int direction; /*処理方向 */ int ave_cnt; /*平均回数 */ int diff_p; /*微分しきい値 */ int level_p; /*濃度しきい値 */ int wave_onoff; /*波形表示フラグ*/ int fs0_image; /*FS0入力画像スイッチ*/ /* * メイン */ void main( void ) { int sts; int xpos; int ypos; int s_xpos; int s_ypos; int i; /* 初期メッセージ表示 */ if( NORMAL_RETURN != message_note() ) return; /* パラメタ初期化 */ xpos = INIT_CUR_POS_X; ypos = INIT_CUR_POS_Y; s_xpos = INIT_CUR_POS_X; s_ypos = INIT_CUR_POS_Y; for ( i=0; i MENU_1_XS && xpos < MENU_1_XE && ypos > MENU_1_YS && ypos < MENU_1_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); set( ); /* 設定 */ main_menu_disp(); } else if ( xpos > MENU_2_XS && xpos < MENU_2_XE && ypos > MENU_2_YS && ypos < MENU_2_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); exec( ); /* 実行 */ main_menu_disp(); } else if ( xpos > MENU_H_XS && xpos < MENU_H_XE && ypos > MENU_H_YS && ypos < MENU_H_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); disp_help(); /* ヘルプ */ main_menu_disp(); } else if ( xpos > MENU_E_XS && xpos < MENU_E_XE && ypos > MENU_E_YS && ypos < MENU_E_YE ) { break; /* 終了 */ } } } Lib_free_gray_memory( mem_no ); } /* * メインメニュー表示 */ static void main_menu_disp( void ) { int iLanguage; /* 日本語/英語表示文字列切替情報取得 */ iLanguage = Lib_get_disp_language(); /* 整列キー表示 -> ( m_menu.c ) */ SUB_menu_disp4he( (char *)str_main_menu[0][iLanguage], (char *)str_main_menu[1][iLanguage], (char *)NULL, (char *)NULL ); } /* * ヘルプ表示 */ static void disp_help( void ) { Lib_chrdisp( 10, 8, "【機能\概要】 PRJTOMBO" ); Lib_chrdisp( 11, 10, "処理ウインド内プロジェクションによる" ); Lib_chrdisp( 11, 12, "トンボ中心計測サンプル。" ); Lib_chrdisp( 11, 14, "任意に固定画像(FS0)入力も可能\です。" ); } /************************************************************************/ /* 設定          */ /************************************************************************/ static char *select_direction[3] = { "XY方向", "X方向 ", "Y方向 " }; void set( ) { int no, i; pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "設定" ); value[1].select_type = direction; value[2].value_type = ave_cnt; value[4].value_type = ( long )diff_p; value[5].value_type = ( long )level_p; value[6].on_off_type = wave_onoff; value[7].on_off_type = fs0_image; i = 0; Lib_view_set_null ( pad_level, 5, 5, "処理範囲" , i ); i++; Lib_view_set_select ( pad_level, 5, 35, "処理方向", value[i].select_type, 3, select_direction, i ); i++; Lib_view_set_uniq_numeral( pad_level, 5, 65, "平均回数", value[i].value_type, 0, 3, i ); i++; Lib_view_set_comment ( pad_level, 5, 100 ,"エッジ検出パラメータ", i ); i++; Lib_view_set_uniq_numeral( pad_level, 10, 130, "微分しきい値", value[i].value_type, 1, 99, i ); i++; Lib_view_set_uniq_numeral( pad_level, 10, 160, "濃度しきい値", value[i].value_type, 1, 99, i ); i++; Lib_view_set_uniq_alter ( pad_level, 5, 195, "波形表\示", value[i].on_off_type, i ); i++; Lib_view_set_uniq_alter ( pad_level, 5, 225, "FS0画像", value[i].on_off_type, i ); i++; Lib_set_xparadigm( pad_level, 0, START_TIMING, pdm_wind_set ); Lib_set_paradigm( pad_level, 7, END_TIMING, pdm_set_file_name ); Lib_view_set_size( pad_level, 50, 50, 50, 5 ); Lib_draw_menu( pad_level ); if( ERROR_RETURN != ( no = Lib_process_menu( pad_level, value ) ) ) { if ( PAD_EXECUTE == no ) { direction = value[1].select_type; ave_cnt = value[2].value_type; diff_p = value[4].value_type; level_p = value[5].value_type; wave_onoff = value[6].on_off_type; fs0_image = value[7].on_off_type; } } else { Lib_chrdisp( 1, 28, "pad_meas err" ); } Lib_erase_menu( pad_level ); Lib_view_close( pad_level ); } /*********************************************************************/ /* ウインド設定制御                         */ /*********************************************************************/ void pdm_wind_set( Menu_no, Timing, Numb, val ) int Menu_no; int Timing; int Numb; PARADIGM val[]; { if ( ON == value[7].on_off_type ) fs0_freeze( TRANSMIT ); else Lib_freerun(); XXwind_set( &wind.xs, &wind.ys, &wind.xe, &wind.ye ); } /*********************************************************************/ /*  ファイル名設定                       */ /*********************************************************************/ void pdm_set_file_name( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { if ( ON == value[7].on_off_type ) Lib_get_string_by_keyboad( 50, 100, 12, grayfile ); } /************************************************************************/ /* 実行          */ /************************************************************************/ void exec( ) { register int i, a; int rtn; int windx; int windy; static long sumx[480]; static long sumy[512]; static int avex[480]; static int avey[512]; static struct _prjinfo prj; int sta, end; static int shaei[513]; static int s_shaei; double cx, cy; /**/Lib_strtclk_count(); /*タイマーカウントモードのスタート*/ Lib_box( wind.xs, wind.ys, wind.xe, wind.ye, SOLID_LINE ); windx = wind.xe - wind.xs + 1; /* ウィンド枠内x画素数 */ windy = wind.ye - wind.ys + 1; /* ウィンド枠内y画素数 */ if ( OFF == fs0_image ) Lib_freeze( TRANSMIT ); else fs0_freeze( TRANSMIT ); pre_proc( ave_cnt ); /*前処理*/ Lib_xvideo_transmit( 0, GRAY_PLANE ); Lib_window( wind.xs, wind.ys, wind.xe, wind.ye ); /*プロジェクション範囲*/ if ( DIRECTION_XY == direction ) Lib_projection( 0, sumx, sumy, &prj, OFF ); /*プロジェクション(X&Y)*/ else if ( DIRECTION_X == direction ) Lib_projection( 0, NULL, sumy, &prj, OFF ); /*プロジェクション(X)*/ else if ( DIRECTION_Y == direction ) Lib_projection( 0, sumx, NULL, &prj, OFF ); /*プロジェクション(Y)*/ /*平均化*/ if ( DIRECTION_Y != direction ) { for ( i=0, a=wind.xs; i sta ) { Lib_drawline( i-1, s_shaei, i, shaei[a] ); } s_shaei = shaei[a]; } } } if ( DIRECTION_X != direction ) { for ( i=0, a=wind.ys; i sta ) { Lib_drawline( s_shaei, i-1, shaei[a], i ); } s_shaei = shaei[a]; } } } if ( ON == wave_onoff ) pause(); rtn = tonbo_xy( wind.xs, wind.ys, wind.xe, wind.ye, avey, avex, direction, &cx, &cy ); if ( ERROR_RETURN == rtn ) Lib_chrdisp( 1, 30, "エッジ検出エラー" ); else { if ( DIRECTION_XY == direction ) Lib_sprintf( ss, "トンボ中心( %.1lf, %.1lf )", cx, cy ); else if ( DIRECTION_X == direction ) Lib_sprintf( ss, "トンボ中心( %.1lf, ---- )", cx ); else if ( DIRECTION_Y == direction ) Lib_sprintf( ss, "トンボ中心( ----, %.1lf )", cy ); Lib_chrdisp( 1, 26, ss ); if ( OFF == wave_onoff ) Lib_time_disp( 0, 452 ); } Lib_display_keyinput( 460, 0, "確認" ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_window( 0, 0, 511, 479 ); if ( OFF == fs0_image ) Lib_freerun(); } /************************************************************************/ /* 画面停止          */ /************************************************************************/ void pause() { Lib_display_keyinput( 430, 0, " 確認 " ); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_box( wind.xs, wind.ys, wind.xe, wind.ye, SOLID_LINE ); } /************************************************************************/ /* tonboの中心取得 */ /************************************************************************/ int tonbo_xy( xs, ys, xe, ye, avey, avex, direction, cx, cy ) int xs, ys, xe, ye; int *avey, *avex; int direction; double *cx, *cy; { int status; static int i; unsigned char *base; unsigned char *wbase; unsigned char *p1; int windx; int windy; EM_INSPECTION *inspection; /*エッジ測定結果格納EM_INSPECTION型構造体ポインタ*/ EM_EDGE_INFO *edge_info; /*エッジ測定結果格納EM_EDGE_INFO型構造体ポインタ */ static double da, db; int x, y; int dx_size; dx_size = Lib_get_dx_size(); windx = xe - xs + 1; /* ウィンド枠内x画素数 */ windy = ye - ys + 1; /* ウィンド枠内y画素数 */ base = (void *)Lib_adrs_gray_memory( 0 ); wbase = base + ys * dx_size + xs; if ( DIRECTION_Y != direction ) { /*中心x計測*/ p1 = wbase; for ( i=0; inum ) { da = (double)edge_info->upx[0] / 16.0; db = (double)edge_info->downx[0] / 16.0; *cx = ( da + db ) / 2.0; x = XXd4i5_d( *cx ); Lib_drawline( x, 0, x, 479 ); status = NORMAL_RETURN; } else status = ERROR_RETURN; } if ( ERROR_RETURN != status ) { if ( DIRECTION_X != direction ) { /*中心y計測*/ p1 = wbase; for ( i=0; inum ) { da = (double)edge_info->upy[0] / 16.0; db = (double)edge_info->downy[0] / 16.0; *cy = ( da + db ) / 2.0; y = XXd4i5_d( *cy ); Lib_drawline( 0, y, 511, y ); } else status = ERROR_RETURN; } } return( status ); } /************************************************************************/ /* 前処理 */ /************************************************************************/ void pre_proc( count ) int count; { int i; for ( i=0; i