This is display debug program by TeraTerm

Dependencies:   GR-PEACH_video mbed

Committer:
TetsuyaKonno
Date:
Thu Nov 17 02:36:01 2016 +0000
Revision:
0:97cbef48166d
First program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TetsuyaKonno 0:97cbef48166d 1 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 2 //Supported MCU: RZ/A1H
TetsuyaKonno 0:97cbef48166d 3 //File Contents: Display Debug
TetsuyaKonno 0:97cbef48166d 4 //Version number: Ver.1.00
TetsuyaKonno 0:97cbef48166d 5 //Date: 2016.11.17
TetsuyaKonno 0:97cbef48166d 6 //Copyright: Renesas Electronics Corporation
TetsuyaKonno 0:97cbef48166d 7 // Hitachi Document Solutions Co., Ltd.
TetsuyaKonno 0:97cbef48166d 8 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 9
TetsuyaKonno 0:97cbef48166d 10 //This program supports the following boards:
TetsuyaKonno 0:97cbef48166d 11 //* GR-PEACH(E version)
TetsuyaKonno 0:97cbef48166d 12 //* Motor drive board Ver.5
TetsuyaKonno 0:97cbef48166d 13 //* Camera module (SC-310)
TetsuyaKonno 0:97cbef48166d 14
TetsuyaKonno 0:97cbef48166d 15 //Include
TetsuyaKonno 0:97cbef48166d 16 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 17 #include "mbed.h"
TetsuyaKonno 0:97cbef48166d 18 #include "math.h"
TetsuyaKonno 0:97cbef48166d 19 #include "iodefine.h"
TetsuyaKonno 0:97cbef48166d 20 #include "DisplayBace.h"
TetsuyaKonno 0:97cbef48166d 21
TetsuyaKonno 0:97cbef48166d 22 //Define
TetsuyaKonno 0:97cbef48166d 23 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 24 //LED Color on GR-PEACH
TetsuyaKonno 0:97cbef48166d 25 #define LED_OFF 0x00
TetsuyaKonno 0:97cbef48166d 26 #define LED_RED 0x01
TetsuyaKonno 0:97cbef48166d 27 #define LED_GREEN 0x02
TetsuyaKonno 0:97cbef48166d 28 #define LED_YELLOW 0x03
TetsuyaKonno 0:97cbef48166d 29 #define LED_BLUE 0x04
TetsuyaKonno 0:97cbef48166d 30 #define LED_PURPLE 0x05
TetsuyaKonno 0:97cbef48166d 31 #define LED_SKYBLUE 0x06
TetsuyaKonno 0:97cbef48166d 32 #define LED_WHITE 0x07
TetsuyaKonno 0:97cbef48166d 33
TetsuyaKonno 0:97cbef48166d 34 //Status
TetsuyaKonno 0:97cbef48166d 35 #define ERROR 0x00
TetsuyaKonno 0:97cbef48166d 36 #define STOP 0x01
TetsuyaKonno 0:97cbef48166d 37 #define RUN 0x02
TetsuyaKonno 0:97cbef48166d 38 #define DEBUG 0x03
TetsuyaKonno 0:97cbef48166d 39 #define MOTOR_START 0x04
TetsuyaKonno 0:97cbef48166d 40 #define MOTOR_STOP 0x05
TetsuyaKonno 0:97cbef48166d 41 #define MARK_T 0x06
TetsuyaKonno 0:97cbef48166d 42
TetsuyaKonno 0:97cbef48166d 43 //Define(NTSC-Video)
TetsuyaKonno 0:97cbef48166d 44 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 45 #define VIDEO_INPUT_CH (DisplayBase::VIDEO_INPUT_CHANNEL_0)
TetsuyaKonno 0:97cbef48166d 46 #define VIDEO_INT_TYPE (DisplayBase::INT_TYPE_S0_VFIELD)
TetsuyaKonno 0:97cbef48166d 47 #define DATA_SIZE_PER_PIC (2u)
TetsuyaKonno 0:97cbef48166d 48
TetsuyaKonno 0:97cbef48166d 49 /*! Frame buffer stride: Frame buffer stride should be set to a multiple of 32 or 128
TetsuyaKonno 0:97cbef48166d 50 in accordance with the frame buffer burst transfer mode. */
TetsuyaKonno 0:97cbef48166d 51 #define PIXEL_HW (320u) /* QVGA */
TetsuyaKonno 0:97cbef48166d 52 #define PIXEL_VW (240u) /* QVGA */
TetsuyaKonno 0:97cbef48166d 53 #define VIDEO_BUFFER_STRIDE (((PIXEL_HW * DATA_SIZE_PER_PIC) + 31u) & ~31u)
TetsuyaKonno 0:97cbef48166d 54 #define VIDEO_BUFFER_HEIGHT (PIXEL_VW)
TetsuyaKonno 0:97cbef48166d 55
TetsuyaKonno 0:97cbef48166d 56 //Constructor
TetsuyaKonno 0:97cbef48166d 57 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 58 Ticker interrput;
TetsuyaKonno 0:97cbef48166d 59 Serial pc(USBTX, USBRX);
TetsuyaKonno 0:97cbef48166d 60 DigitalOut LED_R(P6_13); /* LED1 on the GR-PEACH board */
TetsuyaKonno 0:97cbef48166d 61 DigitalOut LED_G(P6_14); /* LED2 on the GR-PEACH board */
TetsuyaKonno 0:97cbef48166d 62 DigitalOut LED_B(P6_15); /* LED3 on the GR-PEACH board */
TetsuyaKonno 0:97cbef48166d 63 DigitalOut USER_LED(P6_12); /* USER_LED on the GR-PEACH board */
TetsuyaKonno 0:97cbef48166d 64 DigitalIn user_botton(P6_0); /* SW1 on the GR-PEACH board */
TetsuyaKonno 0:97cbef48166d 65
TetsuyaKonno 0:97cbef48166d 66 DigitalIn push_sw(P2_13); /* SW1 on the Motor Drive board */
TetsuyaKonno 0:97cbef48166d 67 DigitalOut LED_3(P2_14); /* LED3 on the Motor Drive board */
TetsuyaKonno 0:97cbef48166d 68 DigitalOut LED_2(P2_15); /* LED2 on the Motor Drive board */
TetsuyaKonno 0:97cbef48166d 69
TetsuyaKonno 0:97cbef48166d 70 //Prototype(NTSC-video)
TetsuyaKonno 0:97cbef48166d 71 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 72 static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type);
TetsuyaKonno 0:97cbef48166d 73 static void WaitVfield(const int32_t wait_count);
TetsuyaKonno 0:97cbef48166d 74 static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type);
TetsuyaKonno 0:97cbef48166d 75 static void WaitVsync(const int32_t wait_count);
TetsuyaKonno 0:97cbef48166d 76
TetsuyaKonno 0:97cbef48166d 77 //Prototype
TetsuyaKonno 0:97cbef48166d 78 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 79 //Peripheral functions
TetsuyaKonno 0:97cbef48166d 80 void intTimer( void ); /* Interrupt fanction */
TetsuyaKonno 0:97cbef48166d 81
TetsuyaKonno 0:97cbef48166d 82 //GR-peach board
TetsuyaKonno 0:97cbef48166d 83 void led_rgb(int led);
TetsuyaKonno 0:97cbef48166d 84 void led_m_user( int led );
TetsuyaKonno 0:97cbef48166d 85 unsigned int user_button_get( void );
TetsuyaKonno 0:97cbef48166d 86 void led_m_set( int set );
TetsuyaKonno 0:97cbef48166d 87 void led_m_process( void ); /* Function for only interrupt */
TetsuyaKonno 0:97cbef48166d 88
TetsuyaKonno 0:97cbef48166d 89 //Motor drive board
TetsuyaKonno 0:97cbef48166d 90 void led_out(int led);
TetsuyaKonno 0:97cbef48166d 91 unsigned int pushsw_get( void );
TetsuyaKonno 0:97cbef48166d 92
TetsuyaKonno 0:97cbef48166d 93 //Prototype(Image process)
TetsuyaKonno 0:97cbef48166d 94 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 95 void Image_Extraction( unsigned char *buff_addr, unsigned char *Data_Y, int frame );
TetsuyaKonno 0:97cbef48166d 96 void Image_Reduction( unsigned char *Data_Y, int Data_W , unsigned char *Comp_Y, int Comp_M );
TetsuyaKonno 0:97cbef48166d 97 void Binarization_process( unsigned char *Comp_Y, unsigned char *Binary, long items, int threshold );
TetsuyaKonno 0:97cbef48166d 98
TetsuyaKonno 0:97cbef48166d 99 //Prototype(Mark detection process)
TetsuyaKonno 0:97cbef48166d 100 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 101 void Image_part_Extraction( unsigned char *Binary, int Width, int Xpix, int Ypix, unsigned char *Data_B, int x_size, int y_size );
TetsuyaKonno 0:97cbef48166d 102 double Standard_Deviation( unsigned char *data, double *Devi, int items );
TetsuyaKonno 0:97cbef48166d 103 double Covariance( double *Devi_A, double *Devi_B, int items );
TetsuyaKonno 0:97cbef48166d 104 int Judgement_ImageMatching( double covari, double SDevi_A, double SDevi_B );
TetsuyaKonno 0:97cbef48166d 105 void MarkDetect_process_T( void );
TetsuyaKonno 0:97cbef48166d 106 int MarkCheck_Triangle( int percentage );
TetsuyaKonno 0:97cbef48166d 107
TetsuyaKonno 0:97cbef48166d 108 //Prototype(Display Debug)
TetsuyaKonno 0:97cbef48166d 109 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 110 void ImageData_Serial_Out( unsigned char *Data_Y, int Width );
TetsuyaKonno 0:97cbef48166d 111 void ImageData_Serial_Out2( unsigned char *Data_Y, int Width );
TetsuyaKonno 0:97cbef48166d 112
TetsuyaKonno 0:97cbef48166d 113 //Globle variable (NTSC-video)
TetsuyaKonno 0:97cbef48166d 114 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 115 static uint8_t FrameBuffer_Video_A[VIDEO_BUFFER_STRIDE * VIDEO_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(16))); //16 bytes aligned!;
TetsuyaKonno 0:97cbef48166d 116 uint8_t * write_buff_addr = FrameBuffer_Video_A;
TetsuyaKonno 0:97cbef48166d 117 static volatile int32_t vsync_count;
TetsuyaKonno 0:97cbef48166d 118 static volatile int32_t vfield_count;
TetsuyaKonno 0:97cbef48166d 119 static volatile int32_t vfield_count2 = 1;
TetsuyaKonno 0:97cbef48166d 120 static volatile int32_t vfield_count2_buff;
TetsuyaKonno 0:97cbef48166d 121
TetsuyaKonno 0:97cbef48166d 122 //Globle variable for Image process
TetsuyaKonno 0:97cbef48166d 123 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 124 unsigned char ImageData_A[160*120];
TetsuyaKonno 0:97cbef48166d 125 unsigned char ImageComp_A[20*15];
TetsuyaKonno 0:97cbef48166d 126 unsigned char ImageBinary[20*15];
TetsuyaKonno 0:97cbef48166d 127
TetsuyaKonno 0:97cbef48166d 128 //Globle variable for Digital sensor process
TetsuyaKonno 0:97cbef48166d 129 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 130 volatile int Sensor_X[8][6];
TetsuyaKonno 0:97cbef48166d 131 volatile unsigned char sensor_value;
TetsuyaKonno 0:97cbef48166d 132
TetsuyaKonno 0:97cbef48166d 133 //Globle variable for Mark detection process
TetsuyaKonno 0:97cbef48166d 134 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 135 double TempDevi_Triangle[15];
TetsuyaKonno 0:97cbef48166d 136 unsigned char TempBinary_Triangle[15] = {0,1,1,1,0,
TetsuyaKonno 0:97cbef48166d 137 0,0,1,0,0,
TetsuyaKonno 0:97cbef48166d 138 0,0,0,0,0};
TetsuyaKonno 0:97cbef48166d 139
TetsuyaKonno 0:97cbef48166d 140 double NowDevi[15];
TetsuyaKonno 0:97cbef48166d 141 unsigned char NowImageBinary[15];
TetsuyaKonno 0:97cbef48166d 142
TetsuyaKonno 0:97cbef48166d 143 volatile double retDevi_Triangle;
TetsuyaKonno 0:97cbef48166d 144
TetsuyaKonno 0:97cbef48166d 145 volatile double retDevi;
TetsuyaKonno 0:97cbef48166d 146 volatile double retCovari;
TetsuyaKonno 0:97cbef48166d 147 volatile int retJudgeIM;
TetsuyaKonno 0:97cbef48166d 148 volatile int retJudgeIM_Max[1];
TetsuyaKonno 0:97cbef48166d 149
TetsuyaKonno 0:97cbef48166d 150 int Xt, Yt;
TetsuyaKonno 0:97cbef48166d 151
TetsuyaKonno 0:97cbef48166d 152 //Globle variable for led fanction
TetsuyaKonno 0:97cbef48166d 153 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 154 volatile int led_set; /* Status */
TetsuyaKonno 0:97cbef48166d 155
TetsuyaKonno 0:97cbef48166d 156 // LED, OnTime, OffTime,
TetsuyaKonno 0:97cbef48166d 157 volatile int led_data[10][3]= {LED_RED, 50, 50, /* ERROR */
TetsuyaKonno 0:97cbef48166d 158 LED_RED, 500, 0, /* STOP */
TetsuyaKonno 0:97cbef48166d 159 LED_GREEN, 500, 500, /* RUN */
TetsuyaKonno 0:97cbef48166d 160 LED_BLUE, 50, 50, /* DEBUG */
TetsuyaKonno 0:97cbef48166d 161 LED_GREEN, 1, 0, /* MOTOR_START */
TetsuyaKonno 0:97cbef48166d 162 LED_RED, 1, 0, /* MOTOR_STOP */
TetsuyaKonno 0:97cbef48166d 163 LED_WHITE, 500, 500}; /* MARK_T */
TetsuyaKonno 0:97cbef48166d 164
TetsuyaKonno 0:97cbef48166d 165 //Globle variable for Trace program
TetsuyaKonno 0:97cbef48166d 166 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 167 volatile unsigned long cnt0; /* Used by timer function */
TetsuyaKonno 0:97cbef48166d 168 volatile unsigned long cnt1; /* Used within main */
TetsuyaKonno 0:97cbef48166d 169
TetsuyaKonno 0:97cbef48166d 170 //******************************************************************//
TetsuyaKonno 0:97cbef48166d 171 // Main function
TetsuyaKonno 0:97cbef48166d 172 //*******************************************************************/
TetsuyaKonno 0:97cbef48166d 173 int main( void )
TetsuyaKonno 0:97cbef48166d 174 {
TetsuyaKonno 0:97cbef48166d 175 /* NTSC-Video */
TetsuyaKonno 0:97cbef48166d 176 DisplayBase::graphics_error_t error;
TetsuyaKonno 0:97cbef48166d 177
TetsuyaKonno 0:97cbef48166d 178 /* Create DisplayBase object */
TetsuyaKonno 0:97cbef48166d 179 DisplayBase Display;
TetsuyaKonno 0:97cbef48166d 180
TetsuyaKonno 0:97cbef48166d 181 /* Graphics initialization process */
TetsuyaKonno 0:97cbef48166d 182 error = Display.Graphics_init(NULL);
TetsuyaKonno 0:97cbef48166d 183 if (error != DisplayBase::GRAPHICS_OK) {
TetsuyaKonno 0:97cbef48166d 184 printf("Line %d, error %d\n", __LINE__, error);
TetsuyaKonno 0:97cbef48166d 185 while (1);
TetsuyaKonno 0:97cbef48166d 186 }
TetsuyaKonno 0:97cbef48166d 187
TetsuyaKonno 0:97cbef48166d 188 error = Display.Graphics_Video_init( DisplayBase::INPUT_SEL_VDEC, NULL);
TetsuyaKonno 0:97cbef48166d 189 if( error != DisplayBase::GRAPHICS_OK ) {
TetsuyaKonno 0:97cbef48166d 190 while(1);
TetsuyaKonno 0:97cbef48166d 191 }
TetsuyaKonno 0:97cbef48166d 192
TetsuyaKonno 0:97cbef48166d 193 /* Interrupt callback function setting (Vsync signal input to scaler 0) */
TetsuyaKonno 0:97cbef48166d 194 error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_VI_VSYNC, 0, IntCallbackFunc_Vsync);
TetsuyaKonno 0:97cbef48166d 195 if (error != DisplayBase::GRAPHICS_OK) {
TetsuyaKonno 0:97cbef48166d 196 printf("Line %d, error %d\n", __LINE__, error);
TetsuyaKonno 0:97cbef48166d 197 while (1);
TetsuyaKonno 0:97cbef48166d 198 }
TetsuyaKonno 0:97cbef48166d 199
TetsuyaKonno 0:97cbef48166d 200 /* Video capture setting (progressive form fixed) */
TetsuyaKonno 0:97cbef48166d 201 error = Display.Video_Write_Setting(
TetsuyaKonno 0:97cbef48166d 202 VIDEO_INPUT_CH,
TetsuyaKonno 0:97cbef48166d 203 DisplayBase::COL_SYS_NTSC_358,
TetsuyaKonno 0:97cbef48166d 204 write_buff_addr,
TetsuyaKonno 0:97cbef48166d 205 VIDEO_BUFFER_STRIDE,
TetsuyaKonno 0:97cbef48166d 206 DisplayBase::VIDEO_FORMAT_YCBCR422,
TetsuyaKonno 0:97cbef48166d 207 DisplayBase::WR_RD_WRSWA_32_16BIT,
TetsuyaKonno 0:97cbef48166d 208 PIXEL_VW,
TetsuyaKonno 0:97cbef48166d 209 PIXEL_HW
TetsuyaKonno 0:97cbef48166d 210 );
TetsuyaKonno 0:97cbef48166d 211 if (error != DisplayBase::GRAPHICS_OK) {
TetsuyaKonno 0:97cbef48166d 212 printf("Line %d, error %d\n", __LINE__, error);
TetsuyaKonno 0:97cbef48166d 213 while (1);
TetsuyaKonno 0:97cbef48166d 214 }
TetsuyaKonno 0:97cbef48166d 215
TetsuyaKonno 0:97cbef48166d 216 /* Interrupt callback function setting (Field end signal for recording function in scaler 0) */
TetsuyaKonno 0:97cbef48166d 217 error = Display.Graphics_Irq_Handler_Set(VIDEO_INT_TYPE, 0, IntCallbackFunc_Vfield);
TetsuyaKonno 0:97cbef48166d 218 if (error != DisplayBase::GRAPHICS_OK) {
TetsuyaKonno 0:97cbef48166d 219 printf("Line %d, error %d\n", __LINE__, error);
TetsuyaKonno 0:97cbef48166d 220 while (1);
TetsuyaKonno 0:97cbef48166d 221 }
TetsuyaKonno 0:97cbef48166d 222
TetsuyaKonno 0:97cbef48166d 223 /* Video write process start */
TetsuyaKonno 0:97cbef48166d 224 error = Display.Video_Start (VIDEO_INPUT_CH);
TetsuyaKonno 0:97cbef48166d 225 if (error != DisplayBase::GRAPHICS_OK) {
TetsuyaKonno 0:97cbef48166d 226 printf("Line %d, error %d\n", __LINE__, error);
TetsuyaKonno 0:97cbef48166d 227 while (1);
TetsuyaKonno 0:97cbef48166d 228 }
TetsuyaKonno 0:97cbef48166d 229
TetsuyaKonno 0:97cbef48166d 230 /* Video write process stop */
TetsuyaKonno 0:97cbef48166d 231 error = Display.Video_Stop (VIDEO_INPUT_CH);
TetsuyaKonno 0:97cbef48166d 232 if (error != DisplayBase::GRAPHICS_OK) {
TetsuyaKonno 0:97cbef48166d 233 printf("Line %d, error %d\n", __LINE__, error);
TetsuyaKonno 0:97cbef48166d 234 while (1);
TetsuyaKonno 0:97cbef48166d 235 }
TetsuyaKonno 0:97cbef48166d 236
TetsuyaKonno 0:97cbef48166d 237 /* Video write process start */
TetsuyaKonno 0:97cbef48166d 238 error = Display.Video_Start (VIDEO_INPUT_CH);
TetsuyaKonno 0:97cbef48166d 239 if (error != DisplayBase::GRAPHICS_OK) {
TetsuyaKonno 0:97cbef48166d 240 printf("Line %d, error %d\n", __LINE__, error);
TetsuyaKonno 0:97cbef48166d 241 while (1);
TetsuyaKonno 0:97cbef48166d 242 }
TetsuyaKonno 0:97cbef48166d 243
TetsuyaKonno 0:97cbef48166d 244 /* Wait vsync to update resister */
TetsuyaKonno 0:97cbef48166d 245 WaitVsync(1);
TetsuyaKonno 0:97cbef48166d 246
TetsuyaKonno 0:97cbef48166d 247 /* Wait 2 Vfield(Top or bottom field) */
TetsuyaKonno 0:97cbef48166d 248 WaitVfield(2);
TetsuyaKonno 0:97cbef48166d 249
TetsuyaKonno 0:97cbef48166d 250 /* Initialize MCU functions */
TetsuyaKonno 0:97cbef48166d 251 interrput.attach(&intTimer, 0.001);
TetsuyaKonno 0:97cbef48166d 252 pc.baud(230400);
TetsuyaKonno 0:97cbef48166d 253
TetsuyaKonno 0:97cbef48166d 254 /* Initialize Micon Car state */
TetsuyaKonno 0:97cbef48166d 255 led_out( 0x0 );
TetsuyaKonno 0:97cbef48166d 256
TetsuyaKonno 0:97cbef48166d 257 /* wait to stabilize NTSC signal (about 170ms) */
TetsuyaKonno 0:97cbef48166d 258 wait(0.2);
TetsuyaKonno 0:97cbef48166d 259
TetsuyaKonno 0:97cbef48166d 260 /* Initialize Mark detection */
TetsuyaKonno 0:97cbef48166d 261 retDevi_Triangle = Standard_Deviation( TempBinary_Triangle, TempDevi_Triangle, 15 );
TetsuyaKonno 0:97cbef48166d 262
TetsuyaKonno 0:97cbef48166d 263 wait(0.1);
TetsuyaKonno 0:97cbef48166d 264 led_m_set( DEBUG );
TetsuyaKonno 0:97cbef48166d 265 pc.printf( "Please push the SW ( on the Motor drive board )\n\r" );
TetsuyaKonno 0:97cbef48166d 266 pc.printf( "\n\r" );
TetsuyaKonno 0:97cbef48166d 267 while( pushsw_get() );
TetsuyaKonno 0:97cbef48166d 268 wait(0.5);
TetsuyaKonno 0:97cbef48166d 269 while( !pushsw_get() );
TetsuyaKonno 0:97cbef48166d 270 while( 1 ){
TetsuyaKonno 0:97cbef48166d 271 ImageData_Serial_Out2( ImageBinary, 20 );
TetsuyaKonno 0:97cbef48166d 272 }
TetsuyaKonno 0:97cbef48166d 273 }
TetsuyaKonno 0:97cbef48166d 274
TetsuyaKonno 0:97cbef48166d 275 //******************************************************************//
TetsuyaKonno 0:97cbef48166d 276 // @brief Interrupt callback function
TetsuyaKonno 0:97cbef48166d 277 // @param[in] int_type : VDC5 interrupt type
TetsuyaKonno 0:97cbef48166d 278 // @retval None
TetsuyaKonno 0:97cbef48166d 279 //*******************************************************************/
TetsuyaKonno 0:97cbef48166d 280 static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type)
TetsuyaKonno 0:97cbef48166d 281 {
TetsuyaKonno 0:97cbef48166d 282 if (vfield_count > 0) {
TetsuyaKonno 0:97cbef48166d 283 vfield_count--;
TetsuyaKonno 0:97cbef48166d 284 }
TetsuyaKonno 0:97cbef48166d 285 /* top or bottom (Change) */
TetsuyaKonno 0:97cbef48166d 286 if ( vfield_count2 == 0 ) vfield_count2 = 1;
TetsuyaKonno 0:97cbef48166d 287 else if ( vfield_count2 == 1 ) vfield_count2 = 0;
TetsuyaKonno 0:97cbef48166d 288 }
TetsuyaKonno 0:97cbef48166d 289
TetsuyaKonno 0:97cbef48166d 290 //******************************************************************//
TetsuyaKonno 0:97cbef48166d 291 // @brief Wait for the specified number of times Vsync occurs
TetsuyaKonno 0:97cbef48166d 292 // @param[in] wait_count : Wait count
TetsuyaKonno 0:97cbef48166d 293 // @retval None
TetsuyaKonno 0:97cbef48166d 294 //*******************************************************************/
TetsuyaKonno 0:97cbef48166d 295 static void WaitVfield(const int32_t wait_count)
TetsuyaKonno 0:97cbef48166d 296 {
TetsuyaKonno 0:97cbef48166d 297 vfield_count = wait_count;
TetsuyaKonno 0:97cbef48166d 298 while (vfield_count > 0) {
TetsuyaKonno 0:97cbef48166d 299 /* Do nothing */
TetsuyaKonno 0:97cbef48166d 300 }
TetsuyaKonno 0:97cbef48166d 301 }
TetsuyaKonno 0:97cbef48166d 302
TetsuyaKonno 0:97cbef48166d 303 //******************************************************************//
TetsuyaKonno 0:97cbef48166d 304 // @brief Interrupt callback function for Vsync interruption
TetsuyaKonno 0:97cbef48166d 305 // @param[in] int_type : VDC5 interrupt type
TetsuyaKonno 0:97cbef48166d 306 // @retval None
TetsuyaKonno 0:97cbef48166d 307 //*******************************************************************/
TetsuyaKonno 0:97cbef48166d 308 static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type)
TetsuyaKonno 0:97cbef48166d 309 {
TetsuyaKonno 0:97cbef48166d 310 if (vsync_count > 0) {
TetsuyaKonno 0:97cbef48166d 311 vsync_count--;
TetsuyaKonno 0:97cbef48166d 312 }
TetsuyaKonno 0:97cbef48166d 313 }
TetsuyaKonno 0:97cbef48166d 314
TetsuyaKonno 0:97cbef48166d 315 //******************************************************************//
TetsuyaKonno 0:97cbef48166d 316 // @brief Wait for the specified number of times Vsync occurs
TetsuyaKonno 0:97cbef48166d 317 // @param[in] wait_count : Wait count
TetsuyaKonno 0:97cbef48166d 318 // @retval None
TetsuyaKonno 0:97cbef48166d 319 //*******************************************************************/
TetsuyaKonno 0:97cbef48166d 320 static void WaitVsync(const int32_t wait_count)
TetsuyaKonno 0:97cbef48166d 321 {
TetsuyaKonno 0:97cbef48166d 322 vsync_count = wait_count;
TetsuyaKonno 0:97cbef48166d 323 while (vsync_count > 0) {
TetsuyaKonno 0:97cbef48166d 324 /* Do nothing */
TetsuyaKonno 0:97cbef48166d 325 }
TetsuyaKonno 0:97cbef48166d 326 }
TetsuyaKonno 0:97cbef48166d 327
TetsuyaKonno 0:97cbef48166d 328 //******************************************************************//
TetsuyaKonno 0:97cbef48166d 329 // Interrupt function( intTimer )
TetsuyaKonno 0:97cbef48166d 330 //*******************************************************************/
TetsuyaKonno 0:97cbef48166d 331 void intTimer( void )
TetsuyaKonno 0:97cbef48166d 332 {
TetsuyaKonno 0:97cbef48166d 333 static int counter = 0;
TetsuyaKonno 0:97cbef48166d 334
TetsuyaKonno 0:97cbef48166d 335 cnt0++;
TetsuyaKonno 0:97cbef48166d 336 cnt1++;
TetsuyaKonno 0:97cbef48166d 337
TetsuyaKonno 0:97cbef48166d 338 /* field check */
TetsuyaKonno 0:97cbef48166d 339 if( vfield_count2 == vfield_count2_buff ) {
TetsuyaKonno 0:97cbef48166d 340 vfield_count2_buff = vfield_count2;
TetsuyaKonno 0:97cbef48166d 341 }
TetsuyaKonno 0:97cbef48166d 342 /* Top field */
TetsuyaKonno 0:97cbef48166d 343 if( !vfield_count2 ) {
TetsuyaKonno 0:97cbef48166d 344 led_m_user( 1 );
TetsuyaKonno 0:97cbef48166d 345 switch( counter++ ) {
TetsuyaKonno 0:97cbef48166d 346 case 0:
TetsuyaKonno 0:97cbef48166d 347 Image_Extraction( write_buff_addr, ImageData_A, vfield_count2 );
TetsuyaKonno 0:97cbef48166d 348 break;
TetsuyaKonno 0:97cbef48166d 349 case 1:
TetsuyaKonno 0:97cbef48166d 350 Image_Extraction( write_buff_addr, ImageData_A, vfield_count2 );
TetsuyaKonno 0:97cbef48166d 351 break;
TetsuyaKonno 0:97cbef48166d 352 case 2:
TetsuyaKonno 0:97cbef48166d 353 Image_Reduction( ImageData_A, 160, ImageComp_A, 8 );
TetsuyaKonno 0:97cbef48166d 354 break;
TetsuyaKonno 0:97cbef48166d 355 case 3:
TetsuyaKonno 0:97cbef48166d 356 Image_Reduction( ImageData_A, 160, ImageComp_A, 8 );
TetsuyaKonno 0:97cbef48166d 357 break;
TetsuyaKonno 0:97cbef48166d 358 case 4:
TetsuyaKonno 0:97cbef48166d 359 Binarization_process( ImageComp_A, ImageBinary, 20*15, 128 );
TetsuyaKonno 0:97cbef48166d 360 break;
TetsuyaKonno 0:97cbef48166d 361 case 5:
TetsuyaKonno 0:97cbef48166d 362 /* Trace by image processing */
TetsuyaKonno 0:97cbef48166d 363 break;
TetsuyaKonno 0:97cbef48166d 364 case 6:
TetsuyaKonno 0:97cbef48166d 365 //MarkCheck_Triangle
TetsuyaKonno 0:97cbef48166d 366 MarkDetect_process_T();
TetsuyaKonno 0:97cbef48166d 367 break;
TetsuyaKonno 0:97cbef48166d 368 case 15:
TetsuyaKonno 0:97cbef48166d 369 counter = 0;
TetsuyaKonno 0:97cbef48166d 370 break;
TetsuyaKonno 0:97cbef48166d 371 default:
TetsuyaKonno 0:97cbef48166d 372 break;
TetsuyaKonno 0:97cbef48166d 373 }
TetsuyaKonno 0:97cbef48166d 374 }
TetsuyaKonno 0:97cbef48166d 375 /* bottom field */
TetsuyaKonno 0:97cbef48166d 376 else {
TetsuyaKonno 0:97cbef48166d 377 led_m_user( 0 );
TetsuyaKonno 0:97cbef48166d 378 switch( counter++ ) {
TetsuyaKonno 0:97cbef48166d 379 case 0:
TetsuyaKonno 0:97cbef48166d 380 Image_Extraction( write_buff_addr, ImageData_A, vfield_count2 );
TetsuyaKonno 0:97cbef48166d 381 break;
TetsuyaKonno 0:97cbef48166d 382 case 1:
TetsuyaKonno 0:97cbef48166d 383 Image_Extraction( write_buff_addr, ImageData_A, vfield_count2 );
TetsuyaKonno 0:97cbef48166d 384 break;
TetsuyaKonno 0:97cbef48166d 385 case 2:
TetsuyaKonno 0:97cbef48166d 386 Image_Reduction( ImageData_A, 160, ImageComp_A, 8 );
TetsuyaKonno 0:97cbef48166d 387 break;
TetsuyaKonno 0:97cbef48166d 388 case 3:
TetsuyaKonno 0:97cbef48166d 389 Image_Reduction( ImageData_A, 160, ImageComp_A, 8 );
TetsuyaKonno 0:97cbef48166d 390 break;
TetsuyaKonno 0:97cbef48166d 391 case 4:
TetsuyaKonno 0:97cbef48166d 392 Binarization_process( ImageComp_A, ImageBinary, 20*15, 128 );
TetsuyaKonno 0:97cbef48166d 393 break;
TetsuyaKonno 0:97cbef48166d 394 case 5:
TetsuyaKonno 0:97cbef48166d 395 /* Trace by image processing */
TetsuyaKonno 0:97cbef48166d 396 break;
TetsuyaKonno 0:97cbef48166d 397 case 6:
TetsuyaKonno 0:97cbef48166d 398 //MarkCheck_Triangle
TetsuyaKonno 0:97cbef48166d 399 MarkDetect_process_T();
TetsuyaKonno 0:97cbef48166d 400 break;
TetsuyaKonno 0:97cbef48166d 401 case 15:
TetsuyaKonno 0:97cbef48166d 402 counter = 0;
TetsuyaKonno 0:97cbef48166d 403 break;
TetsuyaKonno 0:97cbef48166d 404 default:
TetsuyaKonno 0:97cbef48166d 405 break;
TetsuyaKonno 0:97cbef48166d 406 }
TetsuyaKonno 0:97cbef48166d 407 }
TetsuyaKonno 0:97cbef48166d 408
TetsuyaKonno 0:97cbef48166d 409 /* LED processing */
TetsuyaKonno 0:97cbef48166d 410 led_m_process();
TetsuyaKonno 0:97cbef48166d 411 }
TetsuyaKonno 0:97cbef48166d 412
TetsuyaKonno 0:97cbef48166d 413 //******************************************************************//
TetsuyaKonno 0:97cbef48166d 414 // functions ( on GR-PEACH board )
TetsuyaKonno 0:97cbef48166d 415 //*******************************************************************/
TetsuyaKonno 0:97cbef48166d 416 //led_rgb Function
TetsuyaKonno 0:97cbef48166d 417 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 418 void led_rgb(int led)
TetsuyaKonno 0:97cbef48166d 419 {
TetsuyaKonno 0:97cbef48166d 420 LED_R = led & 0x1;
TetsuyaKonno 0:97cbef48166d 421 LED_G = (led >> 1 ) & 0x1;
TetsuyaKonno 0:97cbef48166d 422 LED_B = (led >> 2 ) & 0x1;
TetsuyaKonno 0:97cbef48166d 423 }
TetsuyaKonno 0:97cbef48166d 424
TetsuyaKonno 0:97cbef48166d 425 //user_button_get Function
TetsuyaKonno 0:97cbef48166d 426 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 427 unsigned int user_button_get( void )
TetsuyaKonno 0:97cbef48166d 428 {
TetsuyaKonno 0:97cbef48166d 429 return (~user_botton) & 0x1; /* Read ports with switches */
TetsuyaKonno 0:97cbef48166d 430 }
TetsuyaKonno 0:97cbef48166d 431
TetsuyaKonno 0:97cbef48166d 432 //led_m_user Function
TetsuyaKonno 0:97cbef48166d 433 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 434 void led_m_user( int led )
TetsuyaKonno 0:97cbef48166d 435 {
TetsuyaKonno 0:97cbef48166d 436 USER_LED = led & 0x01;
TetsuyaKonno 0:97cbef48166d 437 }
TetsuyaKonno 0:97cbef48166d 438
TetsuyaKonno 0:97cbef48166d 439 //Lled_m_set Function
TetsuyaKonno 0:97cbef48166d 440 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 441 void led_m_set( int set )
TetsuyaKonno 0:97cbef48166d 442 {
TetsuyaKonno 0:97cbef48166d 443 led_set = set;
TetsuyaKonno 0:97cbef48166d 444 }
TetsuyaKonno 0:97cbef48166d 445
TetsuyaKonno 0:97cbef48166d 446 //led_m_process Function for only interrupt
TetsuyaKonno 0:97cbef48166d 447 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 448 void led_m_process( void )
TetsuyaKonno 0:97cbef48166d 449 {
TetsuyaKonno 0:97cbef48166d 450 static unsigned long led_timer;
TetsuyaKonno 0:97cbef48166d 451
TetsuyaKonno 0:97cbef48166d 452 led_timer++;
TetsuyaKonno 0:97cbef48166d 453
TetsuyaKonno 0:97cbef48166d 454 /* Display */
TetsuyaKonno 0:97cbef48166d 455 if( led_timer < led_data[led_set][1] ) led_rgb( led_data[led_set][0] );
TetsuyaKonno 0:97cbef48166d 456 else if( led_timer < ( led_data[led_set][1] + led_data[led_set][2] ) ) led_rgb( LED_OFF );
TetsuyaKonno 0:97cbef48166d 457 else led_timer = 0;
TetsuyaKonno 0:97cbef48166d 458 }
TetsuyaKonno 0:97cbef48166d 459
TetsuyaKonno 0:97cbef48166d 460 //******************************************************************//
TetsuyaKonno 0:97cbef48166d 461 // functions ( on Motor drive board )
TetsuyaKonno 0:97cbef48166d 462 //*******************************************************************/
TetsuyaKonno 0:97cbef48166d 463 //led_out Function
TetsuyaKonno 0:97cbef48166d 464 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 465 void led_out(int led)
TetsuyaKonno 0:97cbef48166d 466 {
TetsuyaKonno 0:97cbef48166d 467 led = ~led;
TetsuyaKonno 0:97cbef48166d 468 LED_3 = led & 0x1;
TetsuyaKonno 0:97cbef48166d 469 LED_2 = ( led >> 1 ) & 0x1;
TetsuyaKonno 0:97cbef48166d 470 }
TetsuyaKonno 0:97cbef48166d 471
TetsuyaKonno 0:97cbef48166d 472 //pushsw_get Function
TetsuyaKonno 0:97cbef48166d 473 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 474 unsigned int pushsw_get( void )
TetsuyaKonno 0:97cbef48166d 475 {
TetsuyaKonno 0:97cbef48166d 476 return (~push_sw) & 0x1; /* Read ports with switches */
TetsuyaKonno 0:97cbef48166d 477 }
TetsuyaKonno 0:97cbef48166d 478
TetsuyaKonno 0:97cbef48166d 479 //******************************************************************//
TetsuyaKonno 0:97cbef48166d 480 // Image process functions
TetsuyaKonno 0:97cbef48166d 481 //*******************************************************************/
TetsuyaKonno 0:97cbef48166d 482 //Image Data YCbCr -> Y(320*240pix) -> Y(160*120)
TetsuyaKonno 0:97cbef48166d 483 //frame 0 : Top field
TetsuyaKonno 0:97cbef48166d 484 //frame 1 : Bottom field
TetsuyaKonno 0:97cbef48166d 485 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 486 void Image_Extraction( unsigned char *buff_addr, unsigned char *Data_Y, int frame )
TetsuyaKonno 0:97cbef48166d 487 {
TetsuyaKonno 0:97cbef48166d 488 static int Xp, Yp, inc, Data_Y_buff;
TetsuyaKonno 0:97cbef48166d 489 static int counter = 0;
TetsuyaKonno 0:97cbef48166d 490
TetsuyaKonno 0:97cbef48166d 491 // Distributed processing
TetsuyaKonno 0:97cbef48166d 492 switch( counter++ ) {
TetsuyaKonno 0:97cbef48166d 493 case 0:
TetsuyaKonno 0:97cbef48166d 494 for( Yp = frame, inc = 0; Yp < 120; Yp+=2 ){
TetsuyaKonno 0:97cbef48166d 495 for( Xp = 0; Xp < 640; Xp+=4, inc++ ){
TetsuyaKonno 0:97cbef48166d 496 Data_Y_buff = (int)buff_addr[(Xp+0)+(640*Yp)];
TetsuyaKonno 0:97cbef48166d 497 Data_Y_buff += (int)buff_addr[(Xp+2)+(640*Yp)];
TetsuyaKonno 0:97cbef48166d 498 Data_Y[inc] = Data_Y_buff >> 1;
TetsuyaKonno 0:97cbef48166d 499 }
TetsuyaKonno 0:97cbef48166d 500 }
TetsuyaKonno 0:97cbef48166d 501 break;
TetsuyaKonno 0:97cbef48166d 502 case 1:
TetsuyaKonno 0:97cbef48166d 503 for( /* None */ ; Yp < 240; Yp+=2 ){
TetsuyaKonno 0:97cbef48166d 504 for( Xp = 0; Xp < 640; Xp+=4, inc++ ){
TetsuyaKonno 0:97cbef48166d 505 Data_Y_buff = (int)buff_addr[(Xp+0)+(640*Yp)];
TetsuyaKonno 0:97cbef48166d 506 Data_Y_buff += (int)buff_addr[(Xp+2)+(640*Yp)];
TetsuyaKonno 0:97cbef48166d 507 Data_Y[inc] = Data_Y_buff >> 1;
TetsuyaKonno 0:97cbef48166d 508 }
TetsuyaKonno 0:97cbef48166d 509 }
TetsuyaKonno 0:97cbef48166d 510 counter = 0;
TetsuyaKonno 0:97cbef48166d 511 break;
TetsuyaKonno 0:97cbef48166d 512 default:
TetsuyaKonno 0:97cbef48166d 513 break;
TetsuyaKonno 0:97cbef48166d 514 }
TetsuyaKonno 0:97cbef48166d 515 }
TetsuyaKonno 0:97cbef48166d 516
TetsuyaKonno 0:97cbef48166d 517 //Image_Reduction Function ( Averaging processing )
TetsuyaKonno 0:97cbef48166d 518 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 519 void Image_Reduction( unsigned char *Data_Y, int Data_W , unsigned char *Comp_Y, int Comp_M )
TetsuyaKonno 0:97cbef48166d 520 {
TetsuyaKonno 0:97cbef48166d 521 int Data_H, Pixel_T, Pixel_D;
TetsuyaKonno 0:97cbef48166d 522 int x, y;
TetsuyaKonno 0:97cbef48166d 523 static int Xp, Yp, inc;
TetsuyaKonno 0:97cbef48166d 524 static int counter = 0;
TetsuyaKonno 0:97cbef48166d 525
TetsuyaKonno 0:97cbef48166d 526 Data_H = (Data_W / (double)4) * 3;
TetsuyaKonno 0:97cbef48166d 527 Pixel_D = Comp_M * Comp_M;
TetsuyaKonno 0:97cbef48166d 528
TetsuyaKonno 0:97cbef48166d 529 switch( counter++ ) {
TetsuyaKonno 0:97cbef48166d 530 case 0:
TetsuyaKonno 0:97cbef48166d 531 for( Yp = 0, inc = 0; Yp < ( Data_H / 2); Yp+=Comp_M ){
TetsuyaKonno 0:97cbef48166d 532 for( Xp = 0; Xp < Data_W; Xp+=Comp_M, inc++ ){
TetsuyaKonno 0:97cbef48166d 533 Pixel_T = 0;
TetsuyaKonno 0:97cbef48166d 534 for( y = 0; y < Comp_M; y++ ){
TetsuyaKonno 0:97cbef48166d 535 for( x = 0; x < Comp_M; x++ ){
TetsuyaKonno 0:97cbef48166d 536 Pixel_T += Data_Y[( Xp + x ) + (( Yp + y ) * Data_W )];
TetsuyaKonno 0:97cbef48166d 537 }
TetsuyaKonno 0:97cbef48166d 538 }
TetsuyaKonno 0:97cbef48166d 539 Comp_Y[inc] = Pixel_T / Pixel_D;
TetsuyaKonno 0:97cbef48166d 540 }
TetsuyaKonno 0:97cbef48166d 541 }
TetsuyaKonno 0:97cbef48166d 542 break;
TetsuyaKonno 0:97cbef48166d 543 case 1:
TetsuyaKonno 0:97cbef48166d 544 for( /* None */ ; Yp < Data_H ; Yp+=Comp_M ){
TetsuyaKonno 0:97cbef48166d 545 for( Xp = 0; Xp < Data_W; Xp+=Comp_M, inc++ ){
TetsuyaKonno 0:97cbef48166d 546 Pixel_T = 0;
TetsuyaKonno 0:97cbef48166d 547 for( y = 0; y < Comp_M; y++ ){
TetsuyaKonno 0:97cbef48166d 548 for( x = 0; x < Comp_M; x++ ){
TetsuyaKonno 0:97cbef48166d 549 Pixel_T += Data_Y[( Xp + x ) + (( Yp + y ) * Data_W )];
TetsuyaKonno 0:97cbef48166d 550 }
TetsuyaKonno 0:97cbef48166d 551 }
TetsuyaKonno 0:97cbef48166d 552 Comp_Y[inc] = Pixel_T / Pixel_D;
TetsuyaKonno 0:97cbef48166d 553 }
TetsuyaKonno 0:97cbef48166d 554 }
TetsuyaKonno 0:97cbef48166d 555 counter = 0;
TetsuyaKonno 0:97cbef48166d 556 break;
TetsuyaKonno 0:97cbef48166d 557 default:
TetsuyaKonno 0:97cbef48166d 558 break;
TetsuyaKonno 0:97cbef48166d 559 }
TetsuyaKonno 0:97cbef48166d 560 }
TetsuyaKonno 0:97cbef48166d 561
TetsuyaKonno 0:97cbef48166d 562 // Binarization_process Function
TetsuyaKonno 0:97cbef48166d 563 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 564 void Binarization_process( unsigned char *Comp_Y, unsigned char *Binary, long items, int threshold )
TetsuyaKonno 0:97cbef48166d 565 {
TetsuyaKonno 0:97cbef48166d 566 int i;
TetsuyaKonno 0:97cbef48166d 567
TetsuyaKonno 0:97cbef48166d 568 for( i = 0; i < items; i++ ) {
TetsuyaKonno 0:97cbef48166d 569 if( Comp_Y[i] >= threshold ) Binary[i] = 1;
TetsuyaKonno 0:97cbef48166d 570 else Binary[i] = 0;
TetsuyaKonno 0:97cbef48166d 571 }
TetsuyaKonno 0:97cbef48166d 572 }
TetsuyaKonno 0:97cbef48166d 573
TetsuyaKonno 0:97cbef48166d 574 //******************************************************************//
TetsuyaKonno 0:97cbef48166d 575 // Mark detect functions
TetsuyaKonno 0:97cbef48166d 576 //*******************************************************************/
TetsuyaKonno 0:97cbef48166d 577 // Extract_Image
TetsuyaKonno 0:97cbef48166d 578 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 579 void Image_part_Extraction( unsigned char *Binary, int Width, int Xpix, int Ypix, unsigned char *Data_B, int x_size, int y_size )
TetsuyaKonno 0:97cbef48166d 580 {
TetsuyaKonno 0:97cbef48166d 581 int x, y;
TetsuyaKonno 0:97cbef48166d 582 for( y = 0; y < y_size; y++ ) {
TetsuyaKonno 0:97cbef48166d 583 for( x = 0; x < x_size; x++ ) {
TetsuyaKonno 0:97cbef48166d 584 Data_B[ x + ( y * x_size ) ] = Binary[ (Xpix + x) + ( (Ypix + y) * Width ) ];
TetsuyaKonno 0:97cbef48166d 585 }
TetsuyaKonno 0:97cbef48166d 586 }
TetsuyaKonno 0:97cbef48166d 587 }
TetsuyaKonno 0:97cbef48166d 588
TetsuyaKonno 0:97cbef48166d 589 // Standard deviation
TetsuyaKonno 0:97cbef48166d 590 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 591 double Standard_Deviation( unsigned char *data, double *Devi, int items )
TetsuyaKonno 0:97cbef48166d 592 {
TetsuyaKonno 0:97cbef48166d 593 int i;
TetsuyaKonno 0:97cbef48166d 594 double iRet_A, iRet_C, iRet_D;
TetsuyaKonno 0:97cbef48166d 595
TetsuyaKonno 0:97cbef48166d 596 /* A 合計値 平均化 */
TetsuyaKonno 0:97cbef48166d 597 iRet_A = 0;
TetsuyaKonno 0:97cbef48166d 598 for( i = 0; i < items; i++ ) {
TetsuyaKonno 0:97cbef48166d 599 iRet_A += data[i];
TetsuyaKonno 0:97cbef48166d 600 }
TetsuyaKonno 0:97cbef48166d 601 iRet_A /= items;
TetsuyaKonno 0:97cbef48166d 602
TetsuyaKonno 0:97cbef48166d 603 /* B 偏差値 */
TetsuyaKonno 0:97cbef48166d 604 for( i = 0; i < items; i++ ) {
TetsuyaKonno 0:97cbef48166d 605 Devi[i] = data[i] - iRet_A;
TetsuyaKonno 0:97cbef48166d 606 }
TetsuyaKonno 0:97cbef48166d 607
TetsuyaKonno 0:97cbef48166d 608 /* C 分散 */
TetsuyaKonno 0:97cbef48166d 609 iRet_C = 0;
TetsuyaKonno 0:97cbef48166d 610 for( i = 0; i < items; i++ ) {
TetsuyaKonno 0:97cbef48166d 611 iRet_C += ( Devi[i] * Devi[i] );
TetsuyaKonno 0:97cbef48166d 612 }
TetsuyaKonno 0:97cbef48166d 613 iRet_C /= items;
TetsuyaKonno 0:97cbef48166d 614
TetsuyaKonno 0:97cbef48166d 615 /* D 標準偏差 */
TetsuyaKonno 0:97cbef48166d 616 iRet_D = sqrt( iRet_C );
TetsuyaKonno 0:97cbef48166d 617
TetsuyaKonno 0:97cbef48166d 618 return iRet_D;
TetsuyaKonno 0:97cbef48166d 619 }
TetsuyaKonno 0:97cbef48166d 620
TetsuyaKonno 0:97cbef48166d 621 // Covariance
TetsuyaKonno 0:97cbef48166d 622 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 623 double Covariance( double *Devi_A, double *Devi_B, int items )
TetsuyaKonno 0:97cbef48166d 624 {
TetsuyaKonno 0:97cbef48166d 625 int i;
TetsuyaKonno 0:97cbef48166d 626 double iRet, iRet_buff;
TetsuyaKonno 0:97cbef48166d 627
TetsuyaKonno 0:97cbef48166d 628 iRet = 0;
TetsuyaKonno 0:97cbef48166d 629 for( i = 0; i < items; i++ ) {
TetsuyaKonno 0:97cbef48166d 630 iRet_buff = Devi_A[i] * Devi_B[i];
TetsuyaKonno 0:97cbef48166d 631 iRet += iRet_buff;
TetsuyaKonno 0:97cbef48166d 632 }
TetsuyaKonno 0:97cbef48166d 633 iRet /= items;
TetsuyaKonno 0:97cbef48166d 634
TetsuyaKonno 0:97cbef48166d 635 return iRet;
TetsuyaKonno 0:97cbef48166d 636 }
TetsuyaKonno 0:97cbef48166d 637
TetsuyaKonno 0:97cbef48166d 638 // Judgement_ImageMatching
TetsuyaKonno 0:97cbef48166d 639 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 640 int Judgement_ImageMatching( double covari, double SDevi_A, double SDevi_B )
TetsuyaKonno 0:97cbef48166d 641 {
TetsuyaKonno 0:97cbef48166d 642 int iRet;
TetsuyaKonno 0:97cbef48166d 643
TetsuyaKonno 0:97cbef48166d 644 iRet = ( covari * 100 ) / ( SDevi_A * SDevi_B );
TetsuyaKonno 0:97cbef48166d 645
TetsuyaKonno 0:97cbef48166d 646 return iRet;
TetsuyaKonno 0:97cbef48166d 647 }
TetsuyaKonno 0:97cbef48166d 648
TetsuyaKonno 0:97cbef48166d 649 // MarkDetect_process_T
TetsuyaKonno 0:97cbef48166d 650 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 651 void MarkDetect_process_T( void )
TetsuyaKonno 0:97cbef48166d 652 {
TetsuyaKonno 0:97cbef48166d 653 int x, y;
TetsuyaKonno 0:97cbef48166d 654
TetsuyaKonno 0:97cbef48166d 655 retJudgeIM_Max[0] = 0;
TetsuyaKonno 0:97cbef48166d 656 for( y = 0; y <= 12; y++ ) {
TetsuyaKonno 0:97cbef48166d 657 for( x = 0; x <= 15; x++ ) {
TetsuyaKonno 0:97cbef48166d 658 Image_part_Extraction( ImageBinary, 20, x, y, NowImageBinary, 5, 3 );
TetsuyaKonno 0:97cbef48166d 659 retDevi = Standard_Deviation( NowImageBinary, NowDevi, 15 );
TetsuyaKonno 0:97cbef48166d 660 retCovari = Covariance( TempDevi_Triangle, NowDevi, 15 );
TetsuyaKonno 0:97cbef48166d 661 retJudgeIM = 0;
TetsuyaKonno 0:97cbef48166d 662 retJudgeIM = Judgement_ImageMatching( retCovari, retDevi_Triangle, retDevi );
TetsuyaKonno 0:97cbef48166d 663 if( 100 >= retJudgeIM && retJudgeIM > retJudgeIM_Max[0] ) {
TetsuyaKonno 0:97cbef48166d 664 Xt = x;
TetsuyaKonno 0:97cbef48166d 665 Yt = y;
TetsuyaKonno 0:97cbef48166d 666 retJudgeIM_Max[0] = retJudgeIM;
TetsuyaKonno 0:97cbef48166d 667 }
TetsuyaKonno 0:97cbef48166d 668 }
TetsuyaKonno 0:97cbef48166d 669 }
TetsuyaKonno 0:97cbef48166d 670 }
TetsuyaKonno 0:97cbef48166d 671
TetsuyaKonno 0:97cbef48166d 672 // MarkCheck Triangle detection
TetsuyaKonno 0:97cbef48166d 673 // Return values: 0: no triangle mark, 1: Triangle mark
TetsuyaKonno 0:97cbef48166d 674 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 675 int MarkCheck_Triangle( int percentage )
TetsuyaKonno 0:97cbef48166d 676 {
TetsuyaKonno 0:97cbef48166d 677 int ret;
TetsuyaKonno 0:97cbef48166d 678
TetsuyaKonno 0:97cbef48166d 679 ret = 0;
TetsuyaKonno 0:97cbef48166d 680 if( retJudgeIM_Max[0] >= percentage ) {
TetsuyaKonno 0:97cbef48166d 681 ret = 1;
TetsuyaKonno 0:97cbef48166d 682 }
TetsuyaKonno 0:97cbef48166d 683
TetsuyaKonno 0:97cbef48166d 684 return ret;
TetsuyaKonno 0:97cbef48166d 685 }
TetsuyaKonno 0:97cbef48166d 686
TetsuyaKonno 0:97cbef48166d 687 //******************************************************************//
TetsuyaKonno 0:97cbef48166d 688 // Debug functions
TetsuyaKonno 0:97cbef48166d 689 //*******************************************************************/
TetsuyaKonno 0:97cbef48166d 690 //Image Data Output( for the Excel )
TetsuyaKonno 0:97cbef48166d 691 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 692 void ImageData_Serial_Out( unsigned char *Data_Y, int Width )
TetsuyaKonno 0:97cbef48166d 693 {
TetsuyaKonno 0:97cbef48166d 694 int Xp, Yp, inc, Height;
TetsuyaKonno 0:97cbef48166d 695
TetsuyaKonno 0:97cbef48166d 696 Height = (Width / (double)4) * 3;
TetsuyaKonno 0:97cbef48166d 697 for( Yp = 0, inc = 0; Yp < Height; Yp++ ) {
TetsuyaKonno 0:97cbef48166d 698 for( Xp = 0; Xp < Width; Xp++, inc++ ) {
TetsuyaKonno 0:97cbef48166d 699 pc.printf( "%d,", Data_Y[ inc ] );
TetsuyaKonno 0:97cbef48166d 700 }
TetsuyaKonno 0:97cbef48166d 701 pc.printf("\n\r");
TetsuyaKonno 0:97cbef48166d 702 }
TetsuyaKonno 0:97cbef48166d 703 }
TetsuyaKonno 0:97cbef48166d 704
TetsuyaKonno 0:97cbef48166d 705 //Image Data Output2( for TeraTerm )
TetsuyaKonno 0:97cbef48166d 706 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 707 void ImageData_Serial_Out2( unsigned char *Data_Y, int Width )
TetsuyaKonno 0:97cbef48166d 708 {
TetsuyaKonno 0:97cbef48166d 709 int Xp, Yp, Height;
TetsuyaKonno 0:97cbef48166d 710
TetsuyaKonno 0:97cbef48166d 711 Height = (Width / (double)4) * 3;
TetsuyaKonno 0:97cbef48166d 712 for( Yp = 0; Yp < Height; Yp++ ) {
TetsuyaKonno 0:97cbef48166d 713 for( Xp = 0; Xp < Width; Xp++ ) {
TetsuyaKonno 0:97cbef48166d 714 pc.printf( "%d ", Data_Y[Xp + (Yp * Width)] );
TetsuyaKonno 0:97cbef48166d 715 }
TetsuyaKonno 0:97cbef48166d 716 pc.printf( "\n\r" );
TetsuyaKonno 0:97cbef48166d 717 }
TetsuyaKonno 0:97cbef48166d 718
TetsuyaKonno 0:97cbef48166d 719 //Add display
TetsuyaKonno 0:97cbef48166d 720 pc.printf( "\n\r" );
TetsuyaKonno 0:97cbef48166d 721 pc.printf( "T = %3d%% %01d X=%2d Y=%2d\n\r", retJudgeIM_Max[0], MarkCheck_Triangle( 90 ), Xt, Yt );
TetsuyaKonno 0:97cbef48166d 722 pc.printf( "\n\r" );
TetsuyaKonno 0:97cbef48166d 723 Height += 3;
TetsuyaKonno 0:97cbef48166d 724
TetsuyaKonno 0:97cbef48166d 725 pc.printf( "\033[%dA" , Height );
TetsuyaKonno 0:97cbef48166d 726 }
TetsuyaKonno 0:97cbef48166d 727
TetsuyaKonno 0:97cbef48166d 728 //------------------------------------------------------------------//
TetsuyaKonno 0:97cbef48166d 729 // End of file
TetsuyaKonno 0:97cbef48166d 730 //------------------------------------------------------------------//