wu

Dependencies:   mbed-rtos mbed

Fork of CCC by kao yi

Committer:
backman
Date:
Wed Jun 04 14:41:28 2014 +0000
Revision:
3:c5f2281b3ed2
Parent:
2:c51647d3c14d
Child:
4:05b21dbca0c7
center;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
backman 1:82bc25a7b68b 1 #include "mbed.h"
backman 1:82bc25a7b68b 2 #include "camera_api.h"
backman 1:82bc25a7b68b 3
backman 1:82bc25a7b68b 4 #define clk 2 //ms
backman 1:82bc25a7b68b 5
backman 1:82bc25a7b68b 6
backman 2:c51647d3c14d 7 BX_camera::BX_camera(void){
backman 1:82bc25a7b68b 8
backman 2:c51647d3c14d 9 line_CamR = new FastAnalogIn(PTD5);
backman 2:c51647d3c14d 10 line_CamL= new FastAnalogIn(PTD6,0);
backman 2:c51647d3c14d 11 cam_clk=new DigitalOut(PTE1);
backman 2:c51647d3c14d 12 si=new DigitalOut(PTD7);
backman 1:82bc25a7b68b 13
backman 2:c51647d3c14d 14
backman 1:82bc25a7b68b 15
backman 1:82bc25a7b68b 16
backman 1:82bc25a7b68b 17 }
backman 1:82bc25a7b68b 18
backman 3:c5f2281b3ed2 19 int BX_camera::black_centerR(void){
backman 3:c5f2281b3ed2 20
backman 3:c5f2281b3ed2 21
backman 3:c5f2281b3ed2 22 // find center
backman 3:c5f2281b3ed2 23 // case 1 // | //
backman 3:c5f2281b3ed2 24 // case 2 / | /
backman 3:c5f2281b3ed2 25
backman 3:c5f2281b3ed2 26 char find_type=0x00;
backman 3:c5f2281b3ed2 27
backman 3:c5f2281b3ed2 28 int b_end=0;
backman 3:c5f2281b3ed2 29 int b_start=0;
backman 3:c5f2281b3ed2 30
backman 3:c5f2281b3ed2 31 int b2_end=0;
backman 3:c5f2281b3ed2 32 int b2_start=0;
backman 3:c5f2281b3ed2 33
backman 3:c5f2281b3ed2 34
backman 3:c5f2281b3ed2 35 int center;
backman 3:c5f2281b3ed2 36 int j=64;
backman 3:c5f2281b3ed2 37 bool f1=false;
backman 3:c5f2281b3ed2 38 bool f2=false;
backman 3:c5f2281b3ed2 39 bool f3=false;
backman 3:c5f2281b3ed2 40 bool f4=false;
backman 3:c5f2281b3ed2 41
backman 3:c5f2281b3ed2 42
backman 3:c5f2281b3ed2 43 if(sign_line_imageR[64]==' ')
backman 3:c5f2281b3ed2 44 find_type=0x02;
backman 3:c5f2281b3ed2 45 else
backman 3:c5f2281b3ed2 46 find_type=0x01;
backman 3:c5f2281b3ed2 47
backman 3:c5f2281b3ed2 48
backman 3:c5f2281b3ed2 49 for(int i=64;i<128; i++,j--){
backman 3:c5f2281b3ed2 50
backman 3:c5f2281b3ed2 51
backman 3:c5f2281b3ed2 52 switch(find_type){
backman 3:c5f2281b3ed2 53
backman 3:c5f2281b3ed2 54
backman 3:c5f2281b3ed2 55 case 0x01:
backman 3:c5f2281b3ed2 56
backman 3:c5f2281b3ed2 57 if(f1==false&&sign_line_imageR[i]==' '){
backman 3:c5f2281b3ed2 58 if(f1==false){
backman 3:c5f2281b3ed2 59 b_start=i;
backman 3:c5f2281b3ed2 60 f1=true;
backman 3:c5f2281b3ed2 61 }
backman 3:c5f2281b3ed2 62
backman 3:c5f2281b3ed2 63 }
backman 3:c5f2281b3ed2 64 if(f1== true&& f2==false&&sign_line_imageR[i]=='O'){
backman 3:c5f2281b3ed2 65 if(f2==false){
backman 3:c5f2281b3ed2 66 b_end=i-1;
backman 3:c5f2281b3ed2 67 f2=true;
backman 3:c5f2281b3ed2 68 }
backman 3:c5f2281b3ed2 69
backman 3:c5f2281b3ed2 70 }
backman 3:c5f2281b3ed2 71
backman 3:c5f2281b3ed2 72 if(f3==false&&sign_line_imageR[j]==' '){
backman 3:c5f2281b3ed2 73 if(f3==false){
backman 3:c5f2281b3ed2 74 b2_end=j;
backman 3:c5f2281b3ed2 75 f3=true;
backman 3:c5f2281b3ed2 76 }
backman 3:c5f2281b3ed2 77
backman 3:c5f2281b3ed2 78 }
backman 3:c5f2281b3ed2 79 if(f3==true&&f4==false&&sign_line_imageR[j]=='O'){
backman 3:c5f2281b3ed2 80 if(f4==false){
backman 3:c5f2281b3ed2 81 b2_start=j-1;
backman 3:c5f2281b3ed2 82 f4=true;
backman 3:c5f2281b3ed2 83 }
backman 3:c5f2281b3ed2 84
backman 3:c5f2281b3ed2 85 }
backman 3:c5f2281b3ed2 86
backman 3:c5f2281b3ed2 87
backman 3:c5f2281b3ed2 88 break;
backman 3:c5f2281b3ed2 89
backman 3:c5f2281b3ed2 90
backman 3:c5f2281b3ed2 91 case 0x02:
backman 3:c5f2281b3ed2 92
backman 3:c5f2281b3ed2 93 if(sign_line_imageR[i]=='O'){
backman 3:c5f2281b3ed2 94
backman 3:c5f2281b3ed2 95 if(f1==false){
backman 3:c5f2281b3ed2 96 b_end=i;
backman 3:c5f2281b3ed2 97 f1=true;
backman 3:c5f2281b3ed2 98 }
backman 3:c5f2281b3ed2 99 }
backman 3:c5f2281b3ed2 100
backman 3:c5f2281b3ed2 101 if(sign_line_imageR[j]=='O'){
backman 3:c5f2281b3ed2 102
backman 3:c5f2281b3ed2 103 if(f2==false){
backman 3:c5f2281b3ed2 104 b_start=j;
backman 3:c5f2281b3ed2 105 f2=true;
backman 3:c5f2281b3ed2 106 }
backman 3:c5f2281b3ed2 107
backman 3:c5f2281b3ed2 108 }
backman 3:c5f2281b3ed2 109
backman 3:c5f2281b3ed2 110
backman 3:c5f2281b3ed2 111 break;
backman 3:c5f2281b3ed2 112
backman 3:c5f2281b3ed2 113
backman 3:c5f2281b3ed2 114
backman 3:c5f2281b3ed2 115
backman 3:c5f2281b3ed2 116 }
backman 3:c5f2281b3ed2 117
backman 3:c5f2281b3ed2 118
backman 3:c5f2281b3ed2 119 }
backman 3:c5f2281b3ed2 120
backman 3:c5f2281b3ed2 121
backman 3:c5f2281b3ed2 122 switch(find_type){
backman 3:c5f2281b3ed2 123
backman 3:c5f2281b3ed2 124 case 0x01:
backman 3:c5f2281b3ed2 125
backman 3:c5f2281b3ed2 126 if((b_end-b_start)>(b2_end-b2_start) )
backman 3:c5f2281b3ed2 127 center=(b_end+b_start)/2;
backman 3:c5f2281b3ed2 128
backman 3:c5f2281b3ed2 129 else
backman 3:c5f2281b3ed2 130 center=(b2_end+b2_start)/2;
backman 3:c5f2281b3ed2 131 break;
backman 3:c5f2281b3ed2 132
backman 3:c5f2281b3ed2 133 case 0x02:
backman 3:c5f2281b3ed2 134 center=(b_end+b_start)/2;
backman 3:c5f2281b3ed2 135
backman 3:c5f2281b3ed2 136 break;
backman 3:c5f2281b3ed2 137 }
backman 3:c5f2281b3ed2 138
backman 3:c5f2281b3ed2 139
backman 3:c5f2281b3ed2 140 return center;
backman 3:c5f2281b3ed2 141
backman 3:c5f2281b3ed2 142 }
backman 3:c5f2281b3ed2 143
backman 3:c5f2281b3ed2 144
backman 3:c5f2281b3ed2 145
backman 3:c5f2281b3ed2 146
backman 3:c5f2281b3ed2 147 int BX_camera::black_centerL(void){
backman 3:c5f2281b3ed2 148
backman 3:c5f2281b3ed2 149 // find center
backman 3:c5f2281b3ed2 150 // case 1 // | //
backman 3:c5f2281b3ed2 151 //case 2 / | /
backman 3:c5f2281b3ed2 152
backman 3:c5f2281b3ed2 153
backman 3:c5f2281b3ed2 154 char find_type=0x00;
backman 3:c5f2281b3ed2 155
backman 3:c5f2281b3ed2 156 int b_end=0;
backman 3:c5f2281b3ed2 157 int b_start=0;
backman 3:c5f2281b3ed2 158 int b2_end=0;
backman 3:c5f2281b3ed2 159 int b2_start=0;
backman 3:c5f2281b3ed2 160
backman 3:c5f2281b3ed2 161
backman 3:c5f2281b3ed2 162 int center;
backman 3:c5f2281b3ed2 163 int j=64;
backman 3:c5f2281b3ed2 164 bool f1=false;
backman 3:c5f2281b3ed2 165 bool f2=false;
backman 3:c5f2281b3ed2 166 bool f3=false;
backman 3:c5f2281b3ed2 167 bool f4=false;
backman 3:c5f2281b3ed2 168
backman 3:c5f2281b3ed2 169
backman 3:c5f2281b3ed2 170 if(sign_line_imageL[64]==' ')
backman 3:c5f2281b3ed2 171 find_type=0x02;
backman 3:c5f2281b3ed2 172 else
backman 3:c5f2281b3ed2 173 find_type=0x01;
backman 3:c5f2281b3ed2 174
backman 3:c5f2281b3ed2 175
backman 3:c5f2281b3ed2 176 for(int i=64;i<128; i++,j--){
backman 3:c5f2281b3ed2 177
backman 3:c5f2281b3ed2 178
backman 3:c5f2281b3ed2 179 switch(find_type){
backman 3:c5f2281b3ed2 180
backman 3:c5f2281b3ed2 181
backman 3:c5f2281b3ed2 182 case 0x01:
backman 3:c5f2281b3ed2 183
backman 3:c5f2281b3ed2 184 if(f1==false&&sign_line_imageL[i]==' '){
backman 3:c5f2281b3ed2 185 if(f1==false){
backman 3:c5f2281b3ed2 186 b_start=i;
backman 3:c5f2281b3ed2 187 f1=true;
backman 3:c5f2281b3ed2 188 }
backman 3:c5f2281b3ed2 189
backman 3:c5f2281b3ed2 190 }
backman 3:c5f2281b3ed2 191 if(f1== true&& f2==false&&sign_line_imageL[i]=='O'){
backman 3:c5f2281b3ed2 192 if(f2==false){
backman 3:c5f2281b3ed2 193 b_end=i-1;
backman 3:c5f2281b3ed2 194 f2=true;
backman 3:c5f2281b3ed2 195 }
backman 3:c5f2281b3ed2 196
backman 3:c5f2281b3ed2 197 }
backman 3:c5f2281b3ed2 198
backman 3:c5f2281b3ed2 199 if(f3==false&&sign_line_imageL[j]==' '){
backman 3:c5f2281b3ed2 200 if(f3==false){
backman 3:c5f2281b3ed2 201 b2_end=j;
backman 3:c5f2281b3ed2 202 f3=true;
backman 3:c5f2281b3ed2 203 }
backman 3:c5f2281b3ed2 204
backman 3:c5f2281b3ed2 205 }
backman 3:c5f2281b3ed2 206 if(f3==true&&f4==false&&sign_line_imageL[j]=='O'){
backman 3:c5f2281b3ed2 207 if(f4==false){
backman 3:c5f2281b3ed2 208 b2_start=j-1;
backman 3:c5f2281b3ed2 209 f4=true;
backman 3:c5f2281b3ed2 210 }
backman 3:c5f2281b3ed2 211
backman 3:c5f2281b3ed2 212 }
backman 3:c5f2281b3ed2 213
backman 3:c5f2281b3ed2 214
backman 3:c5f2281b3ed2 215
backman 3:c5f2281b3ed2 216
backman 3:c5f2281b3ed2 217
backman 3:c5f2281b3ed2 218
backman 3:c5f2281b3ed2 219
backman 3:c5f2281b3ed2 220
backman 3:c5f2281b3ed2 221 break;
backman 3:c5f2281b3ed2 222
backman 3:c5f2281b3ed2 223
backman 3:c5f2281b3ed2 224 case 0x02:
backman 3:c5f2281b3ed2 225
backman 3:c5f2281b3ed2 226 if(sign_line_imageL[i]=='O'){
backman 3:c5f2281b3ed2 227
backman 3:c5f2281b3ed2 228 if(f1==false){
backman 3:c5f2281b3ed2 229 b_end=i;
backman 3:c5f2281b3ed2 230 f1=true;
backman 3:c5f2281b3ed2 231 }
backman 3:c5f2281b3ed2 232 }
backman 3:c5f2281b3ed2 233
backman 3:c5f2281b3ed2 234 if(sign_line_imageL[j]=='O'){
backman 3:c5f2281b3ed2 235
backman 3:c5f2281b3ed2 236 if(f2==false){
backman 3:c5f2281b3ed2 237 b_start=j;
backman 3:c5f2281b3ed2 238 f2=true;
backman 3:c5f2281b3ed2 239 }
backman 3:c5f2281b3ed2 240
backman 3:c5f2281b3ed2 241 }
backman 3:c5f2281b3ed2 242
backman 3:c5f2281b3ed2 243
backman 3:c5f2281b3ed2 244 break;
backman 3:c5f2281b3ed2 245
backman 3:c5f2281b3ed2 246
backman 3:c5f2281b3ed2 247
backman 3:c5f2281b3ed2 248
backman 3:c5f2281b3ed2 249 }
backman 3:c5f2281b3ed2 250
backman 3:c5f2281b3ed2 251
backman 3:c5f2281b3ed2 252 }
backman 3:c5f2281b3ed2 253
backman 3:c5f2281b3ed2 254
backman 3:c5f2281b3ed2 255 switch(find_type){
backman 3:c5f2281b3ed2 256
backman 3:c5f2281b3ed2 257 case 0x01:
backman 3:c5f2281b3ed2 258
backman 3:c5f2281b3ed2 259 if((b_end-b_start)>(b2_end-b2_start) )
backman 3:c5f2281b3ed2 260 center=(b_end+b_start)/2;
backman 3:c5f2281b3ed2 261
backman 3:c5f2281b3ed2 262 else
backman 3:c5f2281b3ed2 263 center=(b2_end+b2_start)/2;
backman 3:c5f2281b3ed2 264 break;
backman 3:c5f2281b3ed2 265
backman 3:c5f2281b3ed2 266 case 0x02:
backman 3:c5f2281b3ed2 267 center=(b_end+b_start)/2;
backman 3:c5f2281b3ed2 268
backman 3:c5f2281b3ed2 269 break;
backman 3:c5f2281b3ed2 270 }
backman 3:c5f2281b3ed2 271
backman 3:c5f2281b3ed2 272 return center;
backman 3:c5f2281b3ed2 273
backman 3:c5f2281b3ed2 274 }
backman 3:c5f2281b3ed2 275
backman 3:c5f2281b3ed2 276
backman 3:c5f2281b3ed2 277
backman 3:c5f2281b3ed2 278
backman 3:c5f2281b3ed2 279
backman 3:c5f2281b3ed2 280
backman 3:c5f2281b3ed2 281
backman 3:c5f2281b3ed2 282
backman 3:c5f2281b3ed2 283
backman 3:c5f2281b3ed2 284
backman 3:c5f2281b3ed2 285
backman 1:82bc25a7b68b 286
backman 2:c51647d3c14d 287 void BX_camera::read(void){
backman 1:82bc25a7b68b 288
backman 2:c51647d3c14d 289 w_f_vL=0x0000;
backman 2:c51647d3c14d 290 b_f_vL=0xffff;
backman 2:c51647d3c14d 291
backman 2:c51647d3c14d 292 w_f_vR=0x0000;
backman 2:c51647d3c14d 293 b_f_vR=0xffff;
backman 1:82bc25a7b68b 294
backman 1:82bc25a7b68b 295
backman 1:82bc25a7b68b 296
backman 2:c51647d3c14d 297
backman 1:82bc25a7b68b 298 *si=1;
backman 2:c51647d3c14d 299 *cam_clk=1;
backman 1:82bc25a7b68b 300
backman 1:82bc25a7b68b 301 wait_us(30); // tune here
backman 1:82bc25a7b68b 302 *si=0;
backman 1:82bc25a7b68b 303 *cam_clk=0;
backman 1:82bc25a7b68b 304
backman 1:82bc25a7b68b 305
backman 1:82bc25a7b68b 306
backman 2:c51647d3c14d 307 line_CamR->enable();
backman 2:c51647d3c14d 308 line_CamL->enable();
backman 1:82bc25a7b68b 309
backman 1:82bc25a7b68b 310
backman 2:c51647d3c14d 311 //input 128 //both
backman 1:82bc25a7b68b 312
backman 1:82bc25a7b68b 313 for(int i=0;i<128;i++){
backman 2:c51647d3c14d 314 *cam_clk=1;
backman 2:c51647d3c14d 315 wait_us(5);
backman 1:82bc25a7b68b 316
backman 1:82bc25a7b68b 317
backman 2:c51647d3c14d 318 line_imageR[i]=line_CamR->read_u16();
backman 2:c51647d3c14d 319 line_imageL[i]=line_CamL->read_u16();
backman 1:82bc25a7b68b 320
backman 1:82bc25a7b68b 321 // big small
backman 2:c51647d3c14d 322 if(line_imageR[i] > w_f_vR)
backman 2:c51647d3c14d 323 w_f_vR=line_imageR[i];
backman 2:c51647d3c14d 324 else if(line_imageR[i] < b_f_vR )
backman 2:c51647d3c14d 325 b_f_vR = line_imageR[i];
backman 2:c51647d3c14d 326
backman 2:c51647d3c14d 327
backman 2:c51647d3c14d 328 if(line_imageL[i] > w_f_vL)
backman 2:c51647d3c14d 329 w_f_vL=line_imageL[i];
backman 2:c51647d3c14d 330 else if(line_imageL[i] < b_f_vL )
backman 2:c51647d3c14d 331 b_f_vL = line_imageL[i];
backman 1:82bc25a7b68b 332
backman 1:82bc25a7b68b 333
backman 1:82bc25a7b68b 334
backman 1:82bc25a7b68b 335
backman 1:82bc25a7b68b 336 *cam_clk=0;
backman 1:82bc25a7b68b 337 wait_us(5);
backman 1:82bc25a7b68b 338
backman 1:82bc25a7b68b 339
backman 1:82bc25a7b68b 340 }
backman 1:82bc25a7b68b 341
backman 1:82bc25a7b68b 342
backman 2:c51647d3c14d 343 line_CamR->enable();
backman 2:c51647d3c14d 344 line_CamL->enable();
backman 1:82bc25a7b68b 345
backman 1:82bc25a7b68b 346
backman 2:c51647d3c14d 347 //filter L R //may change
backman 1:82bc25a7b68b 348
backman 1:82bc25a7b68b 349 for(int i=0;i<128;i++){
backman 1:82bc25a7b68b 350
backman 1:82bc25a7b68b 351
backman 2:c51647d3c14d 352 if( (line_imageR[i]-b_f_vR) < (w_f_vR - line_imageR[i] ) )
backman 2:c51647d3c14d 353 sign_line_imageR[i]=' ';
backman 2:c51647d3c14d 354 else
backman 2:c51647d3c14d 355 sign_line_imageR[i]='O';
backman 2:c51647d3c14d 356
backman 2:c51647d3c14d 357
backman 2:c51647d3c14d 358 if( (line_imageL[i]-b_f_vL) < (w_f_vL - line_imageL[i] ) )
backman 2:c51647d3c14d 359 sign_line_imageL[i]=' ';
backman 1:82bc25a7b68b 360 else
backman 2:c51647d3c14d 361 sign_line_imageL[i]='O';
backman 2:c51647d3c14d 362
backman 1:82bc25a7b68b 363
backman 2:c51647d3c14d 364
backman 2:c51647d3c14d 365
backman 2:c51647d3c14d 366
backman 2:c51647d3c14d 367 if(i==0){
backman 2:c51647d3c14d 368 sign_line_imageR[i]='X';
backman 2:c51647d3c14d 369 sign_line_imageL[i]='X';
backman 2:c51647d3c14d 370 }
backman 2:c51647d3c14d 371
backman 1:82bc25a7b68b 372
backman 1:82bc25a7b68b 373 }
backman 1:82bc25a7b68b 374
backman 1:82bc25a7b68b 375
backman 1:82bc25a7b68b 376
backman 1:82bc25a7b68b 377 }