wu

Dependencies:   mbed-rtos mbed

Fork of CCC by kao yi

Committer:
backman
Date:
Mon Jun 30 03:37:05 2014 +0000
Revision:
17:3dac99cf2b89
Parent:
16:b78dce5c0e98
wu

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 15:585df3979be8 21 int b_start=0;
backman 14:2d90b0066fc6 22 int b_end=0;
backman 15:585df3979be8 23 bool l_f1=false;
backman 15:585df3979be8 24 bool l_f2=false;
backman 15:585df3979be8 25 bool find=false;
backman 15:585df3979be8 26 int b_thr_up=32;
backman 15:585df3979be8 27 int b_thr_dn=5;
backman 6:5a39bde2e016 28 int b_w=0;
backman 15:585df3979be8 29
backman 15:585df3979be8 30 for(int i=r_care;i>l_care;i--){
backman 15:585df3979be8 31
backman 15:585df3979be8 32
backman 15:585df3979be8 33 if(l_f1==false&&sign_line_imageR[i]==' '){
backman 15:585df3979be8 34
backman 15:585df3979be8 35 b_start=i;
backman 15:585df3979be8 36 l_f1=true;
backman 15:585df3979be8 37 }
backman 15:585df3979be8 38 if(l_f1==true && sign_line_imageR[i]=='O'){
backman 15:585df3979be8 39 b_end=i-1;
backman 15:585df3979be8 40 l_f2=true;
backman 15:585df3979be8 41 }
backman 15:585df3979be8 42
backman 15:585df3979be8 43 if(l_f1==true && l_f2== true){
backman 15:585df3979be8 44 b_w=b_start-b_end;
backman 15:585df3979be8 45 if( b_thr_up>b_w&&b_w> b_thr_dn){
backman 15:585df3979be8 46
backman 15:585df3979be8 47 find=true;
backman 15:585df3979be8 48 break;
backman 6:5a39bde2e016 49 }
backman 15:585df3979be8 50 else{
backman 15:585df3979be8 51 l_f1=false;
backman 15:585df3979be8 52 l_f2=false;
backman 15:585df3979be8 53
backman 15:585df3979be8 54 }
backman 15:585df3979be8 55
backman 15:585df3979be8 56
backman 15:585df3979be8 57 }
backman 15:585df3979be8 58
backman 15:585df3979be8 59
backman 6:5a39bde2e016 60 }
backman 15:585df3979be8 61
backman 15:585df3979be8 62
backman 15:585df3979be8 63
backman 15:585df3979be8 64
backman 3:c5f2281b3ed2 65
backman 15:585df3979be8 66 if(find)
backman 15:585df3979be8 67 return (b_start+b_end)/2;
backman 15:585df3979be8 68 else
backman 15:585df3979be8 69 return -1;
backman 15:585df3979be8 70 }
backman 6:5a39bde2e016 71
backman 11:418e39749f48 72
backman 16:b78dce5c0e98 73 int BX_camera::black_centerL(void)
backman 16:b78dce5c0e98 74 {
backman 16:b78dce5c0e98 75
backman 16:b78dce5c0e98 76 int l_care=10;
backman 16:b78dce5c0e98 77 int r_care=118;
backman 16:b78dce5c0e98 78 int b_start=0;
backman 16:b78dce5c0e98 79 int b_end=0;
backman 16:b78dce5c0e98 80 bool l_f1=false;
backman 16:b78dce5c0e98 81 bool l_f2=false;
backman 16:b78dce5c0e98 82 bool find=false;
backman 16:b78dce5c0e98 83 int b_thr_up=32;
backman 16:b78dce5c0e98 84 int b_thr_dn=5;
backman 16:b78dce5c0e98 85 int b_w=0;
backman 16:b78dce5c0e98 86
backman 17:3dac99cf2b89 87 for(int i=l_care;i<r_care;i++){
backman 16:b78dce5c0e98 88
backman 16:b78dce5c0e98 89
backman 16:b78dce5c0e98 90 if(l_f1==false&&sign_line_imageL[i]==' '){
backman 16:b78dce5c0e98 91
backman 16:b78dce5c0e98 92 b_start=i;
backman 16:b78dce5c0e98 93 l_f1=true;
backman 16:b78dce5c0e98 94 }
backman 16:b78dce5c0e98 95 if(l_f1==true && sign_line_imageL[i]=='O'){
backman 16:b78dce5c0e98 96 b_end=i-1;
backman 16:b78dce5c0e98 97 l_f2=true;
backman 16:b78dce5c0e98 98 }
backman 16:b78dce5c0e98 99
backman 16:b78dce5c0e98 100 if(l_f1==true && l_f2== true){
backman 17:3dac99cf2b89 101 b_w=b_end-b_start;
backman 16:b78dce5c0e98 102 if( b_thr_up>b_w&&b_w> b_thr_dn){
backman 16:b78dce5c0e98 103
backman 16:b78dce5c0e98 104 find=true;
backman 16:b78dce5c0e98 105 break;
backman 16:b78dce5c0e98 106 }
backman 16:b78dce5c0e98 107 else{
backman 16:b78dce5c0e98 108 l_f1=false;
backman 16:b78dce5c0e98 109 l_f2=false;
backman 16:b78dce5c0e98 110
backman 16:b78dce5c0e98 111 }
backman 16:b78dce5c0e98 112
backman 16:b78dce5c0e98 113
backman 16:b78dce5c0e98 114 }
backman 16:b78dce5c0e98 115
backman 16:b78dce5c0e98 116
backman 16:b78dce5c0e98 117 }
backman 16:b78dce5c0e98 118
backman 16:b78dce5c0e98 119
backman 16:b78dce5c0e98 120
backman 16:b78dce5c0e98 121
backman 16:b78dce5c0e98 122
backman 16:b78dce5c0e98 123 if(find)
backman 16:b78dce5c0e98 124 return (b_start+b_end)/2;
backman 16:b78dce5c0e98 125 else
backman 16:b78dce5c0e98 126 return -1;
backman 16:b78dce5c0e98 127 }
backman 6:5a39bde2e016 128
backman 6:5a39bde2e016 129
backman 6:5a39bde2e016 130
backman 6:5a39bde2e016 131 void BX_camera::read(void)
backman 6:5a39bde2e016 132 {
backman 6:5a39bde2e016 133
backman 6:5a39bde2e016 134 w_f_vL=0x0000;
backman 6:5a39bde2e016 135 b_f_vL=0xffff;
backman 6:5a39bde2e016 136
backman 6:5a39bde2e016 137 w_f_vR=0x0000;
backman 6:5a39bde2e016 138 b_f_vR=0xffff;
backman 6:5a39bde2e016 139
backman 6:5a39bde2e016 140
backman 6:5a39bde2e016 141
backman 6:5a39bde2e016 142
backman 6:5a39bde2e016 143 *si=1;
backman 6:5a39bde2e016 144 *cam_clk=1;
backman 6:5a39bde2e016 145
backman 6:5a39bde2e016 146 wait_us(30); // tune here
backman 6:5a39bde2e016 147 *si=0;
backman 6:5a39bde2e016 148 *cam_clk=0;
backman 6:5a39bde2e016 149
backman 6:5a39bde2e016 150
backman 6:5a39bde2e016 151
backman 6:5a39bde2e016 152 line_CamR->enable();
backman 6:5a39bde2e016 153 line_CamL->enable();
backman 6:5a39bde2e016 154
backman 6:5a39bde2e016 155
backman 6:5a39bde2e016 156 //input 128 //both
backman 6:5a39bde2e016 157
backman 6:5a39bde2e016 158 for(int i=0; i<128; i++) {
backman 6:5a39bde2e016 159 *cam_clk=1;
backman 6:5a39bde2e016 160 wait_us(5);
backman 6:5a39bde2e016 161
backman 6:5a39bde2e016 162
backman 6:5a39bde2e016 163 line_imageR[i]=line_CamR->read_u16();
backman 6:5a39bde2e016 164 line_imageL[i]=line_CamL->read_u16();
backman 4:05b21dbca0c7 165
backman 6:5a39bde2e016 166 // big small
backman 6:5a39bde2e016 167 if(line_imageR[i] > w_f_vR)
backman 6:5a39bde2e016 168 w_f_vR=line_imageR[i];
backman 6:5a39bde2e016 169 else if(line_imageR[i] < b_f_vR )
backman 6:5a39bde2e016 170 b_f_vR = line_imageR[i];
backman 6:5a39bde2e016 171
backman 6:5a39bde2e016 172
backman 6:5a39bde2e016 173 if(line_imageL[i] > w_f_vL)
backman 6:5a39bde2e016 174 w_f_vL=line_imageL[i];
backman 6:5a39bde2e016 175 else if(line_imageL[i] < b_f_vL )
backman 6:5a39bde2e016 176 b_f_vL = line_imageL[i];
backman 6:5a39bde2e016 177
backman 6:5a39bde2e016 178
backman 6:5a39bde2e016 179
backman 6:5a39bde2e016 180
backman 6:5a39bde2e016 181 *cam_clk=0;
backman 6:5a39bde2e016 182 wait_us(5);
backman 6:5a39bde2e016 183
backman 6:5a39bde2e016 184
backman 6:5a39bde2e016 185 }
backman 6:5a39bde2e016 186
backman 6:5a39bde2e016 187
backman 6:5a39bde2e016 188 line_CamR->enable();
backman 6:5a39bde2e016 189 line_CamL->enable();
backman 6:5a39bde2e016 190
backman 6:5a39bde2e016 191
backman 6:5a39bde2e016 192 //filter L R //may change
backman 6:5a39bde2e016 193
backman 6:5a39bde2e016 194 for(int i=0; i<128; i++) {
backman 6:5a39bde2e016 195
backman 6:5a39bde2e016 196
backman 6:5a39bde2e016 197 if( (line_imageR[i]-b_f_vR) < (w_f_vR - line_imageR[i] ) )
backman 6:5a39bde2e016 198 sign_line_imageR[i]=' ';
backman 6:5a39bde2e016 199 else
backman 6:5a39bde2e016 200 sign_line_imageR[i]='O';
backman 6:5a39bde2e016 201
backman 6:5a39bde2e016 202
backman 6:5a39bde2e016 203 if( (line_imageL[i]-b_f_vL) < (w_f_vL - line_imageL[i] ) )
backman 6:5a39bde2e016 204 sign_line_imageL[i]=' ';
backman 6:5a39bde2e016 205 else
backman 6:5a39bde2e016 206 sign_line_imageL[i]='O';
backman 6:5a39bde2e016 207
backman 6:5a39bde2e016 208
backman 6:5a39bde2e016 209
backman 6:5a39bde2e016 210
backman 6:5a39bde2e016 211
backman 6:5a39bde2e016 212 if(i==0) {
backman 6:5a39bde2e016 213 sign_line_imageR[i]='X';
backman 6:5a39bde2e016 214 sign_line_imageL[i]='X';
backman 6:5a39bde2e016 215 }
backman 6:5a39bde2e016 216
backman 6:5a39bde2e016 217
backman 6:5a39bde2e016 218 }
backman 6:5a39bde2e016 219
backman 6:5a39bde2e016 220
backman 6:5a39bde2e016 221
backman 6:5a39bde2e016 222 }