Clark Lin
/
BX-car_s
QQQ
Fork of BX-car_s by
camera_api.cpp
- Committer:
- physicsgood
- Date:
- 2014-07-02
- Revision:
- 23:d6d4e8adf7fe
- Parent:
- 22:1464a3f0a290
File content as of revision 23:d6d4e8adf7fe:
#include "mbed.h" #include "camera_api.h" #define clk 2 //ms BX_camera::BX_camera(int p) { line_CamR = new FastAnalogIn(PTD5); line_CamL= new FastAnalogIn(PTD6,0); cam_clk=new DigitalOut(PTE1); si=new DigitalOut(PTD7); padding = p; } /*int BX_camera::black_center(void) { int black_L_right = 96 , black_R_left = 32; for(int i = 10; i <118; i++){ if(sign_line_imageR[i] == 'O' && sign_line_imageR[i+1] == ' ' && sign_line_imageR[i+2] == ' '){ black_R_left = i; break; } } for(int i = 118; i >= 10; i--){ if(sign_line_imageR[i] == 'O' && sign_line_imageR[i-1] == ' ' && sign_line_imageR[i-2] == ' '){ black_L_right = i; break; } } return (black_R_left + black_L_right) / 2; }*/ int BX_camera::black_centerR(void)//64~0 right eye { int black_R_left = 0; for(int i = 120; i >=8; i--){ if(sign_line_imageR[i] == 'O' && sign_line_imageR[i-1] == ' ' && sign_line_imageR[i-2] == ' '){ return i; } } return black_R_left; } int BX_camera::black_centerL(void) { int black_L_right = 128; for(int i = 8; i <121 ; i++){ if(sign_line_imageL[i] == 'O' && sign_line_imageL[i+1] == ' ' && sign_line_imageL[i+2] == ' '){ return i; } } return black_L_right; } //turn right 122~64(120) 0 //turn left 128 64~6(8) //straight 122~64 64~6 186~70 void BX_camera::read(void) { w_f_vL=0x0000; b_f_vL=0xffff; w_f_vR=0x0000; b_f_vR=0xffff; *si=1; *cam_clk=1; wait_us(30); // tune here *si=0; *cam_clk=0; line_CamR->enable(); line_CamL->enable(); //input 128 //both for(int i=0; i<128; i++) { *cam_clk=1; wait_us(5); line_imageR[i]=line_CamR->read_u16(); line_imageL[i]=line_CamL->read_u16(); // big small if(line_imageR[i] > w_f_vR) w_f_vR=line_imageR[i]; else if(line_imageR[i] < b_f_vR ) b_f_vR = line_imageR[i]; if(line_imageL[i] > w_f_vL) w_f_vL=line_imageL[i]; else if(line_imageL[i] < b_f_vL ) b_f_vL = line_imageL[i]; *cam_clk=0; wait_us(5); } line_CamR->enable(); line_CamL->enable(); //filter L R //may change for(int i=0; i<128; i++) { if( (line_imageR[i]-b_f_vR) < (w_f_vR - line_imageR[i] ) ) sign_line_imageR[i]=' '; else sign_line_imageR[i]='O'; if( (line_imageL[i]-b_f_vL) < (w_f_vL - line_imageL[i] ) ) sign_line_imageL[i]=' '; else sign_line_imageL[i]='O'; if(i==0) { sign_line_imageR[i]='X'; sign_line_imageL[i]='X'; } } }