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