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.
Dependencies: mbed freescal_cup_k22f
source/Camera.cpp@15:b77dc649e4f3, 2015-01-14 (annotated)
- Committer:
- RobinN7
- Date:
- Wed Jan 14 18:41:06 2015 +0000
- Revision:
- 15:b77dc649e4f3
- Parent:
- 10:3424e7b66671
- Child:
- 16:88433b5650df
Am?lioration passe-bas
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RobinN7 | 0:3af30bfbc3e5 | 1 | #include "mbed.h" |
RobinN7 | 0:3af30bfbc3e5 | 2 | #include "Camera.h" |
RobinN7 | 0:3af30bfbc3e5 | 3 | |
RobinN7 | 0:3af30bfbc3e5 | 4 | DigitalOut clk(PTC2); |
RobinN7 | 0:3af30bfbc3e5 | 5 | DigitalOut si(PTB3); |
RobinN7 | 0:3af30bfbc3e5 | 6 | AnalogIn pix(PTB2); |
RobinN7 | 0:3af30bfbc3e5 | 7 | |
RobinN7 | 0:3af30bfbc3e5 | 8 | |
AlexandreN7 | 8:8f886cd6a59f | 9 | extern unsigned int pixel[128]= {0}; // |
RobinN7 | 0:3af30bfbc3e5 | 10 | |
AlexandreN7 | 8:8f886cd6a59f | 11 | void readline(void) // fonction de détection de la ligne |
RobinN7 | 0:3af30bfbc3e5 | 12 | { |
RobinN7 | 0:3af30bfbc3e5 | 13 | clk=0; // la clock est nulle au départ |
RobinN7 | 0:3af30bfbc3e5 | 14 | int compteur = 0,index_pixel = 0, capture_finie = 0; |
AlexandreN7 | 8:8f886cd6a59f | 15 | |
AlexandreN7 | 8:8f886cd6a59f | 16 | while (!capture_finie) { |
RobinN7 | 0:3af30bfbc3e5 | 17 | if (compteur & 1) // si compteur impair => front descendant |
RobinN7 | 0:3af30bfbc3e5 | 18 | clk = 0; |
RobinN7 | 0:3af30bfbc3e5 | 19 | else // compteur pair => montant |
RobinN7 | 0:3af30bfbc3e5 | 20 | clk = 1; |
RobinN7 | 0:3af30bfbc3e5 | 21 | if(compteur == 5) |
RobinN7 | 0:3af30bfbc3e5 | 22 | si = 1; |
AlexandreN7 | 8:8f886cd6a59f | 23 | |
RobinN7 | 0:3af30bfbc3e5 | 24 | if (compteur == 7) |
AlexandreN7 | 8:8f886cd6a59f | 25 | si=0; |
AlexandreN7 | 8:8f886cd6a59f | 26 | if ( (compteur & 1) && compteur >= 7) { // mesure sur front descendant, |
RobinN7 | 0:3af30bfbc3e5 | 27 | // pc.printf("lecture pixel\n"); |
RobinN7 | 0:3af30bfbc3e5 | 28 | pixel[index_pixel]=pix.read_u16(); |
RobinN7 | 0:3af30bfbc3e5 | 29 | index_pixel ++; |
RobinN7 | 0:3af30bfbc3e5 | 30 | } |
RobinN7 | 0:3af30bfbc3e5 | 31 | wait_us(10); |
RobinN7 | 0:3af30bfbc3e5 | 32 | compteur++; |
AlexandreN7 | 8:8f886cd6a59f | 33 | |
RobinN7 | 0:3af30bfbc3e5 | 34 | if (index_pixel == 128) |
AlexandreN7 | 8:8f886cd6a59f | 35 | capture_finie = 1; |
RobinN7 | 0:3af30bfbc3e5 | 36 | } |
RobinN7 | 0:3af30bfbc3e5 | 37 | wait_ms(1); |
RobinN7 | 0:3af30bfbc3e5 | 38 | } |
RobinN7 | 0:3af30bfbc3e5 | 39 | |
RobinN7 | 15:b77dc649e4f3 | 40 | void passebas(int ordre) |
RobinN7 | 0:3af30bfbc3e5 | 41 | { |
AlexandreN7 | 10:3424e7b66671 | 42 | |
AlexandreN7 | 8:8f886cd6a59f | 43 | unsigned int tamponpixel[256] = {0}; |
RobinN7 | 15:b77dc649e4f3 | 44 | int i=0; |
RobinN7 | 15:b77dc649e4f3 | 45 | |
RobinN7 | 2:804797b0b298 | 46 | // Passe bas en partant de la gauche sur tamponpixel[0:127] |
RobinN7 | 15:b77dc649e4f3 | 47 | // et de la droite sur tamponpixel[128:255] |
AlexandreN7 | 8:8f886cd6a59f | 48 | for (i=ordre; i<128; i++) { |
RobinN7 | 15:b77dc649e4f3 | 49 | for (int a=0; a<=ordre; a++) { |
RobinN7 | 0:3af30bfbc3e5 | 50 | tamponpixel[i]+=pixel[i-a]; |
RobinN7 | 15:b77dc649e4f3 | 51 | tamponpixel[255-i]+=pixel[127-i+a]; |
RobinN7 | 0:3af30bfbc3e5 | 52 | } |
RobinN7 | 15:b77dc649e4f3 | 53 | tamponpixel[i]/=(ordre+1); |
RobinN7 | 15:b77dc649e4f3 | 54 | tamponpixel[255-i]/=(ordre+1); |
RobinN7 | 0:3af30bfbc3e5 | 55 | } |
AlexandreN7 | 8:8f886cd6a59f | 56 | |
RobinN7 | 15:b77dc649e4f3 | 57 | // Prolongement par continuité à gauche et à droite |
RobinN7 | 15:b77dc649e4f3 | 58 | for (i=0; i<ordre; i++) { |
RobinN7 | 15:b77dc649e4f3 | 59 | tamponpixel[i]=tamponpixel[ordre]; |
RobinN7 | 15:b77dc649e4f3 | 60 | tamponpixel[255-i]=tamponpixel[255-ordre]; |
RobinN7 | 0:3af30bfbc3e5 | 61 | } |
AlexandreN7 | 8:8f886cd6a59f | 62 | |
RobinN7 | 0:3af30bfbc3e5 | 63 | // Actualisation de l'image filtrée |
RobinN7 | 0:3af30bfbc3e5 | 64 | for (i=0;i<128;i++) |
RobinN7 | 0:3af30bfbc3e5 | 65 | { |
RobinN7 | 4:9730c81e3121 | 66 | pixel[i]=(tamponpixel[i]+tamponpixel[255-i])/2; |
AlexandreN7 | 10:3424e7b66671 | 67 | |
RobinN7 | 0:3af30bfbc3e5 | 68 | } |
AlexandreN7 | 8:8f886cd6a59f | 69 | } |
AlexandreN7 | 8:8f886cd6a59f | 70 | |
AlexandreN7 | 8:8f886cd6a59f | 71 | //fonction qui dérive le signal de la camera |
AlexandreN7 | 8:8f886cd6a59f | 72 | void derivation() |
AlexandreN7 | 8:8f886cd6a59f | 73 | { |
RobinN7 | 15:b77dc649e4f3 | 74 | unsigned int tamponpixel[128] = {0}; |
AlexandreN7 | 8:8f886cd6a59f | 75 | |
AlexandreN7 | 8:8f886cd6a59f | 76 | for (int i=1; i<128; i++) { |
RobinN7 | 15:b77dc649e4f3 | 77 | tamponpixel[i]=(pixel[i]-pixel[i-1]); |
AlexandreN7 | 8:8f886cd6a59f | 78 | } |
RobinN7 | 15:b77dc649e4f3 | 79 | tamponpixel[0]=tamponpixel[1]; |
AlexandreN7 | 8:8f886cd6a59f | 80 | |
AlexandreN7 | 8:8f886cd6a59f | 81 | // Actualisation de l'image filtrée |
AlexandreN7 | 8:8f886cd6a59f | 82 | for (int i=0; i<128; i++) { |
AlexandreN7 | 8:8f886cd6a59f | 83 | pixel[i]=tamponpixel[i]; |
AlexandreN7 | 8:8f886cd6a59f | 84 | } |
AlexandreN7 | 8:8f886cd6a59f | 85 | |
RobinN7 | 0:3af30bfbc3e5 | 86 | } |