/* * ***************************************************************** * * * * * 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 複数のBLOBをあたかも1つのBLOBとみなした時の重心 および外接長方形の4頂点座標計測 MEASANEX.C */ /*[作成者]S.Kodama, H.Yagi */ /* 目的: 関数: 履歴: Ver 1.0 99/08/25 注記:リンクモジュール M_MENU.OBJ M_NOTE.OBJ */ /* * 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_meas.h" #include "f_exmeas.h" /* * Include CSC90X common local */ #include "m_menu.h" /* * プロトタイプ宣言 */ void main( void ); void main_menu_disp( void ); void disp_help( void ); void bin_level_set( void ); void pdm_binlevel( int, int, PARADIGM * ); int d4i5_d( double ); void exec( void ); extern int message_note( void ); void L_lwcenter( int, int, struct MEASDATA *, int, int * ); /* * メニュー項目 */ #define LANG_N 2 #define MAIN_MENU_N 4 static const char *str_main_menu[MAIN_MENU_N][LANG_N] = { { " BIN ", " 2 値 " }, { "BIN LEVEL ", "2値レベル" }, { " EXEC ", " 試 行 " }, { " PROC4 ", " 処理4 " } }; #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 static struct MEASDATA *measp; static int *indextbl; static struct CALCDATA *calcultp; int pad_level; PVAL value[1]; static char ss[70]; int sts; int xs, ys, xe, ye; int time; int no; int bin_level; /* * メイン */ void main( void ) { int sts; int xpos; int ypos; int s_xpos; int s_ypos; /* 初期メッセージ表示 */ 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; bin_level = 128; /* 入力ビデオ制御 */ Lib_input_video_control( GRAY_PLANE ); /* ビデオ出力表示項目制御 */ Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); /* ビデオ表示項目クリア */ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); /* カーソル初期化 */ Lib_init_cursor(); /* メインメニューの表示 */ main_menu_disp(); /* マウスカーソルの表示 */ Lib_draw_cursor( INIT_CUR_POS_X, INIT_CUR_POS_Y ); /* システム構築対応1次特徴量計測処理オープン */ Lib_Open_meas_structure ( ); /* メニュー制御 */ for (;;) { sts = 0; /* マウス位置読みとり */ sts = Lib_see_current_position( &xpos, &ypos ); if ( s_xpos != xpos || s_ypos != ypos ) { /* マウス表示位置移動 */ Lib_move_cursor( xpos, ypos ); s_xpos = xpos; s_ypos = ypos; } /* 処理振り分け */ if( CURSOR_EXECUTE == sts ) { if ( xpos > MENU_1_XS && xpos < MENU_1_XE && ypos > MENU_1_YS && ypos < MENU_1_YE ) { Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_system_process( BINARY_MENU ); /*システム2値パッド*/ 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 ); bin_level_set(); /*2値レベル設定*/ main_menu_disp(); } else if ( xpos > MENU_3_XS && xpos < MENU_3_XE && ypos > MENU_3_YS && ypos < MENU_3_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; /* 終了 */ } } } } /* * メインメニュー表示 */ 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 *)str_main_menu[2][iLanguage], (char *)NULL ); } /* * ヘルプ表示 */ static void disp_help( void ) { Lib_chrdisp( 10, 8, "【機能\概要】 MEASANEX" ); Lib_chrdisp( 11, 10, "複数のBLOBをあたかも1つのBLOBとみなし" ); Lib_chrdisp( 11, 12, "た時の重心および外接長方形の4頂点座標を計測し" ); Lib_chrdisp( 11, 14, "ます。" ); Lib_chrdisp( 11, 16, "(システム構\築対応)" ); } /*********************************************************************/ /*  2値レベルセット                        */ /*********************************************************************/ void bin_level_set() { int i; int no; pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "設定" ); value[0].value_type = bin_level; i = 0; Lib_view_set_uniq_numeral( pad_level, 5, 5, "2値レベル", value[i].value_type, 0, 255, i ); i++; Lib_set_paradigm( pad_level, 0, WHOLE_TIMING, pdm_binlevel ); Lib_view_set_size( pad_level, 50, 80, 5, 5 ); Lib_draw_menu( pad_level ); /* 設定値の読みとり */ if ( ERROR_RETURN != ( no = Lib_process_menu( pad_level, value ) ) ) { if ( PAD_EXECUTE == no ) bin_level = value[0].value_type; } Lib_erase_menu( pad_level ); Lib_view_close( pad_level ); } /*********************************************************************/ /*  2値レベル設定                         */ /*********************************************************************/ void pdm_binlevel( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { if ( START_TIMING == Timing ) { Lib_erase_menu( pad_level ); Lib_input_video_control( BIN_PLANE ); Lib_display_control( BIN_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_memory_clear( BIN_PLANE ); } else if ( END_TIMING == Timing ) { Lib_input_video_control( GRAY_PLANE ); Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_draw_menu( pad_level ); } Lib_video_bin_level( (int)val[0].long_type ); Lib_freerun(); } /***********************************************************************/ /* 入力数値(double)の4捨5入した数値(int)を返す */ /***********************************************************************/ int d4i5_d( double in ) { int out; if ( in >= 0.0 ) out = (int)( in + 0.5 ); else out = (int)( in - 0.5 ); return( out ); } /*********************************************************************/ /* 試行                 */ /*********************************************************************/ void exec() { unsigned int max_blob; int i, a; int xs, ys, xe, ye; int ct; int blob; int center_x; int center_y; int color; int u_limit; int l_limit; double lw_px[4], lw_py[4]; unsigned short int *runnumb_indx, *runnumb_indx_limit, check_no; int no; int bno; int xpos[4], ypos[4]; int x[4], y[4]; /* システムで設定されている「最大ブローブ数」の値を取得し、indextblに必要な容量の */ /* ワークメモリを確保する */ max_blob = Lib_get_meas_max_blob(); if ( ( int * )NULL != ( indextbl = ( int * )Lib_mlalloc( ( max_blob + 1 ) * 4 ) ) ) { Lib_input_video_control( BIN_PLANE ); Lib_display_control( BIN_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_set_display_switch( 0 ); Lib_freeze( TRANSMIT ); bno = Lib_get_measure_no(); Lib_get_stage_window( &xs, &ys, &xe, &ye ); Lib_window( xs, ys, xe, ye ); color = Lib_get_meas_color(); /* メジャー計測色(0:黒,else:白) */ u_limit = Lib_get_meas_area_upper(); l_limit = Lib_get_meas_area_lower(); if ( 0 != Lib_measure( bno, &measp ) ) /* メジャー */ { Lib_chrdisp( 1, 30, "ERR! (Lib_measure)" ); Lib_set_display_switch( 1 ); Lib_input_video_control( GRAY_PLANE ); Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_window( 0, 0, 511, 479 ); Lib_freerun(); return; } else { /* システム構築対応1次特徴量アドレステーブル作成 */ Lib_Make_meas_structure ( (void *)measp ); ct = Lib_orderng( bno, measp, indextbl ); } Lib_memory_clear( BIN_PLANE ); Lib_freerun(); /******************************* コメント *********************************/ /* 複数のブローブをあたかも1つのブローブのようにに見せかけるためには各ブ */ /* ローブを一つに併合せねばなりません。よってこの処理以降、一次特徴量計測 */ /* データ格納テーブル内の1ブローブデータ分が壊れる(併合データに変わる) */ /* ことになるので留意しておいてください。 */ /* 今回の場合、併合する必要のあるデータは imin, imax, jmin, jmax, area, */ /* sumi, sumj, sumi2(+xsumi2), sumij(+xsumij), sumj2(+xsumj2), runnumb */ /* です。 */ /**************************************************************************/ /* 各ブローブを一つに併合。ここの例では indextbl に取り出された全ブローブ */ /* を最初に取り出されたブローブ(indextbl[0])に併合します。 */ /* これはあくまでも例ですから、別にどこのブローブを壊わしてもかまいません。*/ blob = indextbl[0]; /* 最初のBLOB番号を得る(ここに併合する) */ for( i = 1; i < ct; i++ ) { no = indextbl[i]; /* X・Yサイズ関係の併合 */ if( *( Meas_imin + blob ) > *( Meas_imin + no ) ) *( Meas_imin + blob ) = *( Meas_imin + no ); if( *( Meas_imax + blob ) < *( Meas_imax + no ) ) *( Meas_imax + blob ) = *( Meas_imax + no ); if( *( Meas_jmin + blob ) > *( Meas_jmin + no ) ) *( Meas_jmin + blob ) = *( Meas_jmin + no ); if( *( Meas_jmax + blob ) < *( Meas_jmax + no ) ) *( Meas_jmax + blob ) = *( Meas_jmax + no ); /* 1次モーメント関係の併合 */ *( Meas_sumi + blob ) += *( Meas_sumi + no ); *( Meas_sumj + blob ) += *( Meas_sumj + no ); *( Meas_area + blob ) += *( Meas_area + no ); /* 2次モーメント関係の併合 */ *( Meas_sumi2 + blob ) += *( Meas_sumi2 + no ); *( Meas_xsumi2 + blob ) += *( Meas_xsumi2 + no ); if( *( Meas_sumi2 + blob ) < *( Meas_sumi2 + no ) ) *( Meas_xsumi2 + blob ) += 1; *( Meas_sumij + blob ) += *( Meas_sumij + no ); *( Meas_xsumij + blob ) += *( Meas_xsumij + no ); if( *( Meas_sumij + blob ) < *( Meas_sumij + no ) ) *( Meas_xsumij + blob ) += 1; *( Meas_sumj2 + blob ) += *( Meas_sumj2 + no ); *( Meas_xsumj2 + blob ) += *( Meas_xsumj2 + no ); if( *( Meas_sumj2 + blob ) < *( Meas_sumj2 + no ) ) *( Meas_xsumj2 + blob ) += 1; /* 各ランレングス・データに付けられているブローブ番号を一つに併合 */ check_no = (unsigned short int)no; runnumb_indx = &( *( Meas_runnumb + *( Meas_rp + *( Meas_jmin + no )))); runnumb_indx_limit = &( *( Meas_runnumb + *( Meas_rp + *( Meas_jmax + no ) + 1 ))); while( runnumb_indx != runnumb_indx_limit ) { if( *runnumb_indx == check_no ) *runnumb_indx = blob; runnumb_indx++; } } Lib_calcult( 3, blob, &calcultp ); /*2次特徴量計算*/ /*** 外接長方形4頂点座標計測(注:事前に区分3にて2次特徴量計算を実行しておく事) ***/ Lib_BLOB_get_area_pos( xpos, ypos ); /*外接長方形4頂点座標参照*/ lw_px[0] = (double)xpos[0] / 10.0; /*外接長方形頂点1のX座標*/ lw_py[0] = (double)ypos[0] / 10.0; /*外接長方形頂点1のY座標*/ lw_px[1] = (double)xpos[1] / 10.0; /*外接長方形頂点2のX座標*/ lw_py[1] = (double)ypos[1] / 10.0; /*外接長方形頂点2のY座標*/ lw_px[2] = (double)xpos[2] / 10.0; /*外接長方形頂点3のX座標*/ lw_py[2] = (double)ypos[2] / 10.0; /*外接長方形頂点3のY座標*/ lw_px[3] = (double)xpos[3] / 10.0; /*外接長方形頂点4のX座標*/ lw_py[3] = (double)ypos[3] / 10.0; /*外接長方形頂点4のY座標*/ for ( a=0; a<4; a++ ) { x[a] = d4i5_d( lw_px[a] ); y[a] = d4i5_d( lw_py[a] ); Lib_drawcircle( x[a], y[a], 5 ); Lib_sprintf( ss, "%d", a+1 ); Lib_kanjishift( 0, 0, 0, x[a]+5, y[a]-5, ss ); } /*外接長方形表示*/ Lib_drawline( x[0], y[0], x[1], y[1] ); Lib_drawline( x[1], y[1], x[2], y[2] ); Lib_drawline( x[2], y[2], x[3], y[3] ); Lib_drawline( x[3], y[3], x[0], y[0] ); center_x = calcultp->centerx / 10; /* 重心x */ center_y = calcultp->centery / 10; /* 重心y */ Lib_drawline( center_x-5, center_y-5, center_x+5, center_y+5 ); Lib_drawline( center_x-5, center_y+5, center_x+5, center_y-5 ); Lib_sprintf( ss, "外接長方形頂点1のXY座標:%.1lf, %.1lf", lw_px[0], lw_py[0] ); Lib_chrdisp( 1, 7, ss ); Lib_sprintf( ss, "外接長方形頂点2のXY座標:%.1lf, %.1lf", lw_px[1], lw_py[1] ); Lib_chrdisp( 1, 8, ss ); Lib_sprintf( ss, "外接長方形頂点3のXY座標:%.1lf, %.1lf", lw_px[2], lw_py[2] ); Lib_chrdisp( 1, 9, ss ); Lib_sprintf( ss, "外接長方形頂点4のXY座標:%.1lf, %.1lf", lw_px[3], lw_py[3] ); Lib_chrdisp( 1, 10, ss ); /**/Lib_display_keyinput( 430, 0, " 確認 " ); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_set_display_switch( 1 ); Lib_input_video_control( GRAY_PLANE ); Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_window( 0, 0, 511, 479 ); Lib_freerun(); } else Lib_display_message( 100, 120, "エラー", "indextbl用のワークメモリを確保できません。" ); }