wu

Dependencies:   mbed-rtos mbed

Fork of CCC by kao yi

Committer:
backman
Date:
Sun Jun 22 15:29:20 2014 +0000
Revision:
8:8e49e21d80a2
Parent:
7:fd976e1ced33
Child:
10:03d5aa2511c4
same work

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