/* * ***************************************************************** * * * * * 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 粒度分布測定(2値画像計測による) RYUDBUNP.C */ /*[作成者]S.Kodama */ /* 目的: 関数: 履歴: Ver 1.0 97/11/10 Ver 1.1 99/03/26 ヘルプコメントに一覧表作成範囲の記述を追加 注記:m_menu.hをインクルードして下さい。 m_menu.c及びm_note.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_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 set( void ); void pdm_bin_level( int, int, PARADIGM * ); void pdm_set_bin( int, int, PARADIGM * ); void Sub_execute( void ); /* 計測実行 */ 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 #define DIVIDE 20 /* 分割数(最大28まで) */ /*----------------------------*/ /* 共用エリア(変数)  */ /*----------------------------*/ int pad_level; static PVAL value[2]; int bin_level; int pitch; static int min_area, max_area; static int area_step[ DIVIDE + 1 ]; /* * メイン */ 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; /* 入力ビデオ制御 */ 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 ); min_area = Lib_get_meas_area_lower(); max_area = Lib_get_meas_area_upper(); pitch = ( max_area - min_area ) / DIVIDE; area_step[0] = min_area; for( i = 1; i < DIVIDE; i++ ) area_step[i] = area_step[i-1] + pitch; area_step[DIVIDE] = max_area + 1; bin_level = 128; /* メニュー制御 */ 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 ); 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 ); Sub_execute( ); /*実行*/ Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); 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 *)NULL, (char *)NULL ); } /* * ヘルプ表示 */ static void disp_help( void ) { Lib_chrdisp( 10, 8, "【機能\概要】 RYUDBUNP" ); Lib_chrdisp( 11, 10, "<粒度分布測定(2値画像計測による)>" ); Lib_chrdisp( 11, 12, "2値メジャー計測により画面上の対象物を全て抽出" ); Lib_chrdisp( 11, 14, "後重心に+マークを表\示し、さらに面積ごとの分類" ); Lib_chrdisp( 11, 16, "表\を作り、例えば0〜99の面積範囲のものが何個、" ); Lib_chrdisp( 11, 18, "100〜199の面積範囲のものが何個、というような一" ); Lib_chrdisp( 11, 20, "覧表\を画面に表\示します。" ); Lib_chrdisp( 11, 22, "一覧表\は面積下限値〜面積上限値の範囲で作成し、" ); Lib_chrdisp( 11, 24, "分割数は20固定です。" ); } /* * 設定 */ void set( ) { int no; int i; pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "設定" ); Lib_view_set_uniq_numeral( pad_level, 5, 5, "2値レベル", bin_level, 0, 255, 0 ); Lib_view_set_null ( pad_level, 5, 35, "2 値" , 1 ); Lib_set_paradigm( pad_level, 0, WHOLE_TIMING, pdm_bin_level ); Lib_set_paradigm( pad_level, 1, START_TIMING, pdm_set_bin ); Lib_view_set_size( pad_level, 50, 50, 5, 5 ); Lib_draw_menu( pad_level ); if ( ERROR_RETURN != ( no = Lib_process_menu( pad_level, value ) ) ) /* メニュー値の取得 */ { switch( no ) { case 101: /*「実行」が選択された */ bin_level = value[0].value_type; break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level ); Lib_view_close( pad_level ); min_area = Lib_get_meas_area_lower(); max_area = Lib_get_meas_area_upper(); pitch = ( max_area - min_area ) / DIVIDE; area_step[0] = min_area; for( i = 1; i < DIVIDE; i++ ) area_step[i] = area_step[i-1] + pitch; area_step[DIVIDE] = max_area + 1; } /*********************************************************************/ /*  2値レベル設定                         */ /*********************************************************************/ void pdm_bin_level( 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 | BIN_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(); } /*********************************************************************/ /* 2値設定                        */ /*********************************************************************/ void pdm_set_bin( Timing, Numb, val ) int Timing; int Numb; PARADIGM val[]; { Lib_erase_menu( pad_level ); Lib_system_process( BINARY_MENU ); Lib_draw_menu( pad_level ); } /**************************************************************/ /**** 計測処理 ************************************************/ /**************************************************************/ void Sub_execute() { static struct MEASDATA *measp; static int *indextbl; unsigned int max_blob; char *error_string; int error_code; char chr_buff[64]; int i, j, x, y, no, time; int ct, blob; int area; int val[DIVIDE]; /* システムで設定されている「最大ブローブ数」の値を取得し、indextblに必要な容量の */ /* ワークメモリを確保する */ max_blob = Lib_get_meas_max_blob(); if ( ( int * )NULL != ( indextbl = ( int * )Lib_mlalloc( ( max_blob + 1 ) * 4 ) ) ) { /* 2値画像取り込み */ Lib_input_video_control( BIN_PLANE | GRAY_PLANE ); /* 2値画像入力とする */ Lib_display_control( BIN_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_strtclk_count(); /* 処理時間計測スタート */ Lib_video_bin_level( bin_level ); Lib_freeze( TRANSMIT ); /* 入力画像凍結 & モニタTVへ表示 */ no = Lib_get_measure_no(); /* システム構築対応1次特徴量計測処理オープン */ Lib_Open_meas_structure(); if ( NORMAL_RETURN == Lib_measure( no, &measp ) ) /* メジャー */ { /* BLOBエントリ番号取り出し */ if ( 0 < ( ct = Lib_orderng( no, measp, indextbl ) ) ) { /* システム構築対応1次特徴量アドレステーブル作成 */ Lib_Make_meas_structure ( (void *)measp ); for( i = 0; i < DIVIDE; i++ ) val[i] = 0; /* 各塊の面積・重心を抽出 */ for( i = 0; i < ct; i++ ) { blob = indextbl[i]; /* BLOB番号(ラベルNo.)を得る */ x = *(Meas_sumi + blob) / *(Meas_area + blob); /* 重心Xを計測 */ y = *(Meas_sumj + blob) / *(Meas_area + blob); /* 重心Yを計測 */ Lib_drawline( x - 2, y, x + 2, y ); /* 重心位置に+マークを表示する */ Lib_drawline( x, y - 2, x, y + 2 ); area = *(Meas_area + blob); for( j = 0; j < DIVIDE; j++ ) { if( area_step[j] <= area && area < area_step[j+1] ) { val[j] += 1; break; } } } /*一覧表の表示*/ Lib_chrdisp( 1, 1, "  面積範囲  個数" ); Lib_drawline( 0, 0, 0, 16 * DIVIDE + 32 ); Lib_drawline( 112, 0, 112, 16 * DIVIDE + 32 ); Lib_drawline( 144, 0, 144, 16 * DIVIDE + 32 ); for( i = 0; i < DIVIDE + 3; i++ ) Lib_drawline( 0, i * 16, 144, i * 16 ); for( i = 0; i < DIVIDE; i++ ) { Lib_sprintf( chr_buff, "%6d〜%6d", area_step[i], area_step[i+1] - 1 ); Lib_chrdisp( 1, i + 2, chr_buff ); Lib_sprintf( chr_buff, "%4d", val[i] ); Lib_chrdisp( 15, i + 2, chr_buff ); } Lib_sprintf( chr_buff, "合計%4d", ct ); Lib_chrdisp( 11, DIVIDE + 2, chr_buff ); time = ( Lib_readclk_count() * 8138 ) / 10000; Lib_sprintf( chr_buff, "処理時間=%dmsec", time ); Lib_chrdisp( 48, 1, chr_buff ); } else Lib_chrdisp( 1, 30, "エラー:ブローブがありません。" ); } else { error_code = Lib_get_meas_error_code(); error_string = Lib_get_meas_error_string(); Lib_sprintf( chr_buff, "2値計測エラー [%d] : %s", error_code, error_string ); Lib_chrdisp( 1, 30, chr_buff ); } } else Lib_chrdisp( 1, 30, "エラー:indextbl用のワークメモリを確保できません。" ); Lib_display_keyinput( 460, 450, "確認" ); Lib_input_video_control( GRAY_PLANE ); Lib_display_control( GRAY_PLANE|LINE_PLANE|CHAR_PLANE ); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_freerun(); }