wu

Dependencies:   mbed-rtos mbed

Fork of CCC by kao yi

Committer:
backman
Date:
Sat Jun 28 08:37:06 2014 +0000
Revision:
13:63f9a5101205
Parent:
12:fdada4af384a
Child:
14:2d90b0066fc6
rt

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 13:63f9a5101205 6 BX_camera::BX_camera(int p)
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 13:63f9a5101205 13 padding = p;
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 10:03d5aa2511c4 29 int b_end=118;
backman 10:03d5aa2511c4 30 int b_start=118;
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 10:03d5aa2511c4 128 de_v=b_start;
backman 10:03d5aa2511c4 129 de_v2=b_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 6:5a39bde2e016 178 int BX_camera::black_centerL(void)
backman 6:5a39bde2e016 179 {
backman 6:5a39bde2e016 180
backman 11:418e39749f48 181 int l_care=10;
backman 11:418e39749f48 182 int r_care=118;
backman 11:418e39749f48 183
backman 11:418e39749f48 184
backman 6:5a39bde2e016 185 // find center
backman 6:5a39bde2e016 186 // case 1 // | //
backman 11:418e39749f48 187 // case 2 / | /
backman 6:5a39bde2e016 188
backman 6:5a39bde2e016 189 char find_type=0x00;
backman 6:5a39bde2e016 190
backman 11:418e39749f48 191 int b_end=118;
backman 11:418e39749f48 192 int b_start=118;
backman 11:418e39749f48 193
backman 11:418e39749f48 194 int b_w=0;
backman 11:418e39749f48 195 int b_center=0;
backman 11:418e39749f48 196
backman 6:5a39bde2e016 197 int b2_end=0;
backman 6:5a39bde2e016 198 int b2_start=0;
backman 11:418e39749f48 199 int b2_center=0;
backman 6:5a39bde2e016 200
backman 11:418e39749f48 201 int b2_w=0;
backman 11:418e39749f48 202
backman 11:418e39749f48 203 int center=30;
backman 6:5a39bde2e016 204 int j=64;
backman 6:5a39bde2e016 205 bool f1=false;
backman 6:5a39bde2e016 206 bool f2=false;
backman 6:5a39bde2e016 207 bool f3=false;
backman 6:5a39bde2e016 208 bool f4=false;
backman 11:418e39749f48 209 int w_thr_up=32;
backman 11:418e39749f48 210 int w_thr_dn=0;
backman 6:5a39bde2e016 211
backman 11:418e39749f48 212 if(sign_line_imageR[64]==' ')
backman 6:5a39bde2e016 213 find_type=0x02;
backman 6:5a39bde2e016 214 else
backman 6:5a39bde2e016 215 find_type=0x01;
backman 6:5a39bde2e016 216
backman 6:5a39bde2e016 217
backman 11:418e39749f48 218 for(int i=64; i<r_care; i++,j--) {
backman 6:5a39bde2e016 219
backman 6:5a39bde2e016 220
backman 6:5a39bde2e016 221 switch(find_type) {
backman 6:5a39bde2e016 222
backman 6:5a39bde2e016 223
backman 6:5a39bde2e016 224 case 0x01:
backman 6:5a39bde2e016 225
backman 12:fdada4af384a 226 if(f1==false&&sign_line_imageL[i]==' ') {
backman 6:5a39bde2e016 227 if(f1==false) {
backman 6:5a39bde2e016 228 b_start=i;
backman 6:5a39bde2e016 229 f1=true;
backman 6:5a39bde2e016 230 }
backman 6:5a39bde2e016 231
backman 6:5a39bde2e016 232 }
backman 12:fdada4af384a 233 if(f1== true&& f2==false&&sign_line_imageL[i]=='O') {
backman 6:5a39bde2e016 234 if(f2==false) {
backman 6:5a39bde2e016 235 b_end=i-1;
backman 6:5a39bde2e016 236 f2=true;
backman 6:5a39bde2e016 237 }
backman 6:5a39bde2e016 238
backman 6:5a39bde2e016 239 }
backman 4:05b21dbca0c7 240
backman 12:fdada4af384a 241 if(f3==false&&sign_line_imageL[j]==' ') {
backman 6:5a39bde2e016 242 if(f3==false) {
backman 6:5a39bde2e016 243 b2_end=j;
backman 6:5a39bde2e016 244 f3=true;
backman 6:5a39bde2e016 245 }
backman 6:5a39bde2e016 246
backman 6:5a39bde2e016 247 }
backman 12:fdada4af384a 248 if(f3==true&&f4==false&&sign_line_imageL[j]=='O') {
backman 6:5a39bde2e016 249 if(f4==false) {
backman 6:5a39bde2e016 250 b2_start=j-1;
backman 6:5a39bde2e016 251 f4=true;
backman 6:5a39bde2e016 252 }
backman 6:5a39bde2e016 253
backman 6:5a39bde2e016 254 }
backman 6:5a39bde2e016 255
backman 11:418e39749f48 256
backman 6:5a39bde2e016 257 break;
backman 6:5a39bde2e016 258
backman 6:5a39bde2e016 259
backman 6:5a39bde2e016 260 case 0x02:
backman 6:5a39bde2e016 261
backman 12:fdada4af384a 262 if(sign_line_imageL[i]=='O') {
backman 6:5a39bde2e016 263
backman 6:5a39bde2e016 264 if(f1==false) {
backman 6:5a39bde2e016 265 b_end=i;
backman 6:5a39bde2e016 266 f1=true;
backman 6:5a39bde2e016 267 }
backman 6:5a39bde2e016 268 }
backman 6:5a39bde2e016 269
backman 12:fdada4af384a 270 if(sign_line_imageL[j]=='O') {
backman 6:5a39bde2e016 271
backman 6:5a39bde2e016 272 if(f2==false) {
backman 6:5a39bde2e016 273 b_start=j;
backman 6:5a39bde2e016 274 f2=true;
backman 6:5a39bde2e016 275 }
backman 6:5a39bde2e016 276
backman 6:5a39bde2e016 277 }
backman 6:5a39bde2e016 278
backman 6:5a39bde2e016 279
backman 6:5a39bde2e016 280 break;
backman 6:5a39bde2e016 281
backman 6:5a39bde2e016 282 }
backman 6:5a39bde2e016 283
backman 11:418e39749f48 284
backman 6:5a39bde2e016 285 }
backman 6:5a39bde2e016 286
backman 11:418e39749f48 287 b_w=b_start-b_end;
backman 11:418e39749f48 288 b2_w=b2_start-b2_end;
backman 11:418e39749f48 289
backman 11:418e39749f48 290 de_v=b_start;
backman 11:418e39749f48 291 de_v2=b_end;
backman 6:5a39bde2e016 292
backman 6:5a39bde2e016 293 switch(find_type) {
backman 6:5a39bde2e016 294
backman 6:5a39bde2e016 295 case 0x01:
backman 11:418e39749f48 296 b_center=(b_end+b_start)/2;
backman 11:418e39749f48 297 b2_center=(b2_end+b2_start)/2;
backman 11:418e39749f48 298
backman 11:418e39749f48 299
backman 11:418e39749f48 300 if(w_thr_up>b_w&&(b_center!=0)&&(b_center-64)<(64-b2_center))
backman 11:418e39749f48 301 center=b_center;
backman 11:418e39749f48 302 else
backman 11:418e39749f48 303 center=b2_center;
backman 6:5a39bde2e016 304
backman 11:418e39749f48 305
backman 11:418e39749f48 306
backman 11:418e39749f48 307
backman 11:418e39749f48 308
backman 11:418e39749f48 309 /* if( ( w_thr_up- (b_w))>0 &&( ( w_thr_up- (b_w)) < (w_thr_up-(b2_w)) ) ) {
backman 6:5a39bde2e016 310 center=(b_end+b_start)/2;
backman 6:5a39bde2e016 311
backman 11:418e39749f48 312
backman 11:418e39749f48 313
backman 11:418e39749f48 314 // } else if( ( w_thr_up- (b2_w) )>0 ) {
backman 6:5a39bde2e016 315 center=(b2_end+b2_start)/2;
backman 11:418e39749f48 316 // } else {
backman 11:418e39749f48 317
backman 11:418e39749f48 318 center=65;
backman 11:418e39749f48 319
backman 11:418e39749f48 320 //????????????????
backman 11:418e39749f48 321
backman 11:418e39749f48 322 }
backman 11:418e39749f48 323
backman 11:418e39749f48 324 */
backman 6:5a39bde2e016 325 break;
backman 6:5a39bde2e016 326
backman 6:5a39bde2e016 327 case 0x02:
backman 6:5a39bde2e016 328 center=(b_end+b_start)/2;
backman 6:5a39bde2e016 329
backman 11:418e39749f48 330
backman 6:5a39bde2e016 331 break;
backman 6:5a39bde2e016 332 }
backman 6:5a39bde2e016 333
backman 13:63f9a5101205 334 return (center+padding);
backman 11:418e39749f48 335
backman 11:418e39749f48 336 }
backman 6:5a39bde2e016 337
backman 11:418e39749f48 338
backman 6:5a39bde2e016 339
backman 6:5a39bde2e016 340
backman 6:5a39bde2e016 341
backman 6:5a39bde2e016 342 void BX_camera::read(void)
backman 6:5a39bde2e016 343 {
backman 6:5a39bde2e016 344
backman 6:5a39bde2e016 345 w_f_vL=0x0000;
backman 6:5a39bde2e016 346 b_f_vL=0xffff;
backman 6:5a39bde2e016 347
backman 6:5a39bde2e016 348 w_f_vR=0x0000;
backman 6:5a39bde2e016 349 b_f_vR=0xffff;
backman 6:5a39bde2e016 350
backman 6:5a39bde2e016 351
backman 6:5a39bde2e016 352
backman 6:5a39bde2e016 353
backman 6:5a39bde2e016 354 *si=1;
backman 6:5a39bde2e016 355 *cam_clk=1;
backman 6:5a39bde2e016 356
backman 6:5a39bde2e016 357 wait_us(30); // tune here
backman 6:5a39bde2e016 358 *si=0;
backman 6:5a39bde2e016 359 *cam_clk=0;
backman 6:5a39bde2e016 360
backman 6:5a39bde2e016 361
backman 6:5a39bde2e016 362
backman 6:5a39bde2e016 363 line_CamR->enable();
backman 6:5a39bde2e016 364 line_CamL->enable();
backman 6:5a39bde2e016 365
backman 6:5a39bde2e016 366
backman 6:5a39bde2e016 367 //input 128 //both
backman 6:5a39bde2e016 368
backman 6:5a39bde2e016 369 for(int i=0; i<128; i++) {
backman 6:5a39bde2e016 370 *cam_clk=1;
backman 6:5a39bde2e016 371 wait_us(5);
backman 6:5a39bde2e016 372
backman 6:5a39bde2e016 373
backman 6:5a39bde2e016 374 line_imageR[i]=line_CamR->read_u16();
backman 6:5a39bde2e016 375 line_imageL[i]=line_CamL->read_u16();
backman 4:05b21dbca0c7 376
backman 6:5a39bde2e016 377 // big small
backman 6:5a39bde2e016 378 if(line_imageR[i] > w_f_vR)
backman 6:5a39bde2e016 379 w_f_vR=line_imageR[i];
backman 6:5a39bde2e016 380 else if(line_imageR[i] < b_f_vR )
backman 6:5a39bde2e016 381 b_f_vR = line_imageR[i];
backman 6:5a39bde2e016 382
backman 6:5a39bde2e016 383
backman 6:5a39bde2e016 384 if(line_imageL[i] > w_f_vL)
backman 6:5a39bde2e016 385 w_f_vL=line_imageL[i];
backman 6:5a39bde2e016 386 else if(line_imageL[i] < b_f_vL )
backman 6:5a39bde2e016 387 b_f_vL = line_imageL[i];
backman 6:5a39bde2e016 388
backman 6:5a39bde2e016 389
backman 6:5a39bde2e016 390
backman 6:5a39bde2e016 391
backman 6:5a39bde2e016 392 *cam_clk=0;
backman 6:5a39bde2e016 393 wait_us(5);
backman 6:5a39bde2e016 394
backman 6:5a39bde2e016 395
backman 6:5a39bde2e016 396 }
backman 6:5a39bde2e016 397
backman 6:5a39bde2e016 398
backman 6:5a39bde2e016 399 line_CamR->enable();
backman 6:5a39bde2e016 400 line_CamL->enable();
backman 6:5a39bde2e016 401
backman 6:5a39bde2e016 402
backman 6:5a39bde2e016 403 //filter L R //may change
backman 6:5a39bde2e016 404
backman 6:5a39bde2e016 405 for(int i=0; i<128; i++) {
backman 6:5a39bde2e016 406
backman 6:5a39bde2e016 407
backman 6:5a39bde2e016 408 if( (line_imageR[i]-b_f_vR) < (w_f_vR - line_imageR[i] ) )
backman 6:5a39bde2e016 409 sign_line_imageR[i]=' ';
backman 6:5a39bde2e016 410 else
backman 6:5a39bde2e016 411 sign_line_imageR[i]='O';
backman 6:5a39bde2e016 412
backman 6:5a39bde2e016 413
backman 6:5a39bde2e016 414 if( (line_imageL[i]-b_f_vL) < (w_f_vL - line_imageL[i] ) )
backman 6:5a39bde2e016 415 sign_line_imageL[i]=' ';
backman 6:5a39bde2e016 416 else
backman 6:5a39bde2e016 417 sign_line_imageL[i]='O';
backman 6:5a39bde2e016 418
backman 6:5a39bde2e016 419
backman 6:5a39bde2e016 420
backman 6:5a39bde2e016 421
backman 6:5a39bde2e016 422
backman 6:5a39bde2e016 423 if(i==0) {
backman 6:5a39bde2e016 424 sign_line_imageR[i]='X';
backman 6:5a39bde2e016 425 sign_line_imageL[i]='X';
backman 6:5a39bde2e016 426 }
backman 6:5a39bde2e016 427
backman 6:5a39bde2e016 428
backman 6:5a39bde2e016 429 }
backman 6:5a39bde2e016 430
backman 6:5a39bde2e016 431
backman 6:5a39bde2e016 432
backman 6:5a39bde2e016 433 }