Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Boboobooov4 by
camera_api.cpp
00001 #include "mbed.h" 00002 #include "camera_api.h" 00003 #include "TFC.h" 00004 #define clk 2 //ms 00005 #define task_ma_time 00006 #ifdef task_ma_time 00007 DigitalOut cam_p(PTE5); 00008 #endif 00009 00010 BX_camera::BX_camera(int p) 00011 { 00012 00013 line_CamR = new FastAnalogIn(PTD5); 00014 line_CamL= new FastAnalogIn(PTD6,0); 00015 cam_clk=new DigitalOut(PTE1); 00016 si=new DigitalOut(PTD7); 00017 padding = p; 00018 } 00019 int BX_camera::black_centerR(void) 00020 { 00021 00022 int l_care=10; 00023 int r_care=64; 00024 int b_start=0; 00025 int b_end=0; 00026 bool l_f1=false; 00027 bool l_f2=false; 00028 bool find=false; 00029 int b_thr_up=20; 00030 int b_thr_dn=5; 00031 int b_w=0; 00032 00033 for(int i=r_care;i>l_care;i--){ 00034 00035 00036 if(l_f1==false&&sign_line_imageR[i]==' '){ 00037 00038 b_start=i; 00039 l_f1=true; 00040 } 00041 if(l_f1==true && sign_line_imageR[i]=='O'){ 00042 b_end=i-1; 00043 l_f2=true; 00044 } 00045 00046 if(l_f1==true && l_f2== true){ 00047 b_w=b_start-b_end; 00048 if( b_thr_up>b_w&&b_w> b_thr_dn){ 00049 00050 find=true; 00051 break; 00052 } 00053 else{ 00054 l_f1=false; 00055 l_f2=false; 00056 00057 } 00058 00059 00060 } 00061 00062 00063 } 00064 00065 00066 00067 00068 00069 if(find) 00070 return (b_start+b_end)/2; 00071 else 00072 return -1; 00073 } 00074 00075 00076 int BX_camera::black_centerL(void) 00077 { 00078 00079 int l_care=64; 00080 int r_care=115; 00081 int b_start=0; 00082 int b_end=0; 00083 bool l_f1=false; 00084 bool l_f2=false; 00085 bool find=false; 00086 int b_thr_up=20; 00087 int b_thr_dn=4; 00088 int b_w=0; 00089 00090 for(int i=l_care;i<r_care;i++){ 00091 00092 00093 if(l_f1==false&&sign_line_imageL[i]==' '){ 00094 00095 b_start=i; 00096 l_f1=true; 00097 } 00098 if(l_f1==true && sign_line_imageL[i]=='O'){ 00099 b_end=i-1; 00100 l_f2=true; 00101 } 00102 00103 if(l_f1==true && l_f2== true){ 00104 b_w=b_end-b_start; 00105 if( b_thr_up>b_w&&b_w>= b_thr_dn){ 00106 00107 find=true; 00108 break; 00109 } 00110 else{ 00111 l_f1=false; 00112 l_f2=false; 00113 00114 } 00115 00116 00117 } 00118 00119 00120 } 00121 00122 00123 00124 00125 00126 if(find) 00127 return (b_start+b_end)/2; 00128 else 00129 return -1; 00130 } 00131 00132 00133 00134 00135 void BX_camera::read(void) 00136 { 00137 00138 w_f_vL=0x0000; 00139 b_f_vL=0xffff; 00140 00141 w_f_vR=0x0000; 00142 b_f_vR=0xffff; 00143 00144 00145 line_CamR->enable(); 00146 00147 *si=1; 00148 *cam_clk=1; 00149 00150 wait_us(30); // tune here 00151 *si=0; 00152 *cam_clk=0; 00153 00154 00155 00156 00157 00158 00159 //input 128 //both 00160 00161 for(int i=0; i<128; i++) { 00162 *cam_clk=1; 00163 wait_us(5); 00164 00165 00166 line_imageR[i]=line_CamR->read_u16(); 00167 00168 00169 00170 00171 00172 // big small 00173 if(line_imageR[i] > w_f_vR) 00174 w_f_vR=line_imageR[i]; 00175 else if(line_imageR[i] < b_f_vR ) 00176 b_f_vR = line_imageR[i]; 00177 00178 00179 00180 00181 00182 *cam_clk=0; 00183 wait_us(5); 00184 00185 00186 } 00187 line_CamR->disable(); 00188 00189 *si=1; 00190 *cam_clk=1; 00191 00192 wait_us(30); // tune here 00193 *si=0; 00194 *cam_clk=0; 00195 00196 00197 00198 cam_p=1; 00199 line_CamL->enable(); 00200 for(int i=0; i<128; i++) { 00201 *cam_clk=1; 00202 wait_us(5); 00203 00204 00205 00206 00207 00208 00209 line_imageL[i]=line_CamL->read_u16(); 00210 00211 // big small 00212 00213 00214 if(line_imageL[i] > w_f_vL) 00215 w_f_vL=line_imageL[i]; 00216 else if(line_imageL[i] < b_f_vL ) 00217 b_f_vL = line_imageL[i]; 00218 00219 00220 00221 00222 *cam_clk=0; 00223 wait_us(5); 00224 00225 00226 } 00227 00228 00229 00230 00231 line_CamL->disable(); 00232 cam_p=0; 00233 00234 //filter L R //may change 00235 00236 for(int i=0; i<128; i++) { 00237 00238 00239 if( (line_imageR[i]-b_f_vR) < (w_f_vR - line_imageR[i] ) ) 00240 sign_line_imageR[i]=' '; 00241 else 00242 sign_line_imageR[i]='O'; 00243 00244 00245 if( (line_imageL[i]-b_f_vL) < (w_f_vL - line_imageL[i] ) ) 00246 sign_line_imageL[i]=' '; 00247 else 00248 sign_line_imageL[i]='O'; 00249 00250 00251 00252 00253 00254 if(i==0) { 00255 sign_line_imageR[i]='X'; 00256 sign_line_imageL[i]='X'; 00257 } 00258 00259 00260 } 00261 00262 00263 00264 }
Generated on Thu Jul 14 2022 03:30:21 by
1.7.2
