/* * ***************************************************************** * * * * * 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. * * * * * ***************************************************************** */ /* CSC902 高分解能エリアセンササンプル 902hr.c */ /*[作成者]A.Sekimori */ /* 目的: 関数: 履歴: Ver 1.0 98/07/22 Ver 2.0 99/02/10 画像メモリをファイルにセーブする機能 画像ファイルから入力する機能を追加 Ver 3.0 99/08/27 CS3910に対応 Ver 4.0 00/04/18 サーチ範囲設定時の不具合を修正 サーチ結果表示の不具合を修正 8bit版グレイサーチに変更 2値計測の処理範囲設定時の不具合を修正 画像ファイル保存/読み込み時の不具合を修正 注記:m_menu.hをインクルードして下さい。 m_menu.c及びm_note.cをリンクして下さい。 ○キャプチャボードIPM-8500Dを搭載した902シリーズでお使いになる場合は 902_hr2.lib ipm85lib.lib  をリンクしてください。 ○キャプチャボードFHC331、FHC331LVを搭載した902シリーズでお使いになる場合は 902_fhc.lib  をリンクしてください。 */ /* Include compiler runtime library */ #include #include /* Include CSC90X library */ #include "f_stdio.h" /* 標準入出力 */ #include "f_stdlib.h" /* メモリ領域割当 */ #include "f_file.h" /* ファイルシステム */ #include "f_gui.h" /* GUI */ #include "f_graph.h" /* モニタ表示 */ #include "f_pinf.h" /* システムパラメータ */ #include "f_video.h" /* ビデオ入力制御 */ #include "f_image.h" /* フレームバッファ */ #include "f_time.h" /* 時刻サービス */ #include "f_gray.h" /* 濃度変換 */ #include "f_bgray.h" /* 画像計測 */ #include "f_system.h" /* システム制御 */ #include "f_meas.h" /* 2値 */ #include "f_exmeas.h" /* 2値 */ #include "f_search.h" /* グレイサーチ */ #include "f_lsens.h" /* ラインセンサ */ #include "f_hres.h" /* 高分解能エリアセンサ */ /* * Include CSC90X common local */ #include "m_menu.h" /* * プロトタイプ宣言 */ void main( void ); void main_menu_disp( void ); void disp_help( void ); int alloc_ptn_area( void ); void high_res_camera_freeze( int, int ); void set_command_pad( void ); int select_camera( void ); void select_camera_control( void ); void set_bin_level( void ); void test_input_control( void ); void input_control( int ); void image_save_control( void ); int open_gray_memory( void ); void close_gray_memory( void ); void data_init( void ); void win_reset( void ); void bin_control( void ); void bin_menu( void ); void set_bin_param( void ); void set_bin_window( void ); void measure( void ); int result_disp_menu( int, int *, int * ); void gray_control( void ); void gray_menu( void ); void set_search_parm( void ); int mn_ptn_entry_control( void ); int mn_ptn_entry( void ); void mn_box_set_extract_mode( int *, int *, int *, int *, int ); void mn_box_draw_reduce_mode( int, int, int, int ); void disp_ptn( void ); void set_gs_window( void ); void search( void ); void move_disp_area( void ); void disp_mem_size( void ); void disp_area( void ); void mn_box_set_menu( int *, int *, int *, int *, int ); void image_file_load_gray( int, char *, int ); void image_file_load_bin( int, int, char *, int ); int image_file_save( int, char * ); void cut_space( char *, char * ); extern int message_note( void ); /* * メニュー項目 */ #define LANG_N 2 #define MAIN_MENU_N 3 static const char *str_main_menu[MAIN_MENU_N][LANG_N] = { { " SET ", " 入力設定 " }, { " GRAY ", " グレイ " }, { " BIN ", " 2 値 " } }; #define INIT_CUR_POS_X 255 #define INIT_CUR_POS_Y 239 #define EXECUTE 100 #define CANCEL 200 /* 表示メニュー */ #define D_KEY1_XS 1 /* キー「前頁」の表示位置(X) */ #define D_KEY_YS 455 /* キーの表示位置(Y) */ #define D_STR 8 /* キーの表示文字数 */ #define AR_MIN 0 #define CONTINUE 300 #define END 400 #define BL_MIN 0 #define BL_MAX 255 #define NUM_MIN 1 #define NUM_MAX 10 #define COM_MIN 1 #define COM_MAX 9 #define SCO_MIN 1000 #define SCO_MAX 9999 #define XS_MIN 0 #define YS_MIN 0 #define PTN_SIZE 102400 #define X_SIZE 1280 #define Y_SIZE 1030 /* パタン登録・メニュー */ #define PE_KEY1_XS 1 /* キー「移動」の表示位置(X) */ #define PE_KEY_YS 455 /* キーの表示位置(Y) */ #define PE_KEY_SIZE_Y 25 /* キーのサイズ(縦) */ #define PE_STR 8 /* キーの表示文字数 */ /* サーチウィンドウ設定メニュー */ #define EL_KEY1_XS 1 /* キー「移動」の表示位置(X) */ #define EL_KEY_YS 455 /* キーの表示位置(Y) */ #define EL_KEY_SIZE_Y 25 /* キーのサイズ(縦) */ #define EL_STR_NUM 8 /* キーの表示文字数 */ #define CAMERA 0 #define FILE 1 static char *camera_table[3] = { "FC1300 ", "KP-F100", "CS3910 " }; static char *input_table[2] = { "カメラ ", "ファイル" }; static char *disp_menu_key[5] = { " 前頁 ", " 次頁 ", " 前塊 ", " 次塊 ", " 終了 " }; static char *select_cl[2] = { "黒", "白" }; static char *select_bds[2] = { "切り出し", " 縮小 " }; static char *ptn_entry_menu_key[3] = { " 移 動 ", " 登 録 ", " 終 了 " }; static char *set_line_menu_key[3] = { " 移 動 ", " 設 定 ", " 終 了 " }; static char *select_c[3] = { "通常" , "高 " , "超高" }; static char *select_f[4] = { "高速", "黒線" , "白線" , "通常" }; typedef struct /* サーチ・パラメータ */ { char p_name[5]; /* パタン名称 */ int number; /* 個数 */ int mode; /* 精度 */ int complex; /* 複雑度 */ int mid_lower; /* 途中相関値 */ int last_lower; /* 最終相関値 */ int edge_detect; /* Wエッジ */ int x_step; /* ピッチX */ int y_step; /* ピッチY */ int filter; /* フィルター */ } SEARCH_P; typedef struct /* 処理範囲 */ { int xs; /* 始点X */ int ys; /* 始点Y */ int xe; /* 終点X */ int ye; /* 終点Y */ int x_size; /* 処理範囲サイズX */ int y_size; /* 処理範囲サイズY */ } WINDOW; typedef struct /* 2値計測 */ { int bin_level; /* 2値レベル */ int color; /* 対象物の色 */ int edge; /* ウィンドウ接触塊 */ int al_limit; /* 面積下限値 */ int au_limit; /* 面積上限値 */ int disp_sw; /* 結果表示モード */ } BIN_P; typedef struct /* 入力設定 */ { int type; /* カメラの種類 */ int input; /* 入力方法 */ char f_name[13]; /* 画像ファイル名 */ } IMAGE; SEARCH_P gsp; BIN_P bp; WINDOW gwin; WINDOW bwin; IMAGE img; int gray_mem_no; int gwrk_mem_no; int cpx,cpy; static struct MEASDATA *measp; static int *indextbl; static struct CALCDATA *calcp; static char *ptn_adr; /* メイン */ void main( void ) { int sts; int xpos; int ypos; int s_xpos; int s_ypos; int error; /* 初期メッセージ表示 */ if( NORMAL_RETURN != message_note() ) return; data_init(); select_camera(); if ( NORMAL_RETURN == ( error = Lib_high_res_init( img.type ) ) ) { if ( NORMAL_RETURN == open_gray_memory() ) { if ( NORMAL_RETURN == alloc_ptn_area() ) { /* パラメタ初期化 */ 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 ); /* メニュー制御 */ 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_command_pad(); 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 ); /* グレイが選択された */ gray_control(); Lib_memory_clear( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); 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 ); /* 2値が選択された */ bin_control(); Lib_memory_clear( BIN_PLANE | 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; /* 終了 */ } } } } close_gray_memory(); } else Lib_display_message( 120, 200, "エラー", "画像メモリが確保できません" ); Lib_high_res_finish(); } else if ( ARG_ERR == error ) Lib_display_message( 120, 200, "エラー", "カメラ種別が不明です。" ); else if ( UNUSUAL_ERR == error ) Lib_display_message( 120, 200, "エラー", "ボードまたは902の初期化に失敗しました。" ); else if ( NO_DEVICE == error ) Lib_display_message( 120, 200, "エラー", "ボードが存在していません。" ); Lib_lfree( ptn_adr ); } /* メインメニュー表示 */ 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 ); } /* ヘルプ表示 */ void disp_help( void ) { Lib_chrdisp( 6, 8, "【機能\概要】 902HR.EXE" ); Lib_chrdisp( 7, 10, "このサンプルソ\フトは902シリーズとIPM8500DまたはFHC331(LV)と" ); Lib_chrdisp( 7, 11, "高分解能\エリアセンサとの組み合わせにより高分解能\な" ); Lib_chrdisp( 7, 12, "画像を入力し処理するサンプルです。" ); Lib_chrdisp( 7, 13, "入力画像をファイルにセーブすることができます。" ); Lib_chrdisp( 7, 14, "画像ファイルをロードして処理を行うこともできます。" ); Lib_chrdisp( 7, 15, "竹中システム機器(株)製 FC1300" ); Lib_chrdisp( 7, 16, "竹中システム機器(株)製 FC1320V" ); Lib_chrdisp( 7, 17, "日立電子(株)製 KP−F100" ); Lib_chrdisp( 7, 18, "東京電子工業(株)製 CS3910" ); Lib_chrdisp( 7, 19, "に対応しています。" ); Lib_chrdisp( 7, 21, "【入力設定】使用するカメラ等の設定を行います。" ); Lib_chrdisp( 7, 23, "【グレイ】 濃淡画像を入力し、グレイサーチを実行します。" ); Lib_chrdisp( 7, 25, "【2値】 2値画像を入力し、2値計測を実行します。" ); } /***** サーチ・パタン領域の確保 *****/ int alloc_ptn_area( void ) { int error; if ( NULL != ( ptn_adr = Lib_mlalloc( PTN_SIZE ) ) ) { if ( 0 == Lib_gs_xdefadrs( ptn_adr, PTN_SIZE, INITIAL_PTN_AREA ) ) error = NORMAL_RETURN; else { error = ERROR_RETURN; Lib_display_message( 100, 200, "エラー", "パタンエリアは使用できません" ); } } else { error = ERROR_RETURN; Lib_display_message( 100, 200, "エラー", "パタン用メモリーが確保できません" ); } return( error ); } /***** 設定用コマンドパッド *****/ void set_command_pad( void ) { int no; int pad_level; int status_flag; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "入力設定" ); Lib_view_set_null( pad_level, 5, 5, "カメラ選択", 0 ); Lib_view_set_null( pad_level, 5, 35, "2値レベル", 1 ); Lib_view_set_null( pad_level, 5, 65, "調整入力" , 2 ); Lib_view_set_null( pad_level, 5, 95, "画像入力" , 3 ); Lib_view_set_null( pad_level, 5, 125, "画像セーブ", 4 ); Lib_view_set_size( pad_level, 50, 50, 5, 5 ); Lib_draw_command( pad_level ); for ( status_flag = ON; OFF != status_flag; ) { if ( ERROR_RETURN != ( no = Lib_process_command( pad_level ) ) ) { switch( no ) { case 0: /* 入力設定 */ select_camera_control(); break; case 1: /* 2値レベル */ set_bin_level(); break; case 2: /* 調整入力 */ test_input_control(); break; case 3: /* 画像入力 */ input_control( GRAY_PLANE ); break; case 4: /* 画像セーブ */ image_save_control(); break; case 102: status_flag = OFF; break; } } } Lib_erase_command( pad_level ); Lib_view_close( pad_level ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); } /***** カメラの選択制御 *****/ void select_camera_control( void ) { int error; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); if ( EXECUTE == select_camera() ) { Lib_lfree( ptn_adr ); close_gray_memory(); Lib_high_res_finish(); if ( NORMAL_RETURN == ( error = Lib_high_res_init( img.type ) ) ) { win_reset(); if ( NORMAL_RETURN == open_gray_memory() ) alloc_ptn_area(); else Lib_display_message( 120, 200, "エラー", "画像メモリが確保できません" ); } else if ( ARG_ERR == error ) Lib_display_message( 120, 200, "エラー", "カメラ種別が不明です。" ); else if ( UNUSUAL_ERR == error ) Lib_display_message( 120, 200, "エラー", "ボードまたは902の初期化に失敗しました。" ); else if ( NO_DEVICE == error ) Lib_display_message( 120, 200, "エラー", "ボードが存在していません。" ); } Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_recover_plane( idc ); } /***** カメラの選択 *****/ int select_camera( void ) { PVAL value[3]; int no; int pad_level; int select_c; int status; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); pad_level = Lib_view_open(); /* パッドのオープン */ if ( FC1300 == img.type ) select_c = 0; else if ( KP_F100 == img.type ) select_c = 1; else if ( CS3910 == img.type ) select_c = 2; Lib_view_set_title( pad_level, "カメラ" ); /* パッドタイトルの登録 */ /* 各属性メニューの登録 */ Lib_view_set_select ( pad_level, 5, 5, "カメラ" , select_c , 3, camera_table, 0 ); Lib_view_set_select ( pad_level, 5, 35, "入力方法" , img.input , 2, input_table , 1 ); Lib_view_set_uniq_string( pad_level, 5, 65, "ファイル名", img.f_name, 12, 2 ); /* パッドの表示位置の登録 */ Lib_view_set_size( pad_level, 20, 50, 5, 5 ); Lib_draw_menu( pad_level ); /* メニューパッドの表示 */ if ( ERROR_RETURN != ( no = Lib_process_menu( pad_level, value ) ) ) /* メニュー値の取得 */ { switch( no ) { case 101: /*「実行」が選択された */ select_c = value[0].select_type; img.input = value[1].select_type; strcpy( img.f_name, value[2].string_type ); status = EXECUTE; break; case 102: /*「取り消し」が選択された */ status = CANCEL; break; } } if ( EXECUTE == status ) { if ( 0 == select_c ) img.type = FC1300; else if ( 1 == select_c ) img.type = KP_F100; else if ( 2 == select_c ) img.type = CS3910; } Lib_erase_menu( pad_level ); /* メニューパッドの消去 */ Lib_view_close( pad_level ); /* パッドのクローズ */ Lib_recover_plane( idc ); return( status ); } /***** 2値レベル設定 *****/ void set_bin_level( void ) { int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); if ( CAMERA == img.input ) high_res_camera_freeze( GRAY_PLANE, TRANSMIT ); else if ( FILE == img.input ) image_file_load_bin( gray_mem_no, CURRENT_MEMORY, img.f_name, bp.bin_level ); Lib_lsensor_adjust_bin_level(); bp.bin_level = Lib_get_bin_level(); Lib_video_bin_level( bp.bin_level ); Lib_recover_plane( idc ); } /***** 高分解能センサからの画像入力 *****/ void high_res_camera_freeze( plane, t_flag ) int plane; /* 入力プレーン */ int t_flag; /* 転送フラグ */ { Lib_display_control( plane | LINE_PLANE | CHAR_PLANE ); /* 入力開始 */ if ( ERROR_RETURN == Lib_high_res_freeze( plane, NOT_TRANSMIT ) ) Lib_display_message( 100, 200, "ERROR", "Lib_lsensor_video_input" ); if ( TRANSMIT == t_flag ) Lib_ex_video_transmit( CURRENT_MEMORY, plane, REDUCE_MODE ); } /***** 調整入力制御 *****/ void test_input_control( void ) { int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); Lib_erase_cursor(); for ( ; ; ) { if ( CURSOR_CANCEL == Lib_see_current_position_real( &cpx, &cpy ) ) break; /* 入力開始 */ if ( NORMAL_RETURN == Lib_high_res_xfreeze() ) { /* 入力完了待ち */ for ( ; ; ) { if ( FINISHED_TRANSMIT == Lib_high_res_get_video_status() ) { Lib_ex_video_transmit( CURRENT_MEMORY, GRAY_PLANE, REDUCE_MODE ); break; } } } else Lib_display_message( 100, 200, "ERROR", "Lib_high_res_xfreeze" ); } Lib_look_current_position( &cpx, &cpy ); Lib_draw_cursor( cpx, cpy ); Lib_cls( GRAY_PLANE, BLACK_COLOR ); Lib_recover_plane( idc ); } /***** 画像入力制御 *****/ void input_control( plane ) int plane; /* 入力プレーン */ { char ss[50]; int time; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); Lib_strtclk_count(); /* Lib_extraction_display_memoryを使用するために、入力プレーンを */ /* 表示プレーンに合わせる */ Lib_input_video_control( plane ); if ( CAMERA == img.input ) high_res_camera_freeze( plane, TRANSMIT ); else if ( FILE == img.input ) image_file_load_gray( gray_mem_no, img.f_name, TRANSMIT ); time = ( Lib_readclk_count() * 8138 ) / 10000; Lib_sprintf( ss, "入力時間 %5d(msec)", time ); Lib_chrdisp( 1, 30, ss ); Lib_display_keyinput( 460, 0, "確認" ); Lib_extraction_display_memory( CURRENT_MEMORY ); /* 入力プレーンを元に戻す */ Lib_input_video_control( GRAY_PLANE ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_recover_plane( idc ); } /***** 画像セーブ制御 *****/ void image_save_control( void ) { int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); high_res_camera_freeze( GRAY_PLANE, TRANSMIT ); Lib_set_cursor_shape( HOURGLASS_TYPE ); if ( ERROR_RETURN == image_file_save( gray_mem_no, img.f_name ) ) { Lib_set_cursor_shape( ARROW_TYPE ); Lib_display_message( 120, 200, "エラー", "画像ファイルをロードできません" ); } Lib_set_cursor_shape( ARROW_TYPE ); Lib_recover_plane( idc ); } /***** データ初期化 *****/ void data_init( void ) { /* カメラ・パラメータ */ img.type = FC1300; /* カメラの種類 */ img.input = CAMERA; /* 入力方法 */ Lib_sprintf( img.f_name, "GRAYMEM0.DAT" ); /* 画像ファイル名 */ /* グレイサーチ・パラメータ */ Lib_sprintf( gsp.p_name, "%04d", 0 ); /* パタン名称 */ gsp.number = 1; /* 個数 */ gsp.mode = NORMAL_MODE; /* 精度 */ gsp.complex = 1; /* 複雑度 */ gsp.mid_lower = 5000; /* 途中相関値 */ gsp.last_lower = 6000; /* 最終相関値 */ gsp.edge_detect = 0; /* Wエッジ */ gsp.x_step = 0; /* ピッチX */ gsp.y_step = 0; /* ピッチY */ gsp.filter = 0; /* フィルター */ /* 2値計測・パラメータ */ bp.bin_level = 128; /* 2値レベル */ bp.color = BLACK_COLOR; /* 対象物の色 */ bp.edge = ON; /* ウィンドウ接触塊 */ bp.al_limit = 0; /* 面積下限値 */ bp.au_limit = 245760; /* 面積上限値 */ bp.disp_sw = REDUCE_MODE; /* 結果表示モード */ /* サーチウィンドウ */ gwin.xs = 0; /* ウィンドウ始点X */ gwin.ys = 0; /* ウィンドウ始点Y */ gwin.xe = gwin.xs + X_SIZE - 1; /* ウィンドウ終点X */ gwin.ye = gwin.ys + Y_SIZE - 1; /* ウィンドウ終点Y */ gwin.x_size = X_SIZE; /* ウィンドウサイズX */ gwin.y_size = Y_SIZE; /* ウィンドウサイズY */ /* 2値計測処理範囲 */ bwin.xs = 0; /* ウィンドウ始点X */ bwin.ys = 0; /* ウィンドウ始点Y */ bwin.xe = bwin.xs + X_SIZE - 1; /* ウィンドウ終点X */ bwin.ye = bwin.ys + Y_SIZE - 1; /* ウィンドウ終点Y */ bwin.x_size = X_SIZE; /* ウィンドウサイズX */ bwin.y_size = Y_SIZE; /* ウィンドウサイズY */ } /***** 処理範囲リセット *****/ void win_reset( void ) /* 解説:取り込みサイズ変更時に処理範囲をフルサイズに強制的に再設定する */ { /* サーチウィンドウ */ gwin.xs = 0; /* ウィンドウ始点X */ gwin.ys = 0; /* ウィンドウ始点Y */ gwin.xe = gwin.xs + X_SIZE - 1; /* ウィンドウ終点X */ gwin.ye = gwin.ys + Y_SIZE - 1; /* ウィンドウ終点Y */ gwin.x_size = X_SIZE; /* ウィンドウサイズX */ gwin.y_size = Y_SIZE; /* ウィンドウサイズY */ /* 2値計測処理範囲 */ bwin.xs = 0; /* ウィンドウ始点X */ bwin.ys = 0; /* ウィンドウ始点Y */ bwin.xe = bwin.xs + X_SIZE - 1; /* ウィンドウ終点X */ bwin.ye = bwin.ys + Y_SIZE - 1; /* ウィンドウ終点Y */ bwin.x_size = X_SIZE; /* ウィンドウサイズX */ bwin.y_size = Y_SIZE; /* ウィンドウサイズY */ } /***** グレイメモリの確保 *****/ int open_gray_memory( void ) { int status; gray_mem_no = Lib_get_gray_memory(); if ( ERROR_RETURN != ( gwrk_mem_no = Lib_alloc_gray_memory() ) ) status = NORMAL_RETURN; else status = ERROR_RETURN; return( status ); } /***** グレイメモリの解放 *****/ void close_gray_memory( void ) { Lib_change_gray_memory( gray_mem_no ); Lib_free_gray_memory( gwrk_mem_no ); } /***** 設定制御 *****/ void bin_control( void ) { Lib_cls( ( LINE_PLANE | CHAR_PLANE | GRAY_PLANE | BIN_PLANE ), BLACK_COLOR ); if ( CAMERA == img.input ) high_res_camera_freeze( BIN_PLANE, TRANSMIT ); else if ( FILE == img.input ) image_file_load_bin( gray_mem_no, CURRENT_MEMORY, img.f_name, bp.bin_level ); bin_menu(); Lib_cls( ( LINE_PLANE | CHAR_PLANE | GRAY_PLANE | BIN_PLANE ), BLACK_COLOR ); } /***** 2値メニュー *****/ void bin_menu( void ) { int no; int pad_level; int status_flag; Lib_cls( ( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_display_control( BIN_PLANE | LINE_PLANE | CHAR_PLANE ); pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "2値" ); Lib_view_set_null( pad_level, 5, 5, "2値設定", 0 ); Lib_view_set_null( pad_level, 5, 35, "処理範囲", 1 ); Lib_view_set_null( pad_level, 5, 65, "計測試行", 2 ); Lib_view_set_size( pad_level, 50, 50, 5, 5 ); Lib_draw_command( pad_level ); for ( status_flag = ON; OFF != status_flag; ) { if ( ERROR_RETURN != ( no = Lib_process_command( pad_level ) ) ) { switch( no ) { case 0:/* 設定 */ set_bin_param(); break; case 1:/* 処理範囲 */ set_bin_window(); break; case 2:/* 試行 */ measure(); break; case 102:/* 終了 */ status_flag = OFF; break; } } } Lib_erase_command( pad_level ); Lib_view_close( pad_level ); Lib_display_control( GRAY_PLANE | LINE_PLANE | CHAR_PLANE ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); } /***** 2値パラメータ設定 *****/ void set_bin_param( void ) { PVAL value[5]; int pad_level_b; int no; int area_max; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); area_max = Lib_get_fx_size() * Lib_get_fy_size(); pad_level_b = Lib_view_open(); /* パッドのオープン */ Lib_view_set_title( pad_level_b, "2値条件" ); /* パッドタイトルの登録 */ /* 各属性メニューの登録 */ Lib_view_set_select ( pad_level_b, 5, 5, "対象物の色", bp.color , 2, select_cl, 0 ); Lib_view_set_uniq_alter ( pad_level_b, 5, 35, "境界" , bp.edge , 1 ); Lib_view_set_uniq_numeral( pad_level_b, 5, 65, "面積下限値", bp.al_limit, AR_MIN, area_max, 2 ); Lib_view_set_uniq_numeral( pad_level_b, 5, 95, "面積上限値", bp.au_limit, AR_MIN, area_max, 3 ); Lib_view_set_select ( pad_level_b, 5, 125, "結果表\示" , bp.disp_sw , 2, select_bds, 4 ); /* パッドの表示位置の登録 */ Lib_view_set_size( pad_level_b, 30, 30, 5, 5 ); Lib_draw_menu( pad_level_b ); /* メニューパッドの表示 */ if ( ERROR_RETURN != ( no = Lib_process_menu( pad_level_b, value ) ) ) /* メニュー値の取得 */ { switch( no ) { case 101: /*「実行」が選択された */ bp.color = value[0].select_type; bp.edge = value[1].on_off_type; bp.al_limit = value[2].value_type; bp.au_limit = value[3].value_type; bp.disp_sw = value[4].select_type; break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level_b ); Lib_view_close( pad_level_b ); Lib_recover_plane( idc ); } /***** 2値計測処理範囲設定 *****/ void set_bin_window( void ) { int xs,ys,xe,ye; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); xs = bwin.xs; ys = bwin.ys; xe = bwin.xe; ye = bwin.ye; mn_box_set_menu( &xs, &ys, &xe, &ye, BIN_PLANE ); bwin.xs = xs; bwin.ys = ys; bwin.xe = xe; bwin.ye = ye; Lib_recover_plane( idc ); } /***** 2値計測 *****/ void measure( void ) { char ss[50]; char *error_string; unsigned int max_blob; int ratio; int time,time2; int status; int ct; int num; int page,blob_no; int fx_size,fy_size; int x_scale,y_scale; int x_offset,y_offset; int area; int sumi,sumj; int center_x,center_y; int xe,ye; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); fx_size = Lib_get_fx_size(); fy_size = Lib_get_fy_size(); ratio = Lib_get_frame_ratio(); Lib_set_stage_window( bwin.xs, bwin.ys, bwin.xe, bwin.ye ); Lib_set_display_switch( OFF ); max_blob = Lib_get_meas_max_blob(); if ( ( int * )NULL != ( indextbl = ( int * )Lib_mlalloc( ( max_blob + 1 ) * 4 ) ) ) { num = 0; page = 1; ct = 0; Lib_strtclk_count(); if ( CAMERA == img.input ) high_res_camera_freeze( BIN_PLANE, TRANSMIT ); else if ( FILE == img.input ) image_file_load_bin( gray_mem_no, CURRENT_MEMORY, img.f_name, bp.bin_level ); time = ( Lib_readclk_count() * 8138 ) / 10000; Lib_sprintf( ss, "入力時間 %5d(msec)", time ); Lib_chrdisp( 1, 29, ss ); Lib_box( bwin.xs / ratio, bwin.ys / ratio, bwin.xe / ratio, bwin.ye / ratio, SOLID_LINE ); /* システム構築対応1次特徴量計測処理オープン */ Lib_Open_meas_structure(); if ( NORMAL_RETURN == ( status = Lib_xmeasure( bp.color, bp.edge, bp.al_limit, &measp ) ) ) { /* システム構築対応1次特徴量アドレステーブル作成 */ Lib_Make_meas_structure( (void *)measp ); if ( 0 != ( num = Lib_xorderng( measp, 0, 0, bp.color, bp.au_limit, bp.al_limit, indextbl ) ) ) { time2 = ( Lib_readclk_count() * 8138 ) / 10000; Lib_sprintf( ss, "処理時間 %5d(msec)", time2 - time ); Lib_chrdisp( 1, 30, ss ); Lib_display_keyinput( 450, 0, "確認" ); Lib_cls( CHAR_PLANE, BLACK_COLOR ); for ( ; ; ) { blob_no = *( indextbl + ct ); if ( EXTRACT_MODE == bp.disp_sw ) /* 結果表示切り出し転送 */ { Lib_cls( LINE_PLANE, BLACK_COLOR ); x_scale = 1; y_scale = 1; /* 対象ブローブの重心を計算 */ area = *( Meas_area + blob_no ); sumi = *( Meas_sumi + blob_no ); sumj = *( Meas_sumj + blob_no ); center_x = sumi / area; center_y = sumj / area; /* 結果表示範囲の計算 */ x_offset = center_x - 256; y_offset = center_y - 240; if ( x_offset < 0 ) x_offset = 0; else if ( (fx_size - 512) < x_offset ) x_offset = fx_size - 512; if ( y_offset < 0 ) y_offset = 0; else if ( (fy_size - 480) < y_offset ) y_offset = fy_size - 480; xe = x_offset + 511; ye = y_offset + 479; Lib_set_extract_window( x_offset, y_offset, xe, ye ); Lib_ex_video_transmit( CURRENT_MEMORY, BIN_PLANE, EXTRACT_MODE ); } else if ( REDUCE_MODE == bp.disp_sw ) /* 結果表示縮小転送 */ { Lib_box( bwin.xs / ratio, bwin.ys / ratio, bwin.xe / ratio, bwin.ye / ratio, SOLID_LINE ); x_scale = ratio; y_scale = ratio; x_offset = 0; y_offset = 0; } Lib_strtclk_count(); Lib_calcult( page, blob_no, &calcp ); time = ( Lib_readclk_count() * 8138 ) / 10000; Lib_sprintf( ss, "処理時間 %5d(msec)", time ); Lib_chrdisp( 1, 1, ss ); Lib_calcult_disp_result( x_offset, y_offset, x_scale, y_scale, blob_no, page, measp, calcp ); if ( END == result_disp_menu( num, &page, &ct ) ) break; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); } } else Lib_display_message( 100, 200, "エラー", "Lib_xorderng" ); } else { error_string = Lib_get_meas_error_string(); Lib_sprintf( ss, "%s", error_string ); Lib_display_message( 100, 200, "エラー", ss ); } Lib_lfree( ( char * )indextbl ); } else Lib_chrdisp( 1, 30, "ワークメモリを確保できませんでした。" ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_recover_plane( idc ); } /***** 2値計測結果表示メニュー *****/ int result_disp_menu( num, page, ct ) int num; int *page; int *ct; { int status; int width,height; int d_key2_xs,d_key3_xs,d_key4_xs,d_key5_xs; int d_key1_xe,d_key2_xe,d_key3_xe,d_key4_xe,d_key5_xe; status = CONTINUE; /* メニュー・キー初期表示 */ Lib_display_key( D_KEY1_XS, D_KEY_YS, ( char * )disp_menu_key[0], 1 ); Lib_get_key_size( D_STR, &width, &height ); d_key1_xe = D_KEY1_XS + width - 1; d_key2_xs = D_KEY1_XS + width + 1; Lib_display_key( d_key2_xs, D_KEY_YS, ( char * )disp_menu_key[1], 1 ); Lib_get_key_size( D_STR, &width, &height ); d_key2_xe = d_key2_xs + width - 1; d_key3_xs = d_key2_xs + width + 1; Lib_display_key( d_key3_xs, D_KEY_YS, ( char * )disp_menu_key[2], 1 ); Lib_get_key_size( D_STR, &width, &height ); d_key3_xe = d_key3_xs + width - 1; d_key4_xs = d_key3_xs + width + 1; Lib_display_key( d_key4_xs, D_KEY_YS, ( char * )disp_menu_key[3], 1 ); Lib_get_key_size( D_STR, &width, &height ); d_key4_xe = d_key4_xs + width - 1; d_key5_xs = d_key4_xs + width + 1; Lib_display_key( d_key5_xs, D_KEY_YS, ( char * )disp_menu_key[4], 1 ); Lib_get_key_size( D_STR, &width, &height ); d_key5_xe = d_key5_xs + width - 1; /* トラック・ボールの左ボタンクリック? */ if ( CURSOR_EXECUTE == Lib_get_current_position( &cpx, &cpy ) ) { if ( D_KEY1_XS <= cpx && cpx <= d_key1_xe && D_KEY_YS < cpy ) { /* 「前頁」が選択された */ Lib_display_key( D_KEY1_XS, D_KEY_YS, ( char * )disp_menu_key[0], 2 ); *page = ( *page ) - 1; } else if ( d_key2_xs <= cpx && cpx <= d_key2_xe && D_KEY_YS < cpy ) { /* 「次頁」が選択された */ Lib_display_key( d_key2_xs, D_KEY_YS, ( char * )disp_menu_key[1], 2 ); *page = ( *page ) + 1; } else if ( d_key3_xs <= cpx && cpx <= d_key3_xe && D_KEY_YS < cpy ) { /* 「前塊」が選択された */ Lib_display_key( d_key3_xs, D_KEY_YS, ( char * )disp_menu_key[2], 2 ); *ct = ( *ct ) - 1; } else if ( d_key4_xs <= cpx && cpx <= d_key4_xe && D_KEY_YS < cpy ) { /* 「次塊」が選択された */ Lib_display_key( d_key4_xs, D_KEY_YS, ( char * )disp_menu_key[3], 2 ); *ct = ( *ct ) + 1; } else if ( d_key5_xs <= cpx && cpx <= d_key5_xe && D_KEY_YS < cpy ) { /* 「終了」が選択された */ Lib_display_key( d_key5_xs, D_KEY_YS, ( char * )disp_menu_key[4], 2 ); status = END; } if ( *page < 1 ) *page = 1; else if ( 3 < *page ) *page = 3; if ( *ct < 0 ) *ct = 0; else if ( num <= *ct ) *ct = num - 1; } return( status ); } /***** 設定制御 *****/ void gray_control( void ) { Lib_cls( ( LINE_PLANE | CHAR_PLANE | GRAY_PLANE | BIN_PLANE ), BLACK_COLOR ); if ( CAMERA == img.input ) high_res_camera_freeze( GRAY_PLANE, TRANSMIT ); else if ( FILE == img.input ) image_file_load_gray( gray_mem_no, img.f_name, TRANSMIT ); gray_menu(); Lib_cls( ( LINE_PLANE | CHAR_PLANE | GRAY_PLANE | BIN_PLANE ), BLACK_COLOR ); } /***** グレイメニュー *****/ void gray_menu( void ) { int no; int pad_level; int status_flag; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); pad_level = Lib_view_open(); Lib_view_set_title( pad_level, "グレイ" ); Lib_view_set_null( pad_level, 5, 5, "サーチ条件" , 0 ); Lib_view_set_null( pad_level, 5, 35, "パタン登録" , 1 ); Lib_view_set_null( pad_level, 5, 65, "パタン表\示", 2 ); Lib_view_set_null( pad_level, 5, 95, "サーチ範囲" , 3 ); Lib_view_set_null( pad_level, 5, 125, "サーチ試行" , 4 ); Lib_view_set_size( pad_level, 50, 50, 5, 5 ); Lib_draw_command( pad_level ); for ( status_flag = ON; OFF != status_flag; ) { if ( ERROR_RETURN != ( no = Lib_process_command( pad_level ) ) ) { switch( no ) { case 0: /* サーチ条件 */ set_search_parm(); break; case 1: /* パタン登録 */ mn_ptn_entry_control(); break; case 2: /* パタン表示 */ disp_ptn(); break; case 3: /* サーチ範囲 */ set_gs_window(); break; case 4: /* サーチ試行 */ search(); break; case 102: status_flag = OFF; break; } } } Lib_erase_command( pad_level ); Lib_view_close( pad_level ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); } /***** グレイサーチ設定 *****/ void set_search_parm( void ) { PVAL value[10]; int no; int pad_level_gsp; int xs_max,ys_max; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); xs_max = Lib_get_fx_size(); ys_max = Lib_get_fy_size(); pad_level_gsp = Lib_view_open(); /* パッドのオープン */ Lib_view_set_title( pad_level_gsp, "設定" ); /* パッドタイトルの登録 */ /* 各属性メニューの登録 */ Lib_view_set_uniq_string ( pad_level_gsp, 5, 5, "パタン名称", gsp.p_name , 4 , 0 ); Lib_view_set_uniq_numeral( pad_level_gsp, 5, 35, "個数" , gsp.number , NUM_MIN, NUM_MAX , 1 ); Lib_view_set_select ( pad_level_gsp, 5, 65, "精度" , gsp.mode - 1 , 3 , select_c, 2 ); Lib_view_set_uniq_numeral( pad_level_gsp, 5, 95, "複雑度" , gsp.complex , COM_MIN, COM_MAX , 3 ); Lib_view_set_uniq_numeral( pad_level_gsp, 5, 125, "途中下限値", gsp.mid_lower , SCO_MIN, SCO_MAX , 4 ); Lib_view_set_uniq_numeral( pad_level_gsp, 5, 155, "最終下限値", gsp.last_lower , SCO_MIN, SCO_MAX , 5 ); Lib_view_set_uniq_alter ( pad_level_gsp, 5, 185, "Wエッジ" , gsp.edge_detect, 6 ); Lib_view_set_uniq_numeral( pad_level_gsp, 5, 215, "ピッチX" , gsp.x_step , XS_MIN , xs_max , 7 ); Lib_view_set_uniq_numeral( pad_level_gsp, 5, 245, "ピッチY" , gsp.y_step , YS_MIN , ys_max , 8 ); Lib_view_set_select ( pad_level_gsp, 5, 275, "フィルター", gsp.filter , 4 , select_f, 9 ); /* パッドの表示位置の登録 */ Lib_view_set_size( pad_level_gsp, 80, 80, 5, 5 ); Lib_draw_menu( pad_level_gsp ); /* メニューパッドの表示 */ if ( ERROR_RETURN != ( no = Lib_process_menu( pad_level_gsp, value ) ) ) /* メニュー値の取得 */ { switch( no ) { case 101: /*「実行」が選択された */ strcpy( gsp.p_name, value[0].string_type ); gsp.number = value[1].value_type; gsp.mode = value[2].select_type + 1; gsp.complex = value[3].value_type; gsp.mid_lower = value[4].value_type; gsp.last_lower = value[5].value_type; gsp.edge_detect = value[6].on_off_type; gsp.x_step = value[7].value_type; gsp.y_step = value[8].value_type; gsp.filter = value[9].select_type; break; case 102: /*「取り消し」が選択された */ break; } } Lib_erase_menu( pad_level_gsp ); /* メニューパッドの消去 */ Lib_view_close( pad_level_gsp ); /* パッドのクローズ */ Lib_recover_plane( idc ); } /***** m×n画像のパタン登録(メニュー)*****/ int mn_ptn_entry_control( void ) { int status; int width,height; int pe_key2_xs,pe_key3_xs; int pe_key1_xe,pe_key2_xe,pe_key3_xe; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); status = NORMAL_RETURN; for ( ; ; ) { disp_mem_size(); disp_area(); /* メニュー・キー初期表示 */ Lib_display_key( PE_KEY1_XS, PE_KEY_YS, ( char * )ptn_entry_menu_key[0], 1 ); Lib_get_key_size( PE_STR, &width, &height ); pe_key1_xe = PE_KEY1_XS + width - 1; pe_key2_xs = PE_KEY1_XS + width + 1; Lib_display_key( pe_key2_xs, PE_KEY_YS, ( char * )ptn_entry_menu_key[1], 1 ); Lib_get_key_size( PE_STR, &width, &height ); pe_key2_xe = pe_key2_xs + width - 1; pe_key3_xs = pe_key2_xs + width + 1; Lib_display_key( pe_key3_xs, PE_KEY_YS, ( char * )ptn_entry_menu_key[2], 1 ); Lib_get_key_size( PE_STR, &width, &height ); pe_key3_xe = pe_key3_xs + width - 1; if ( CURSOR_EXECUTE == Lib_get_current_position( &cpx, &cpy ) ) { if ( PE_KEY1_XS <= cpx && cpx <= pe_key1_xe && PE_KEY_YS < cpy ) { /* 「移動」が選択された */ Lib_display_key( PE_KEY1_XS, PE_KEY_YS, ( char * )ptn_entry_menu_key[0], 2 ); move_disp_area(); } else if ( pe_key2_xs <= cpx && cpx <= pe_key2_xe && PE_KEY_YS < cpy ) { /* 「登録」が選択された */ Lib_display_key( pe_key2_xs, PE_KEY_YS, ( char * )ptn_entry_menu_key[1], 2 ); status = mn_ptn_entry(); } else if ( pe_key3_xs <= cpx && cpx <= pe_key3_xe && PE_KEY_YS < cpy ) { /* 「終了」が選択された */ Lib_display_key( pe_key3_xs, PE_KEY_YS, ( char * )ptn_entry_menu_key[2], 2 ); break; } } } Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_recover_plane( idc ); return( status ); } /***** 範囲表示 *****/ void disp_area( void ) { int ratio; int dx_size,dy_size; int fx_size,fy_size; int wxs,wxe,wys,wye; int bxs,bys; int bx_size,by_size; if( 0 < ( ratio = Lib_get_frame_ratio() ) ) { /*メモリサイズの取得*/ fx_size = Lib_get_fx_size(); fy_size = Lib_get_fy_size(); /*フレーム・バッファサイズの取得*/ dx_size = Lib_get_dx_size(); dy_size = Lib_get_dy_size(); Lib_get_extract_window( &wxs, &wys, &wxe, &wye ); /* BOX初期表示の始点及びサイズ(X)*/ bxs = wxs / ratio; bx_size = dx_size / ratio - 1; if ( ( fx_size / ratio - bx_size - 1 ) < bxs ) bxs = fx_size / ratio - bx_size - 1; /* BOX初期表示の始点及びサイズ(Y)*/ if ( fy_size < dy_size ) { bxs = 0; by_size = fy_size / ratio - 1; } else { bys = wys / ratio; by_size = dy_size / ratio - 1; if ( ( fy_size / ratio - by_size - 1 ) < bys ) bxs = fy_size / ratio - by_size - 1; } Lib_box( bxs, bys, bxs + bx_size, bys + by_size, SOLID_LINE ); } } /***** 表示範囲の移動 *****/ void move_disp_area( void ) { int status; int ratio; int dx_size,dy_size; int fx_size,fy_size; int bxp,byp; int wxs,wxe,wys,wye; int bxs,bys; int bx_size,by_size; Lib_cls( CHAR_PLANE, BLACK_COLOR ); if( 0 < ( ratio = Lib_get_frame_ratio() ) ) { bxp = 0; byp = 0; /*メモリサイズの取得*/ fx_size = Lib_get_fx_size(); fy_size = Lib_get_fy_size(); /*フレーム・バッファサイズの取得*/ dx_size = Lib_get_dx_size(); dy_size = Lib_get_dy_size(); Lib_get_extract_window( &wxs, &wys, &wxe, &wye ); /* BOX初期表示の始点及びサイズ(X)*/ bxs = wxs / ratio; bx_size = dx_size / ratio - 1; if ( ( fx_size / ratio - bx_size - 1 ) < bxs ) bxs = fx_size / ratio - bx_size - 1; /* BOX初期表示の始点及びサイズ(Y)*/ if ( fy_size < dy_size ) { bxs = 0; by_size = fy_size / ratio - 1; } else { bys = wys / ratio; by_size = dy_size / ratio - 1; if ( ( fy_size / ratio - by_size - 1 ) < bys ) bxs = fy_size / ratio - by_size - 1; } Lib_box( bxs, bys, bxs + bx_size, bys + by_size, SOLID_LINE ); cpx = bxs; cpy = bys; bxp = bxs; byp = bys; Lib_see_current_position( &cpx, &cpy ); Lib_draw_cursor( cpx, cpy ); for ( status = 0; CURSOR_EXECUTE != status; ) { status = Lib_see_current_position( &cpx, &cpy ); if ( bxp != cpx || byp != cpy ) /* カーソルは移動したか? */ { Lib_box( bxp, byp, bxp + bx_size, byp + by_size, BLACK_LINE ); /* カーソル移動の抑制 */ if ( ( fx_size / ratio - bx_size - 1 ) < cpx ) cpx = fx_size / ratio - bx_size - 1; if ( ( fy_size / ratio - by_size - 1 ) < cpy ) cpy = fy_size / ratio - by_size - 1; Lib_move_cursor( cpx, cpy ); /* カーソルは移動したので新たに表示 */ bxp = cpx; byp = cpy; /* 新たに表示したカーソルの位置を保存 */ Lib_box( cpx, cpy, cpx + bx_size, cpy + by_size, SOLID_LINE ); } } wxs = cpx * ratio; wys = cpy * ratio; wxe = cpx * ratio + dx_size - 1; wye = cpy * ratio + dy_size - 1; Lib_set_extract_window( wxs, wys, wxe, wye ); } Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); } /***** m×n画像のパタン登録 *****/ int mn_ptn_entry( void ) { int *p_name; int error; int wxs,wxe,wys,wye; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_ex_video_transmit( CURRENT_MEMORY, GRAY_PLANE, EXTRACT_MODE ); Lib_get_extract_window( &wxs, &wys, &wxe, &wye ); Lib_gs_smode( gsp.filter ); p_name = (int *)(gsp.p_name); if ( -1 == ( error = Lib_gs_exdefpat( *p_name, wxs, wys, 1, 1 ) ) ) Lib_display_message( 120, 200, "エラー", "既に200個登録済みです" ); else if ( -2 == error ) Lib_display_message( 120, 200, "エラー", "パタン格納領域不足です" ); Lib_ex_video_transmit( CURRENT_MEMORY, GRAY_PLANE, REDUCE_MODE ); return( error ); } /***** メモリサイズの表示 *****/ void disp_mem_size( void ) { char disp_size[15]; int fx_size, fy_size; fx_size = Lib_get_fx_size(); fy_size = Lib_get_fy_size(); Lib_sprintf( disp_size, " %4d × %4d ", fx_size, fy_size ); Lib_display_comment( 380, 456, disp_size ); } /***** パタン表示 *****/ void disp_ptn( void ) { int error; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); Lib_change_gray_memory( gwrk_mem_no ); error = Lib_gs_dsppat(); Lib_cls( GRAY_PLANE, BLACK_COLOR ); Lib_change_gray_memory( gray_mem_no ); Lib_ex_video_transmit( CURRENT_MEMORY, GRAY_PLANE, REDUCE_MODE ); Lib_recover_plane( idc ); } /***** サーチウィンドウ設定 *****/ void set_gs_window( void ) { int xs,ys,xe,ye; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); xs = gwin.xs; ys = gwin.ys; xe = gwin.xe; ye = gwin.ye; mn_box_set_menu( &xs, &ys, &xe, &ye, GRAY_PLANE ); gwin.xs = xs; gwin.ys = ys; gwin.xe = xe; gwin.ye = ye; Lib_recover_plane( idc ); } /***** m×n画像の処理範囲(BOX)設定メニュー *****/ void mn_box_set_menu( xs, ys, xe, ye, plane ) int *xs,*ys,*xe,*ye; int plane; { int width,height; int el_key2_xs,el_key3_xs; int el_key1_xe,el_key2_xe,el_key3_xe; Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); for ( ; ; ) { disp_mem_size(); disp_area(); /* メニュー・キー初期表示 */ Lib_display_key( EL_KEY1_XS, EL_KEY_YS, ( char * )set_line_menu_key[0], 1 ); Lib_get_key_size( EL_STR_NUM, &width, &height ); el_key1_xe = EL_KEY1_XS + width - 1; el_key2_xs = EL_KEY1_XS + width + 1; Lib_display_key( el_key2_xs, EL_KEY_YS, ( char * )set_line_menu_key[1], 1 ); Lib_get_key_size( EL_STR_NUM, &width, &height ); el_key2_xe = el_key2_xs + width - 1; el_key3_xs = el_key2_xs + width + 1; Lib_display_key( el_key3_xs, EL_KEY_YS, ( char * )set_line_menu_key[2], 1 ); Lib_get_key_size( EL_STR_NUM, &width, &height ); el_key3_xe = el_key3_xs + width - 1; if ( CURSOR_EXECUTE == Lib_get_current_position( &cpx, &cpy ) ) { if ( EL_KEY1_XS <= cpx && cpx <= el_key1_xe && EL_KEY_SIZE_Y < cpy ) { /* 「移動」が選択された */ Lib_display_key( EL_KEY1_XS, EL_KEY_YS, ( char * )set_line_menu_key[0], 2 ); move_disp_area(); } else if ( el_key2_xs <= cpx && cpx <= el_key2_xe && EL_KEY_SIZE_Y < cpy ) { /* 「設定」が選択された */ Lib_display_key( el_key2_xs, EL_KEY_YS, ( char * )set_line_menu_key[1], 2 ); mn_box_set_extract_mode( xs, ys, xe, ye, plane ); mn_box_draw_reduce_mode( *xs, *ys, *xe, *ye ); } else if ( el_key3_xs <= cpx && cpx <= el_key3_xe && EL_KEY_SIZE_Y < cpy ) { /* 「終了」が選択された */ Lib_display_key( el_key3_xs, EL_KEY_YS, ( char * )set_line_menu_key[2], 2 ); break; } } } Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); } /***** m×n画像切り出し転送時の処理範囲(BOX)設定 *****/ void mn_box_set_extract_mode( xs, ys, xe, ye, plane ) int *xs,*ys,*xe,*ye; int plane; { char s[50]; int ct; int status; int ratio; int dx_size,dy_size; int fx_size,fy_size; int bcx,bcy; int new_x,new_y; int wxs,wxe,wys,wye; int move_x,move_y; Lib_cls( ( plane | LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_display_control( plane | LINE_PLANE | CHAR_PLANE ); Lib_ex_video_transmit( CURRENT_MEMORY, plane, EXTRACT_MODE ); if( 0 < ( ratio = Lib_get_frame_ratio() ) ) { /*メモリサイズの取得*/ fx_size = Lib_get_fx_size(); fy_size = Lib_get_fy_size(); /*フレーム・バッファサイズの取得*/ dx_size = Lib_get_dx_size(); dy_size = Lib_get_dy_size(); Lib_get_extract_window( &wxs, &wys, &wxe, &wye ); cpx = 255; cpy = 239; bcx = 0; bcy = 0; Lib_draw_cursor( cpx, cpy ); for ( ct = 0; ct < 2; ct++ ) { for ( status = 0; CURSOR_EXECUTE != status; ) { Lib_sprintf( s, "( %4d, %4d )", wxs + cpx, wys + cpy ); Lib_chrdisp( 1, 30, s ); if ( 0 == ct ) Lib_chrdisp( 1, 1, "始点を指定してください" ); else if ( 1 == ct ) Lib_chrdisp( 1, 1, "終点を指定してください" ); status = Lib_see_current_position( &cpx, &cpy ); if ( bcx != cpx || bcy != cpy ) { Lib_move_cursor( cpx, cpy ); bcx = cpx; bcy = cpy; if ( 1 == ct ) { new_x = cpx - ( wxs + cpx - *xs ); new_y = cpy - ( wys + cpy - *ys ); Lib_cls( LINE_PLANE, BLACK_COLOR ); Lib_box( new_x, new_y, cpx, cpy, SOLID_LINE ); } } /* 表示範囲を移動する */ if ( 0 == cpx || 0 == cpy || (dx_size - 1) == cpx || (dy_size - 1) == cpy ) { if ( 0 == cpx && 0 != cpy ) { move_x = -100; move_y = 0; } else if ( 0 != cpx && 0 == cpy ) { move_x = 0; move_y = -100; } else if ( 0 == cpx && 0 == cpy ) { move_x = -100; move_y = -100; } else if ( (dx_size - 1) == cpx && (dy_size - 1) != cpy ) { move_x = 100; move_y = 0; } else if ( (dx_size - 1) != cpx && (dy_size - 1) == cpy ) { move_x = 0; move_y = 100; } else if ( (dx_size - 1) == cpx && (dy_size - 1) == cpy ) { move_x = 100; move_y = 100; } wxs += move_x; wxe += move_x; wys += move_y; wye += move_y; if( wxs < 0 ) { wxs = 0; wxe = dx_size -1; } if( (fx_size - 1) < wxe ) { wxs = fx_size - dx_size; wxe = fx_size - 1; } if( wys < 0 ) { wys = 0; wye = dy_size -1; } if( (fy_size - 1) < wye ) { wys = fy_size - dy_size; wye = fy_size - 1; } /*ラインセンサ画像の表示*/ Lib_ex_memory_display( plane, TRANSMIT, CURRENT_MEMORY, wxs, wys, wxe, wye ); } } if ( 0 == ct ) /* 始点を保存する */ { *xs = wxs + cpx; *ys = wys + cpy; } else if ( 1 == ct ) /* 終点を保存する */ { *xe = wxs + cpx; *ye = wys + cpy; } } Lib_set_extract_window( wxs, wys, wxe, wye ); } Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_ex_video_transmit( CURRENT_MEMORY, plane, REDUCE_MODE ); } /***** 縮小表示時に、設定した処理範囲(BOX)を表示 *****/ void mn_box_draw_reduce_mode( xs, ys, xe, ye ) int xs,ys,xe,ye; { int ratio; if( 0 < ( ratio = Lib_get_frame_ratio() ) ) Lib_box( xs / ratio, ys / ratio, xe / ratio, ye / ratio, SOLID_LINE ); } /***** サーチ実行 *****/ void search( void ) { char ss[50]; int result[150]; int *p_name; int ratio; int num; int time; int idc; idc = Lib_shelter_plane( 0, 0, (Lib_get_dx_size() - 1), (Lib_get_dy_size() - 1), CHAR_PLANE ); ratio = Lib_get_frame_ratio(); p_name = (int *)(gsp.p_name); Lib_strtclk_count(); if ( CAMERA == img.input ) high_res_camera_freeze( GRAY_PLANE, TRANSMIT ); else if ( FILE == img.input ) image_file_load_gray( gray_mem_no, img.f_name, TRANSMIT ); time = ( Lib_readclk_count() * 8138 ) / 10000; Lib_sprintf( ss, "入力時間 %5d(msec)", time ); Lib_chrdisp( 1, 29, ss ); Lib_gs_window( NON_DISPLAY, gwin.xs, gwin.ys, gwin.xe, gwin.ye ); Lib_box( gwin.xs / ratio, gwin.ys / ratio, gwin.xe / ratio, gwin.ye / ratio, SOLID_LINE ); Lib_gs_smode( gsp.filter ); Lib_gs_xcondition( gsp.edge_detect, gsp.x_step, gsp.y_step, 0, 0 ); Lib_strtclk_count(); if ( 0 < ( num = Lib_gs_search( NON_DISPLAY, *p_name, gsp.number, gsp.mode, gsp.complex, gsp.mid_lower, gsp.last_lower, result ) ) ) { time = ( Lib_readclk_count() * 8138 ) / 10000; Lib_sprintf( ss, "処理時間 %5d(msec)", time ); Lib_chrdisp( 1, 30, ss ); Lib_gs_disp_result( *p_name, 0, 0, ratio, ratio, num, result, ON ); } else if ( 0 == num ) Lib_display_message( 120, 200, "エラー", "対象物が見つかりません" ); else if ( -1 == num ) Lib_display_message( 120, 200, "エラー", "パタンが登録されていません" ); Lib_cls( ( LINE_PLANE | CHAR_PLANE ), BLACK_COLOR ); Lib_recover_plane( idc ); } /***** 画像ファイルのロード(濃淡) *****/ void image_file_load_gray( mem_no, f_name, t_flag ) int mem_no; char *f_name; int t_flag; { char gf_name[20]; char f_name2[20]; char *top_adrs; unsigned long error; unsigned long mem_size; mem_size = Lib_get_fx_size() * Lib_get_fy_size(); if ( NULL != ( top_adrs = Lib_adrs_gray_memory( mem_no ) ) ) { cut_space( f_name, f_name2 ); Lib_sprintf( gf_name, "\\FS0\\%s", f_name2 ); if ( ( unsigned long )NULL != ( error = Lib_fload( gf_name, top_adrs, mem_size ) ) ) { if ( TRANSMIT == t_flag ) Lib_ex_video_transmit( mem_no, GRAY_PLANE, REDUCE_MODE ); } else Lib_display_message( 120, 200, "エラー", "画像ファイルをロードできません" ); } else Lib_display_message( 120, 200, "エラー", "アドレスが正しくありません" ); } /***** 画像ファイルのロード(2値) *****/ void image_file_load_bin( g_mem_no, b_mem_no, f_name, bin_level ) int g_mem_no; int b_mem_no; char *f_name; int bin_level; { image_file_load_gray( g_mem_no, f_name, NOT_TRANSMIT ); Lib_binary_convert( b_mem_no, g_mem_no, bin_level ); Lib_ex_video_transmit( b_mem_no, BIN_PLANE, REDUCE_MODE ); } /***** 画像ファイルのセーブ(濃淡) *****/ int image_file_save( mem_no, f_name ) int mem_no; char *f_name; { char gf_name[20]; char f_name2[20]; char *top_adrs; unsigned long error; unsigned long mem_size; int status; mem_size = Lib_get_fx_size() * Lib_get_fy_size(); if ( NULL != ( top_adrs = Lib_adrs_gray_memory( mem_no ) ) ) { cut_space( f_name, f_name2 ); Lib_sprintf( gf_name, "\\FS0\\%s", f_name2 ); if ( ( unsigned long )NULL != ( error = Lib_fsave( gf_name, top_adrs, mem_size ) ) ) status = NORMAL_RETURN; else status = ERROR_RETURN; } else status = ERROR_RETURN; return( status ); } /***** スペース除去 *****/ void cut_space( instr, otstr ) char *instr; char *otstr; { for(;;) { if ( ' ' != *instr ) *otstr++ = *instr; if ( 0x00 == *instr ) break; instr++; } }