/* * ***************************************************************** * * * * * 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値重心面積計測(FS0画像入力) MEASFS0.C */ /*[作成者]H.Yagi */ /* 目的: 関数: 履歴: Ver 1.0 97/08/27 Ver 2.0 00/04/21 システム構築対応 by A.Sekimori 注記: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 "f_gray.h" #include "f_file.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 * ); void exec( void ); void set_file( void ); void xxx_freeze( int ); void cut_space( char *, char * ); 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] = { { " BIN ", " 2 値 " }, { "BIN LEVEL ", "2値レベル" }, { " FILE ", " ファイル選択 " }, { " EXEC ", " 実 行 " } }; #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 #define FILENAME_SAIZE 12 char grayfile[FILENAME_SAIZE+1]; int pad_level; static char ss[70]; int sts; 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; strcpy( grayfile, "GRAYMEM1.DAT" ); /* 入力ビデオ制御 */ 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 ); /* メニュー制御 */ 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 ); set_file( ); /* ファイル名設定 */ main_menu_disp(); } else if ( xpos > MENU_4_XS && xpos < MENU_4_XE && ypos > MENU_4_YS && ypos < MENU_4_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 *)str_main_menu[3][iLanguage] ); } /* * ヘルプ表示 */ static void disp_help( void ) { Lib_chrdisp( 10, 8, "【機能\概要】 MEASFS0" ); Lib_chrdisp( 11, 10, "FS0よりロードした濃淡画像ファイルを2値化し" ); Lib_chrdisp( 11, 12, "2値計測を行います。各物体の重心、面積と物体の個数、" ); Lib_chrdisp( 11, 14, "フェレ径を表\示します。" ); Lib_chrdisp( 11, 16, "計測のパラメータはシステムのパッドを使用しています。" ); Lib_chrdisp( 11, 18, "2値計測はシステム構\築対応です。" ); } /*********************************************************************/ /*  2値レベルセット                        */ /*********************************************************************/ void bin_level_set() { PVAL value[1]; int no; 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_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_display_control( BIN_PLANE | LINE_PLANE | CHAR_PLANE ); xxx_freeze( NOT_TRANSMIT ); /* 画像LOAD */ } else if ( END_TIMING == Timing ) { Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_memory_clear( LINE_PLANE | CHAR_PLANE ); Lib_draw_menu( pad_level ); } Lib_binary_convert( 0, 0, (int)val[0].long_type ); Lib_xvideo_transmit( 0, BIN_PLANE ); /* モニタ表示 */ } /*********************************************************************/ /* 実行                 */ /*********************************************************************/ void exec( void ) { static struct MEASDATA *measp; static int *indextbl; unsigned int max_blob; char *error_string; int error_code; int i; int xs, ys, xe, ye; int fxs, fys, fxe, fye; int ct; int no; int blobno; int center_x; int center_y; int area; int sumi,sumj; Lib_input_video_control( BIN_PLANE ); Lib_display_control( BIN_PLANE | LINE_PLANE | CHAR_PLANE ); /* システムで設定されている「最大ブローブ数」の値を取得し、indextblに必要な容量の */ /* ワークメモリを確保する */ max_blob = Lib_get_meas_max_blob(); if ( ( int * )NULL != ( indextbl = ( int * )Lib_mlalloc( ( max_blob + 1 ) * 4 ) ) ) { Lib_strtclk_count(); /*タイマーカウントモードのスタート*/ xxx_freeze( TRANSMIT ); /* 画像LOAD */ Lib_get_stage_window( &xs, &ys, &xe, &ye ); Lib_window( xs, ys, xe, ye ); no = Lib_get_measure_no(); /* システム構築対応1次特徴量計測処理オープン */ Lib_Open_meas_structure(); if ( NORMAL_RETURN == Lib_measure( no, &measp ) ) /* メジャー */ { if ( 0 < ( ct = Lib_orderng( no, measp, indextbl ) ) ) { /* システム構築対応1次特徴量アドレステーブル作成 */ Lib_Make_meas_structure ( (void *)measp ); for ( i = 0; i < ct; i++ ) { blobno = indextbl[i]; /* 重心の計算 */ area = *( Meas_area + blobno ); sumi = *( Meas_sumi + blobno ); sumj = *( Meas_sumj + blobno ); center_x = sumi / area; /* 重心x */ center_y = sumj / area; /* 重心y */ /* フェレ経 */ fxs = *( Meas_imin + blobno ); fxe = *( Meas_imax + blobno ); fys = *( Meas_jmin + blobno ); fye = *( Meas_jmax + blobno ); Lib_box( fxs, fys, fxe, fye, SOLID_LINE ); Lib_drawline( center_x-2, center_y-2, center_x+2, center_y+2 ); Lib_drawline( center_x-2, center_y+2, center_x+2, center_y-2 ); Lib_sprintf( ss, "%d", area ); Lib_kanjishift( 0, 0, 0, center_x+5, center_y-5, ss ); } Lib_sprintf( ss, "個数:%d", ct ); Lib_chrdisp( 50, 30, ss ); Lib_time_disp( 0, 452 ); } else Lib_chrdisp( 1, 30, "エラー:ブローブがありません。" ); } else { error_code = Lib_get_meas_error_code(); error_string = Lib_get_meas_error_string(); Lib_sprintf( ss, "2値計測エラー [%d] : %s", error_code, error_string ); Lib_chrdisp( 1, 30, ss ); } } else Lib_chrdisp( 1, 30, "エラー:indextbl用のワークメモリを確保できません。" ); Lib_display_keyinput( 430, 0, " 確認 " ); Lib_input_video_control( GRAY_PLANE ); Lib_cls( ( BIN_PLANE | LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_window( 0, 0, 511, 479 ); Lib_freerun(); } /************************************************************************/ /* ファイル名設定 */ /************************************************************************/ void set_file( ) { int no; int pad_level_f; PVAL value[1]; pad_level_f = Lib_view_open(); Lib_view_set_title( pad_level_f, "ファイル設定" ); Lib_view_set_uniq_string ( pad_level_f, 5, 5, "GRAY FILE", grayfile, 12, 0 ); Lib_view_set_size( pad_level_f, 50, 80, 5, 5 ); Lib_draw_menu( pad_level_f ); if( ERROR_RETURN != ( no = Lib_process_menu( pad_level_f, value ) ) ) { switch( no ) { case 101: /*「実行」が選択された */ strcpy( grayfile, value[0].string_type ); break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level_f ); Lib_view_close( pad_level_f ); } /************************************************************************/ /* フリーズ */ /************************************************************************/ void xxx_freeze( flag ) int flag; /* バッファ転送フラグ */ { char wwstr[13]; char infile[20]; Lib_freeze( NOT_TRANSMIT ); Lib_chrdisp( 1, 30, "画像ロード中..." ); cut_space( grayfile, wwstr ); Lib_sprintf( infile, "\\FS0\\%s", wwstr ); if ( NORMAL_RETURN == Lib_load_gray_memory( CURRENT_MEMORY, infile ) ) { Lib_chrdisp( 1, 30, " " ); if ( ON == flag ) { Lib_binary_convert( 0, 0, bin_level ); Lib_xvideo_transmit( 0, BIN_PLANE ); /* モニタ表示 */ } } else { Lib_chrdisp( 1, 30, " " ); Lib_display_message( 70, 200, "fload_err", infile ); } } /*********************************************************************/ /* スペース除去                        */ /*********************************************************************/ void cut_space( instr, otstr ) char *instr; char *otstr; { for(;;) { if ( ' ' != *instr ) *otstr++ = *instr; if ( 0x00 == *instr ) break; instr++; } }