wu

Dependencies:   mbed-rtos mbed

Fork of CCC by kao yi

Committer:
backman
Date:
Wed Jun 11 14:41:52 2014 +0000
Revision:
6:5a39bde2e016
Parent:
5:e32b091aa1fb
Child:
7:fd976e1ced33
three;

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