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 BX-car_2 by
camera_api.cpp
00001 #include "mbed.h" 00002 #include "camera_api.h" 00003 00004 #define clk 2 //ms 00005 00006 BX_camera::BX_camera(int p) 00007 { 00008 00009 line_CamR = new FastAnalogIn(PTD5); 00010 line_CamL= new FastAnalogIn(PTD6,0); 00011 cam_clk=new DigitalOut(PTE1); 00012 si=new DigitalOut(PTD7); 00013 padding = p; 00014 } 00015 00016 int BX_camera::black_centerR(void) 00017 { 00018 00019 int l_care=10; 00020 int r_care=118; 00021 int b_start=0; 00022 int b_end=0; 00023 bool l_f1=false; 00024 bool l_f2=false; 00025 bool find=false; 00026 int b_thr_up=32; 00027 int b_thr_dn=5; 00028 int b_w=0; 00029 00030 for(int i=r_care;i>l_care;i--){ 00031 00032 00033 if(l_f1==false&&sign_line_imageR[i]==' '){ 00034 00035 b_start=i; 00036 l_f1=true; 00037 } 00038 if(l_f1==true && sign_line_imageR[i]=='O'){ 00039 b_end=i-1; 00040 l_f2=true; 00041 } 00042 00043 if(l_f1==true && l_f2== true){ 00044 b_w=b_start-b_end; 00045 if( b_thr_up>b_w&&b_w> b_thr_dn){ 00046 00047 find=true; 00048 break; 00049 } 00050 else{ 00051 l_f1=false; 00052 l_f2=false; 00053 00054 } 00055 00056 00057 } 00058 00059 00060 } 00061 00062 00063 00064 00065 00066 if(find) 00067 return (b_start+b_end)/2; 00068 else 00069 return -1; 00070 } 00071 00072 00073 00074 00075 00076 void BX_camera::read(void) 00077 { 00078 00079 w_f_vL=0x0000; 00080 b_f_vL=0xffff; 00081 00082 w_f_vR=0x0000; 00083 b_f_vR=0xffff; 00084 00085 00086 00087 00088 *si=1; 00089 *cam_clk=1; 00090 00091 wait_us(30); // tune here 00092 *si=0; 00093 *cam_clk=0; 00094 00095 00096 00097 line_CamR->enable(); 00098 line_CamL->enable(); 00099 00100 00101 //input 128 //both 00102 00103 for(int i=0; i<128; i++) { 00104 *cam_clk=1; 00105 wait_us(5); 00106 00107 00108 line_imageR[i]=line_CamR->read_u16(); 00109 line_imageL[i]=line_CamL->read_u16(); 00110 00111 // big small 00112 if(line_imageR[i] > w_f_vR) 00113 w_f_vR=line_imageR[i]; 00114 else if(line_imageR[i] < b_f_vR ) 00115 b_f_vR = line_imageR[i]; 00116 00117 00118 if(line_imageL[i] > w_f_vL) 00119 w_f_vL=line_imageL[i]; 00120 else if(line_imageL[i] < b_f_vL ) 00121 b_f_vL = line_imageL[i]; 00122 00123 00124 00125 00126 *cam_clk=0; 00127 wait_us(5); 00128 00129 00130 } 00131 00132 00133 line_CamR->enable(); 00134 line_CamL->enable(); 00135 00136 00137 //filter L R //may change 00138 00139 for(int i=0; i<128; i++) { 00140 00141 00142 if( (line_imageR[i]-b_f_vR) < (w_f_vR - line_imageR[i] ) ) 00143 sign_line_imageR[i]=' '; 00144 else 00145 sign_line_imageR[i]='O'; 00146 00147 00148 if( (line_imageL[i]-b_f_vL) < (w_f_vL - line_imageL[i] ) ) 00149 sign_line_imageL[i]=' '; 00150 else 00151 sign_line_imageL[i]='O'; 00152 00153 00154 00155 00156 00157 if(i==0) { 00158 sign_line_imageR[i]='X'; 00159 sign_line_imageL[i]='X'; 00160 } 00161 00162 00163 } 00164 00165 00166 00167 }
Generated on Tue Jul 12 2022 21:33:29 by
1.7.2
