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 Boboobooo 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(void){ 00007 00008 line_CamR = new FastAnalogIn(PTD5); 00009 line_CamL= new FastAnalogIn(PTD6,0); 00010 cam_clk=new DigitalOut(PTE1); 00011 si=new DigitalOut(PTD7); 00012 00013 } 00014 00015 int BX_camera::black_centerR(void){ 00016 00017 int black_R = 10; 00018 for(int i = 118; i >=10; i--){ 00019 if(sign_line_imageR[i] == 'O' && sign_line_imageR[i-1] == ' ' && sign_line_imageR[i-2] == ' '){ 00020 return i; 00021 } 00022 } 00023 return black_R; 00024 00025 00026 00027 00028 } 00029 00030 int BX_camera::black_centerL(void){ 00031 00032 int black_L = 118; 00033 for(int i = 10; i <118 ; i++){ 00034 if(sign_line_imageL[i] == 'O' && sign_line_imageL[i+1] == ' ' && sign_line_imageL[i+2] == ' '){ 00035 return i; 00036 } 00037 } 00038 return black_L; 00039 00040 00041 00042 00043 00044 00045 00046 } 00047 00048 00049 00050 void BX_camera::read(void){ 00051 00052 w_f_vL=0x0000; 00053 b_f_vL=0xffff; 00054 00055 w_f_vR=0x0000; 00056 b_f_vR=0xffff; 00057 00058 00059 00060 00061 *si=1; 00062 *cam_clk=1; 00063 00064 wait_us(30); // tune here 00065 *si=0; 00066 *cam_clk=0; 00067 00068 00069 00070 line_CamR->enable(); 00071 line_CamL->enable(); 00072 00073 00074 //input 128 //both 00075 00076 for(int i=127;i>=0;i--){ 00077 *cam_clk=1; 00078 wait_us(5); 00079 00080 00081 line_imageR[i]=line_CamR->read_u16(); 00082 line_imageL[i]=line_CamL->read_u16(); 00083 00084 // big small 00085 if(line_imageR[i] > w_f_vR) 00086 w_f_vR=line_imageR[i]; 00087 else if(line_imageR[i] < b_f_vR ) 00088 b_f_vR = line_imageR[i]; 00089 00090 00091 if(line_imageL[i] > w_f_vL) 00092 w_f_vL=line_imageL[i]; 00093 else if(line_imageL[i] < b_f_vL ) 00094 b_f_vL = line_imageL[i]; 00095 00096 00097 00098 00099 *cam_clk=0; 00100 wait_us(5); 00101 00102 00103 } 00104 00105 00106 line_CamR->enable(); 00107 line_CamL->enable(); 00108 00109 00110 //filter L R //may change 00111 00112 for(int i=0;i<128;i++){ 00113 00114 00115 if( (line_imageR[i]-b_f_vR) < (w_f_vR - line_imageR[i] ) ) 00116 sign_line_imageR[i]=' '; 00117 else 00118 sign_line_imageR[i]='O'; 00119 00120 00121 if( (line_imageL[i]-b_f_vL) < (w_f_vL - line_imageL[i] ) ) 00122 sign_line_imageL[i]=' '; 00123 else 00124 sign_line_imageL[i]='O'; 00125 00126 00127 00128 00129 00130 if(i==0){ 00131 sign_line_imageR[i]='X'; 00132 sign_line_imageL[i]='X'; 00133 } 00134 00135 00136 } 00137 00138 00139 00140 }
Generated on Wed Jul 20 2022 19:27:32 by
1.7.2
