kao yi
/
Bov3
wu
Fork of CCC by
camera_api.cpp@1:82bc25a7b68b, 2014-06-03 (annotated)
- Committer:
- backman
- Date:
- Tue Jun 03 15:53:55 2014 +0000
- Revision:
- 1:82bc25a7b68b
- Parent:
- 0:68c173249c01
- Child:
- 2:c51647d3c14d
cam_algroithm
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:82bc25a7b68b | 5 | |
backman | 1:82bc25a7b68b | 6 | |
backman | 1:82bc25a7b68b | 7 | BX_camera::BX_camera(char cam){ |
backman | 1:82bc25a7b68b | 8 | |
backman | 1:82bc25a7b68b | 9 | |
backman | 1:82bc25a7b68b | 10 | cam_clk= new DigitalOut(PTE1) ; |
backman | 1:82bc25a7b68b | 11 | |
backman | 1:82bc25a7b68b | 12 | si = new DigitalOut(PTD7); |
backman | 1:82bc25a7b68b | 13 | |
backman | 1:82bc25a7b68b | 14 | line_Cam = new FastAnalogIn(PTD5); |
backman | 1:82bc25a7b68b | 15 | |
backman | 1:82bc25a7b68b | 16 | |
backman | 1:82bc25a7b68b | 17 | |
backman | 1:82bc25a7b68b | 18 | |
backman | 1:82bc25a7b68b | 19 | |
backman | 1:82bc25a7b68b | 20 | |
backman | 1:82bc25a7b68b | 21 | } |
backman | 1:82bc25a7b68b | 22 | |
backman | 1:82bc25a7b68b | 23 | |
backman | 1:82bc25a7b68b | 24 | void BX_camera::read(void){ |
backman | 1:82bc25a7b68b | 25 | |
backman | 1:82bc25a7b68b | 26 | |
backman | 1:82bc25a7b68b | 27 | w_f_v=0x0000; |
backman | 1:82bc25a7b68b | 28 | b_f_v=0xffff; |
backman | 1:82bc25a7b68b | 29 | |
backman | 1:82bc25a7b68b | 30 | |
backman | 1:82bc25a7b68b | 31 | |
backman | 1:82bc25a7b68b | 32 | *si=1; |
backman | 1:82bc25a7b68b | 33 | *cam_clk=1; |
backman | 1:82bc25a7b68b | 34 | |
backman | 1:82bc25a7b68b | 35 | wait_us(30); // tune here |
backman | 1:82bc25a7b68b | 36 | *si=0; |
backman | 1:82bc25a7b68b | 37 | *cam_clk=0; |
backman | 1:82bc25a7b68b | 38 | |
backman | 1:82bc25a7b68b | 39 | |
backman | 1:82bc25a7b68b | 40 | |
backman | 1:82bc25a7b68b | 41 | line_Cam->enable(); |
backman | 1:82bc25a7b68b | 42 | |
backman | 1:82bc25a7b68b | 43 | |
backman | 1:82bc25a7b68b | 44 | //input 128 |
backman | 1:82bc25a7b68b | 45 | |
backman | 1:82bc25a7b68b | 46 | for(int i=0;i<128;i++){ |
backman | 1:82bc25a7b68b | 47 | *cam_clk=1; |
backman | 1:82bc25a7b68b | 48 | wait_us(5); |
backman | 1:82bc25a7b68b | 49 | |
backman | 1:82bc25a7b68b | 50 | |
backman | 1:82bc25a7b68b | 51 | line_image[i]=line_Cam->read_u16(); |
backman | 1:82bc25a7b68b | 52 | |
backman | 1:82bc25a7b68b | 53 | |
backman | 1:82bc25a7b68b | 54 | // big small |
backman | 1:82bc25a7b68b | 55 | if(line_image[i] > w_f_v) |
backman | 1:82bc25a7b68b | 56 | w_f_v=line_image[i]; |
backman | 1:82bc25a7b68b | 57 | else if(line_image[i] < b_f_v ) |
backman | 1:82bc25a7b68b | 58 | b_f_v = line_image[i]; |
backman | 1:82bc25a7b68b | 59 | |
backman | 1:82bc25a7b68b | 60 | |
backman | 1:82bc25a7b68b | 61 | |
backman | 1:82bc25a7b68b | 62 | |
backman | 1:82bc25a7b68b | 63 | *cam_clk=0; |
backman | 1:82bc25a7b68b | 64 | wait_us(5); |
backman | 1:82bc25a7b68b | 65 | |
backman | 1:82bc25a7b68b | 66 | |
backman | 1:82bc25a7b68b | 67 | } |
backman | 1:82bc25a7b68b | 68 | |
backman | 1:82bc25a7b68b | 69 | |
backman | 1:82bc25a7b68b | 70 | line_Cam->disable(); |
backman | 1:82bc25a7b68b | 71 | |
backman | 1:82bc25a7b68b | 72 | |
backman | 1:82bc25a7b68b | 73 | |
backman | 1:82bc25a7b68b | 74 | //filter |
backman | 1:82bc25a7b68b | 75 | |
backman | 1:82bc25a7b68b | 76 | for(int i=0;i<128;i++){ |
backman | 1:82bc25a7b68b | 77 | |
backman | 1:82bc25a7b68b | 78 | |
backman | 1:82bc25a7b68b | 79 | if( (line_image[i]-b_f_v) < (w_f_v - line_image[i] ) ) |
backman | 1:82bc25a7b68b | 80 | sign_line_image[i]=' '; |
backman | 1:82bc25a7b68b | 81 | else |
backman | 1:82bc25a7b68b | 82 | sign_line_image[i]='O'; |
backman | 1:82bc25a7b68b | 83 | |
backman | 1:82bc25a7b68b | 84 | if(i==0) |
backman | 1:82bc25a7b68b | 85 | sign_line_image[i]='X'; |
backman | 1:82bc25a7b68b | 86 | |
backman | 1:82bc25a7b68b | 87 | } |
backman | 1:82bc25a7b68b | 88 | |
backman | 1:82bc25a7b68b | 89 | |
backman | 1:82bc25a7b68b | 90 | |
backman | 1:82bc25a7b68b | 91 | } |