QQQQQQQ

Dependencies:   mbed

Fork of 7_7Boboobooo by 譯文 張

Committer:
backman
Date:
Thu Jun 05 10:32:55 2014 +0000
Revision:
5:e32b091aa1fb
Parent:
4:05b21dbca0c7
Child:
6:b046d6ff3745
test commit

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