/* * ***************************************************************** * * * * * Copyright (c) Fast Corporation, 2001 * * * * * * 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 偏心計測 HENSHIN.C */ /*[作成者]H.Yagi */ /* 目的: 関数: 履歴: Ver 1.0 98/10/15     Ver 1.1 01/10/12 求めた2円の中心に番号(1,2)を付与。 エッジ検出しきい値設定時、エッジ検出も行うよう変更。 注記: m_menu.h、xx.hをインクルードして下さい。 m_menu.c、m_note.c、xxcomm.c、xxgraph.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_math.h" #include "f_filter.h" #include "f_calip.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_set_cir_cnt( int, int, int, PARADIGM * ); void pdm_set_circle( int, int, PARADIGM * ); void pdm_edge( int, int, PARADIGM * ); void exec( void ); void exec_cir( int, int, int, int, int, int, double *, double *, double * ); int d4i5_d( double ); 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 EXECUTE 1 /* トラックボール EXECUTE キー */ #define CANCEL 2 /* トラックボール CANCEL キー */ #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 #define MAX_EDGE_LINE 16 #define CIRCLE_NO 2 int pad_level; int pad_level_cir; static PVAL value[5]; static PVAL value_cir[10]; static char ss[70]; int cx[CIRCLE_NO], cy[CIRCLE_NO], cr[CIRCLE_NO]; int henshin_shikii; int cir_idx; int edge_line_no[CIRCLE_NO]; int direction[CIRCLE_NO]; int thresh[CIRCLE_NO]; int gray_mem_no; int pre_code; /* * メイン */ 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; cir_idx = 0; 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(); /*設定*/ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); 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_clp_close( ); /*キャリパクローズ*/ Lib_free_gray_memory( gray_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, "【機能\概要】 HENSHIN" ); Lib_chrdisp( 11, 10, "放射状エッジ検出にて2円の中心座標を求め、" ); Lib_chrdisp( 11, 12, "偏心計測します。" ); } /**************************************************************/ /* 設定 */ /**************************************************************/ static char *select_pre_code[7] = { "なし     ", "平均     ", "ソ\ーベル   ", "最大値    ", "最小値    ", "ロバーツ   ", "鮮鋭化    " }; void set() { int no; int i; Lib_set_pad_maxstring( 14 ); /*パッド表示文字数変更*/ pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "設定" ); value[2].select_type = pre_code; value[3].value_type = ( long )henshin_shikii; i = 0; Lib_view_set_null ( pad_level, 5, 5, "円1設定", i ); i++; Lib_view_set_null ( pad_level, 5, 35, "円2設定", i ); i++; Lib_view_set_select( pad_level, 5, 65, "前処理" , value[i].select_type, 7, select_pre_code, i ); i++; Lib_view_set_uniq_numeral( pad_level, 5, 95, "許容偏心(pix)", value[i].value_type, 0L, 200L, i ); i++; Lib_set_xparadigm( pad_level, 0, START_TIMING, pdm_set_cir_cnt ); Lib_set_xparadigm( pad_level, 1, START_TIMING, pdm_set_cir_cnt ); Lib_view_set_size( pad_level, 50, 80, 5, 5 ); Lib_draw_menu( pad_level ); no = Lib_process_menu( pad_level, value ); if ( PAD_EXECUTE == no ) { pre_code = value[2].select_type; henshin_shikii = ( int )value[3].value_type; } Lib_erase_menu( pad_level ); Lib_view_close( pad_level ); Lib_set_pad_maxstring( 10 ); /*パッド表示文字数変更*/ Lib_freerun(); } /**************************************************************/ /* 放射状エッジ検出設定 */ /**************************************************************/ static char *select_direc[2] = { "中心→円周", "円周→中心" }; static void pdm_set_cir_cnt( menu_no, Timing, Numb, val ) int menu_no; int Timing; int Numb; PARADIGM val[]; { int i; int no; Lib_erase_menu( pad_level ); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); cir_idx = menu_no; pad_level_cir = Lib_view_open(); Lib_view_set_title( pad_level_cir, "設定" ); value_cir[1].value_type = ( long )edge_line_no[menu_no]; value_cir[2].select_type = direction[menu_no]; value_cir[3].value_type = ( long )thresh[menu_no]; i = 0; Lib_view_set_null ( pad_level_cir, 5, 5, "円設定" , i ); i++; Lib_view_set_uniq_numeral( pad_level_cir, 5, 35, "検出ライン数", value_cir[i].value_type, 3, MAX_EDGE_LINE, i ); i++; Lib_view_set_select ( pad_level_cir, 5, 65, "方向" , value_cir[i].select_type, 2, select_direc, i ); i++; Lib_view_set_uniq_numeral( pad_level_cir, 5, 95, "しきい値" , value_cir[i].value_type, -1, 255, i ); i++; Lib_set_paradigm( pad_level_cir, 0, START_TIMING, pdm_set_circle ); Lib_set_paradigm( pad_level_cir, 3, WHOLE_TIMING, pdm_edge ); Lib_view_set_size( pad_level_cir, 50, 50, 5, 5 ); Lib_draw_menu( pad_level_cir ); /* 設定値の読みとり */ if ( ERROR_RETURN != ( no = Lib_process_menu( pad_level_cir, value_cir ) ) ) { if ( PAD_EXECUTE == no ) { edge_line_no[menu_no] = ( int )value_cir[1].value_type; direction[menu_no] = value_cir[2].select_type; thresh[menu_no] = ( int )value_cir[3].value_type; } } Lib_erase_menu( pad_level_cir ); Lib_view_close( pad_level_cir ); Lib_draw_menu( pad_level ); } /*********************************************************************/ /* 円設定                         */ /*********************************************************************/ void pdm_set_circle( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { XXcircle_set2( &cx[cir_idx], &cy[cir_idx], &cr[cir_idx], ON ); } /*********************************************************************/ /* しきい値設定時のエッジ検出                    */ /*********************************************************************/ void pdm_edge( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { double dx, dy, dr; int x, y; if ( START_TIMING == Timing ) { Lib_erase_menu( pad_level_cir ); Lib_freeze( TRANSMIT ); if ( 0 == pre_code ) /*なし*/ /*NOP*/; else if ( 1 == pre_code ) Lib_averaging( 0, gray_mem_no ); /*平均*/ else if ( 2 == pre_code ) Lib_sobel( 0, gray_mem_no, XY_DIRECTION ); /*ソーベル XY*/ else if ( 3 == pre_code ) Lib_max_filter( 0, gray_mem_no ); /*最大値*/ else if ( 4 == pre_code ) Lib_min_filter( 0, gray_mem_no ); /*最小値*/ else if ( 5 == pre_code ) Lib_roberts( 0, gray_mem_no ); /*ロバーツ*/ else if ( 6 == pre_code ) Lib_sharp( 0, gray_mem_no ); /*鮮鋭化*/ if ( 0 != pre_code ) { Lib_xvideo_transmit( gray_mem_no, GRAY_PLANE ); Lib_change_gray_memory( gray_mem_no ); } } /*エッジ検出*/ Lib_memory_clear( LINE_PLANE ); exec_cir( cx[cir_idx], cy[cir_idx], cr[cir_idx], edge_line_no[cir_idx], direction[cir_idx], (int)val[0].long_type, &dx, &dy, &dr ); x = d4i5_d( dx ); y = d4i5_d( dy ); if ( END_TIMING == Timing ) { Lib_draw_menu( pad_level_cir ); Lib_freerun(); } } /*********************************************************************/ /* 実行                          */ /*********************************************************************/ void exec( ) { int i; double dx[CIRCLE_NO], dy[CIRCLE_NO], dr[CIRCLE_NO]; double distance; int x, y, r; /**/Lib_strtclk_count(); /*タイマーカウントモードのスタート*/ Lib_freeze( TRANSMIT ); if ( 0 == pre_code ) /*なし*/ /*NOP*/; else if ( 1 == pre_code ) Lib_averaging( 0, gray_mem_no ); /*平均*/ else if ( 2 == pre_code ) Lib_sobel( 0, gray_mem_no, XY_DIRECTION ); /*ソーベル XY*/ else if ( 3 == pre_code ) Lib_max_filter( 0, gray_mem_no ); /*最大値*/ else if ( 4 == pre_code ) Lib_min_filter( 0, gray_mem_no ); /*最小値*/ else if ( 5 == pre_code ) Lib_roberts( 0, gray_mem_no ); /*ロバーツ*/ else if ( 6 == pre_code ) Lib_sharp( 0, gray_mem_no ); /*鮮鋭化*/ if ( 0 != pre_code ) { Lib_xvideo_transmit( gray_mem_no, GRAY_PLANE ); Lib_change_gray_memory( gray_mem_no ); } for ( i=0; i= 0.0 ) out = (int)( in + 0.5 ); else out = (int)( in - 0.5 ); return( out ); }