/* * ***************************************************************** * * * * * 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値計測(システム構築対応) MEASHPNT.C */ /*[作成者]H.Yagi */ /* 目的: 関数: 履歴: Ver 1.0 97/08/27 Ver 2.0 01/12/21 ファイル内関数のプロトタイプにstaticを追加 注記: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 ); static void main_menu_disp( void ); static void disp_help( void ); static void bin_level_set( void ); static void pdm_binlevel( int, int, PARADIGM * ); static void exec( void ); static int blob_hole_paint( struct MEASDATA *, int, 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] = { { " BIN ", " 2 値 " }, { "BIN LEVEL ", "2値レベル" }, { " EXEC ", " 実 行 " }, { " PROC4 ", " 処理4 " } }; #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 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; /* 入力ビデオ制御 */ 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 ); 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, "【機能\概要】 MEASHPNT" ); Lib_chrdisp( 11, 10, "穴塗りつぶし後2値計測を行い各物体の重心・面積" ); Lib_chrdisp( 11, 12, "と物体の個数およびフェレ径を表\示します。" ); Lib_chrdisp( 11, 14, "2値計測はシステム構\築対応です。" ); } /*********************************************************************/ /*  2値レベルセット                        */ /*********************************************************************/ static 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値レベル設定                         */ /*********************************************************************/ static 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(); } /*********************************************************************/ /* 実行                 */ /*********************************************************************/ static 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 color; 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 ); Lib_video_bin_level( bin_level ); /* システムで設定されている「最大ブローブ数」の値を取得し、indextblに必要な容量の */ /* ワークメモリを確保する */ max_blob = Lib_get_meas_max_blob(); if ( ( int * )NULL != ( indextbl = ( int * )Lib_mlalloc( ( max_blob + 1 ) * 4 ) ) ) { Lib_strtclk_count(); /*タイマーカウントモードのスタート*/ Lib_freeze( TRANSMIT ); Lib_get_stage_window( &xs, &ys, &xe, &ye ); Lib_window( xs, ys, xe, ye ); no = Lib_get_measure_no(); color = Lib_get_meas_color(); /* メジャー計測色(0:黒,else:白) */ /* システム構築対応1次特徴量計測処理オープン */ Lib_Open_meas_structure(); /* 穴を塗りつぶすための一次特徴量計測 */ if ( NORMAL_RETURN == Lib_measure( no, &measp ) ) { if ( 0 < ( ct = Lib_orderng( no, measp, indextbl ) ) ) { for ( i = 0; i < ct; i++ ) { blobno = indextbl[i]; blob_hole_paint( measp, blobno, color ); /*穴の塗りつぶし*/ } Lib_xvideo_transmit( CURRENT_MEMORY, BIN_PLANE ); /* 穴を塗りつぶした対象物の一次特徴量計測 */ 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, "エラー:ブローブがありません。" ); } 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(); } /*********************************************************************/ /* 指定blobの全穴を塗りつぶす */ /*********************************************************************/ static int blob_hole_paint( measp, blobno, color ) struct MEASDATA *measp; /* メジャー構造体のベースアドレス */ int blobno; /* BLOB番号 */ int color; /* 塗りつぶし色 */ /* [関数値]:0:正常終了    −1:メジャー結果異常:ERROR_RETURN */ { int status; int child; status = ERROR_RETURN; /* システム構築対応1次特徴量アドレステーブル作成 */ Lib_Make_meas_structure ( (void *)measp ); if ( 2 >= *(Meas_bn) ) return ( status ); child = *(Meas_child + blobno); while ( -1 != child ) { Lib_blob_paint( measp, child, color, CURRENT_MEMORY ); /*塗りつぶし*/ child = *(Meas_sibling + child); } status = NORMAL_RETURN; return ( status ); }