Tested on Nucleo F411RE Based on OV7670 without FIFO, SCCB protocol rewritten. View on TFT ILI9341, possible capture picture on sd Around 3 frames per second Basic image treatment: zoom, rotation, etc Very basic pattern recognition, pattern being stored on SD, after camera capture, or from .bmp file (rgb 565, 120x160 max)

Dependencies:   FastPWM SDFileSystem SPI_TFT_ILI9341 TFT_fonts imagetrlib mbed ov7670s

Dependents:   Practica4_Camara

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "global.h"
00003 #include "FastPWM.h"
00004 #include "imagetr.h"
00005 #include "ov7670s.h"
00006 #include "ov7670sreg.h"
00007 #include "SPI_TFT_ILI9341.h"
00008 #include "SDFileSystem.h"
00009 #include "Arial12x12.h"
00010 #include "Arial24x23.h"
00011 #include "Arial28x28.h"
00012 #include "font_big.h"
00013 
00014 #define SCTFT     PA_5 // sclk TFT
00015 #define MISOTFT     PA_6 //miso TFT
00016 #define MOSITFT     PA_7 //Mosi tft
00017 #define PA9     PA_9 // dc TFT
00018 #define PB6     PB_6 // cs TFT
00019 #define PA11     PA_11 // reset TFT pc7
00020 
00021 #define PCLK    PC_10 //camera Pixel clock 
00022 #define HREF    PC_11 //camera Href
00023 #define VSYNC   PC_12 // camera Vsync
00024 #define I2C_D   PB_3 // Camera SCCB port data
00025 #define I2C_CLK PB_10 // Camera SCCB port clock
00026 #define RESET   PB_12 // camera reset
00027 #define XCLK    PA_10 // camera system clock
00028 
00029 
00030 #define mD0     PC_2//camera Data
00031 #define mD1     PC_3//camera Data
00032 #define mD2     PC_4//camera Data
00033 #define mD3     PC_5//camera Data
00034 #define mD4     PC_6//camera Data
00035 #define mD5     PC_7//camera Data
00036 #define mD6     PC_8 // camera Data
00037 #define mD7     PC_9 //camera Data
00038 
00039 
00040 #define SCSD    PB_13    // sclk SD
00041 #define MISD    PB_14 //  miso SD
00042 #define MOSD    PB_15 // mosi SD
00043 
00044 #define PD2 PD_2 /: CS SD
00045 
00046 
00047 
00048 DigitalOut myled(LED1);
00049 InterruptIn my_button(USER_BUTTON);
00050 AnalogIn analog_value0(A0);
00051 AnalogIn analog_value1(A1);
00052 AnalogIn analog_value2(A2);
00053 AnalogIn analog_value3(A3);
00054 
00055 Timer Time;
00056 
00057 int mask =0x1FFC;
00058 
00059 #define QQVGA   19200          //160*120
00060 
00061 Serial pc(USBTX,USBRX);
00062 //camera
00063 OV7670 OV7670(I2C_D,I2C_CLK,XCLK,PortC,mask,RESET);
00064 // 4.7 Kohm pull up on I2C_D
00065 
00066 // the TFT is connected to SPI pin
00067 SPI_TFT_ILI9341 TFT(MOSITFT, MISOTFT, SCTFT, PB6, PA11, PA9,"TFT"); // mosi, miso, sclk, cs, reset, dc
00068 // LED on 3.3V with 1Kohm
00069 
00070 SDFileSystem sd(MOSD, MISD, SCSD, PD_2, "sd",NC,SDFileSystem::SWITCH_NONE,2500000); // mosi, miso, sclk, cs, cd unused, switchtype, speed spi
00071 
00072 imagetr imagetr;
00073 
00074 char desfile[25];
00075 char patfile[25];
00076 char filename[25];
00077 const int tmarray = nc*2*nl;
00078 unsigned char bank[tmarray];
00079 unsigned char bankt[nl][nc];
00080 unsigned char bankta[nlta][ncta][nv];
00081 unsigned char banktatc[nlta][ncta];
00082 unsigned char bankf[tmarray];
00083 unsigned char banktc[nl][nc];
00084 
00085 
00086 float meas0,measold0,meas1,measold1,meas2,measold2, meas3, measold3;
00087 
00088 int volatile statc=0;
00089 bool volatile captur =false;
00090 FILE *fp;
00091 
00092 void pressed()
00093 {
00094     wait (0.1);
00095     if (my_button==0) {
00096         if (statc==0) {
00097             pc.printf("capture requested\r\n");
00098             captur=true;
00099             TFT.foreground(Red);
00100             TFT.locate(0,0);
00101         }
00102         if (statc==1) {
00103             pc.printf("visu \r\n");
00104             fp = fopen(desfile, "r");
00105             for (int i=0; i<tmarray; i++) {
00106                 bankf[i] =fgetc(fp);
00107             }
00108             fclose(fp);
00109 
00110         }
00111         if (statc==2) {
00112             statc=0;
00113         } else {
00114             statc=statc+1;
00115         }
00116     }
00117 }
00118 void pressedtargnewca()
00119 {
00120     //start from first image cat extract target in desfile
00121     wait (0.1);
00122     if (my_button==0) {
00123         if (statc==0) {
00124             pc.printf("capture target requested \r\n");
00125             //imagetr.rgbtoy();
00126             imagetr.ytorgb(banktc);
00127             fp = fopen(desfile, "w");
00128             for (int i=0; i<tmarray; i++) {
00129                 fputc(bank[i], fp);
00130             }
00131             TFT.Bitmap(160,0,160,120,bank);
00132             pc.printf("captured target done \r\n");
00133             TFT.foreground(Green);
00134             TFT.locate(0,0);
00135             printf("  capture done");
00136             fclose(fp);
00137             pc.printf("open target file \r\n");
00138             fp = fopen(desfile, "r");
00139             for (int i=0; i<tmarray; i++) {
00140                 bank[i] =fgetc(fp);
00141             }
00142             fclose(fp);
00143             TFT.Bitmap(0,120,160,120,bank);
00144             imagetr.rgbtoy();
00145             imagetr.ytorgb(bankt);
00146 
00147         }
00148         if (statc==1) {
00149             printf("  target capture done");
00150             imagetr.extrta();
00151             imagetr.ytorgbta(bankta,0,patfile);
00152             TFT.fillrect(160,0,160,240,Green);
00153             TFT.Bitmap(160,10,ncta,nlta,bank);
00154             pc.printf("clear bank \r\n");
00155             for (int i=0; i<tmarray; i++) {
00156                 bank[i]=78;
00157             }
00158             fp = fopen(patfile, "r");
00159             pc.printf("get targetf \r\n");
00160             for (int i=0; i<tmarrayta; i++) {
00161                 bank[i] =fgetc(fp);
00162             }
00163             fclose(fp);
00164             imagetr.rgbtoyta();
00165             for (int i = 0; i<7; i++) {
00166                 imagetr.ytorgbtas(bankta,i);
00167                 TFT.Bitmap(40*(i/3),120+30* (i%3),ncta,nlta,bank);
00168             }
00169         }
00170         if (statc==2) {
00171             statc=0;
00172         } else {
00173             statc=statc+1;
00174 
00175         }
00176         pc.printf("new s:%d \r\n", statc);
00177     }
00178 }
00179 
00180 void pressedtargca()
00181 {
00182     //start from first image from camera extract
00183     wait (0.1);
00184     if (my_button==0) {
00185         if (statc==0) {
00186 
00187             pc.printf("view \r\n");
00188 
00189         }
00190         if (statc==1) {
00191             pc.printf("search \r\n");
00192         }
00193         if (statc==2) {
00194             statc=0;
00195         } else {
00196             statc=statc+1;
00197 
00198         }
00199     }
00200 }
00201 
00202 
00203 void sdtofile(const char sou[],const char des[])
00204 {
00205     pc.printf("open .bmp \r\n");
00206     int err = imagetr.BMP_tofile(0, 0, sou);
00207     if (err != 1) TFT.printf(" - Err: %d",err);
00208     TFT.Bitmap(0,0,160,120,bank);
00209 
00210     pc.printf("open .txt in write \r\n");
00211     fp = fopen(des, "w");
00212 
00213     for (int i=0; i<tmarray; i++) {
00214         fputc(bank[i], fp);
00215     }
00216     fclose(fp);
00217     pc.printf("open .txt in read \r\n");
00218     fp = fopen(des, "r");
00219     for (int i=0; i<tmarray; i++) {
00220         bank[i] =fgetc(fp);
00221     }
00222     fclose(fp);
00223     TFT.Bitmap(0,120,160,120,bank);
00224 }
00225 void pressedtargsd()
00226 {
00227     //start from first image in bankt extract target in bankta generate different target
00228     wait (0.1);
00229     if (my_button==0) {
00230 
00231         imagetr.extrta();
00232         imagetr.ytorgbta(bankta,0,desfile);
00233         TFT.Bitmap(160,10,ncta,nlta,bank);
00234         TFT.fillrect(0,120,160,240,Green);
00235         pc.printf("clear bank \r\n");
00236         for (int i=0; i<tmarray; i++) {
00237             bank[i]=78;
00238         }
00239         fp = fopen(desfile, "r");
00240         pc.printf("get targetf \r\n");
00241         for (int i=0; i<tmarrayta; i++) {
00242             bank[i] =fgetc(fp);
00243         }
00244         fclose(fp);
00245         imagetr.rgbtoyta();
00246         TFT.Bitmap(0,120,ncta,nlta,bank);
00247         for (int i = 0; i<7; i++) {
00248             imagetr.ytorgbtas(bankta,i);
00249             TFT.Bitmap(40*(i/3),120+30* (i%3),ncta,nlta,bank);
00250         }
00251         //sdtofile(des);
00252     }
00253 }
00254 
00255 void affinem(bool rec)
00256 {
00257     bool c = false;
00258     float ad;
00259     meas0 = analog_value0.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00260     meas0 = meas0 * 320-160 ;   // x colonnes
00261     if( fabs(meas0-measold0)>1 ) {
00262         measold0=meas0;
00263         c=true;
00264     }
00265     meas1 = analog_value1.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00266     meas1 = meas1 * 240 -120;   // y lines
00267     if( fabs(meas1-measold1)>1 ) {
00268         measold1=meas1;
00269         c=true;
00270     }
00271 
00272     meas2 = analog_value2.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00273     meas2 = meas2 -0.5f;   // angle -0.5 a +0.5 (radiant)
00274     if( fabs(meas2-measold2)>0.1f ) {
00275         measold2=meas2;
00276         c=true;
00277     }
00278     meas3 = analog_value3.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00279     meas3 = 0.5f + (meas3 * 1.5f);   // zoom max1.5
00280     if( fabs(meas3-measold3)>0.5f ) {
00281         measold3=meas3;
00282         c=true;
00283     }
00284     if(c) {
00285 
00286         ad=180*meas2/3.14f;
00287         TFT.foreground(White);
00288         pc.printf("x: %d, y: %d, angle: %.2f zoom: %.2f \r\n", int(meas0),int(meas1), meas2, meas3);
00289         TFT.locate(170,45);
00290         printf("x %d",int(meas0));
00291         TFT.locate(170,65);
00292         printf("y %d",int(meas1));
00293         TFT.locate(170,105);
00294         printf("zoom %.2f",meas3);
00295         TFT.locate(170,85);
00296         printf("angle %.2f",ad);
00297         // imagetr.affine(0,0,0, 1.2);
00298         imagetr.affine(meas1,meas0,meas2, meas3);
00299         if (rec) {
00300             TFT.rect(160,120,160+ncta,120+nlta,Red);
00301         }
00302     }
00303 }
00304 void gentam(void)
00305 {
00306     bool c = false;
00307     float ad;
00308     meas0 = analog_value0.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00309     meas0 = meas0 * 0.2f + 0.8f;   // tilt x 0-20%
00310     if( fabs(meas0-measold0)>0.05f ) {
00311         measold0=meas0;
00312         c=true;
00313     }
00314     meas1 = analog_value1.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00315     meas1 = meas1 * 0.2f+0.8f;   // tilt y lines 0-20%
00316     if( fabs(meas1-measold1)>0.05f ) {
00317         measold1=meas1;
00318         c=true;
00319     }
00320 
00321     meas2 = analog_value2.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00322     meas2 = meas2 -0.5f;   // angle -0.5 a +0.5 (radiant)
00323     if( fabs(meas2-measold2)>0.1f ) {
00324         measold2=meas2;
00325         c=true;
00326     }
00327     meas3 = analog_value3.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00328     meas3 = 0.5f + (meas3 * 1.5f);   // zoom max1.5
00329     if( fabs(meas3-measold3)>0.3f ) {
00330         measold3=meas3;
00331         c=true;
00332     }
00333     if(c) {
00334         ad=180*meas2/3.14f;
00335         TFT.foreground(White);
00336         //pc.printf("x: %d, y: %d, angle: %.2f zoom: %.2f \r\n", int(meas0),int(meas1), meas2, meas3);
00337         TFT.locate(170,45);
00338         printf("tiltx %2f",meas0);
00339         TFT.locate(170,65);
00340         printf("tilty %2f",meas1);
00341         TFT.locate(170,105);
00342         printf("zoom %.2f",meas3);
00343         TFT.locate(170,85);
00344         printf("angle %.2f",ad);
00345         // imagetr.affine(0,0,0, 1.2);
00346         imagetr.genta(meas1,meas0,meas2, meas3);
00347     }
00348 }
00349 
00350 
00351 
00352 void luma(void)
00353 {
00354     float meas,measold;
00355     meas = analog_value3.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00356     meas = meas * 3;   // 0 a 10
00357     if( fabs(meas-measold)>0.1f ) {
00358         pc.printf("lumi: %04f \r\n", meas);
00359         TFT.locate(170,85);
00360         TFT.foreground(White);
00361         printf("lumi %f",meas);
00362         imagetr.lumi(meas);
00363         measold=meas;
00364     }
00365 
00366 }
00367 
00368 void searchp(char name[])
00369 {
00370     bool c = false;
00371     float ad;
00372     meas0 = analog_value0.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00373     meas0 = meas0 * 320-160 ;   // x colonnes
00374     if( fabs(meas0-measold0)>1 ) {
00375         measold0=meas0;
00376         c=true;
00377 
00378     }
00379     meas1 = analog_value1.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00380     meas1 =  meas1 * 100000;   // 0 a 100 000 -    50 000 is appropriate usually
00381     if( fabs(meas1-measold1)>200 ) {
00382         c=true;
00383     }
00384 
00385     meas2 = analog_value2.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00386     meas2 = meas2 -0.5f;   // angle -0.5 a +0.5 (radiant)
00387     if( fabs(meas2-measold2)>0.1f ) {
00388         measold2=meas2;
00389         c=true;
00390     }
00391     meas3 = analog_value3.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00392     meas3 = 0.5f + (meas3 * 1.5f);   // zoom max1.5
00393     if( fabs(meas3-measold3)>0.5f ) {
00394         measold3=meas3;
00395         c=true;
00396     }
00397     if(c) {
00398         ad=180*meas2/3.14f;
00399         TFT.foreground(White);
00400         //pc.printf("x: %d, y: %d, angle: %.2f zoom: %.2f \r\n", int(meas0),int(meas1), meas2, meas3);
00401         TFT.locate(170,45);
00402         printf("x %4d",int(meas0));
00403         TFT.locate(170,65);
00404         printf("threshold %6d",int(meas1));
00405         TFT.locate(170,105);
00406         printf("zoom %4.2f",meas3);
00407         TFT.locate(170,85);
00408         printf("angle %4.2f",ad);
00409         imagetr.affine(0,meas0,meas2, meas3);
00410         imagetr.searchpat(meas1, name);
00411     }
00412 }
00413 void viewf(void)
00414 {
00415     imagetr.ytorgb(banktc);
00416     TFT.Bitmap(160,120,160,120,bank);
00417 }
00418 
00419 void extedgem(void)
00420 {
00421     bool c = false;
00422     meas0 = analog_value0.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00423     meas0 = meas0 * 50;   // 0 to 50 max threshod
00424     if( fabs(meas0-measold0)>1) {
00425         measold0=meas0;
00426         c=true;
00427     }
00428     meas1 = analog_value1.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00429     meas1 = meas1 * 50  ; // min threshold 0 50
00430     if( fabs(meas1-measold1)>1 ) {
00431         measold1=meas1;
00432         c=true;
00433     }
00434     meas2 = analog_value2.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
00435     meas2 = meas2 * 5  ; // thrshold
00436     if( fabs(meas2-measold2)>1 ) {
00437         measold2=meas2;
00438         c=true;
00439     }
00440 
00441     if (c) {
00442         //pc.printf("x: %d, y: %d \r\n", int(meas0),int(meas1));
00443         imagetr.extedge(meas1,meas0, meas2);
00444     }
00445 }
00446 void loadtargettxt(const char sou[])
00447 {
00448     imagetr.getimage(sou);
00449     TFT.Bitmap(0,0,160,120,bank);
00450     imagetr.rgbtoy();
00451     imagetr.ytorgb(bankt);
00452     TFT.Bitmap(160,120,160,120,bank);
00453 }
00454 
00455 void loadtarget(const char sou[])
00456 {
00457     int err = imagetr.BMP_tofile(0, 0, sou);
00458     if (err != 1) TFT.printf(" - Err: %d",err);
00459     TFT.Bitmap(0,0,160,120,bank);
00460     imagetr.rgbtoy();
00461     //imagetr.ytorgb(bankt);
00462     //TFT.Bitmap(160,120,160,120,bank);
00463 }
00464 void loadtargeted(const char sou[])
00465 {
00466     int err = imagetr.BMP_tofile(0, 0, sou);
00467     if (err != 1) TFT.printf(" - Err: %d",err);
00468     TFT.Bitmap(0,0,160,120,bank);
00469     imagetr.rgbtoy();
00470     imagetr.extedge(0,0,2);
00471     for (int i=0; i<nl; i=i+1) {
00472         for (int j=0; j<nc; j=j+1) {
00473             bankt[i][j]= banktc[i][j];
00474         }
00475     }
00476     imagetr.ytorgb(bankt);
00477     TFT.Bitmap(160,120,160,120,bank);
00478 }
00479 void loadpat(const char pat[])
00480 {
00481     imagetr.getimage(pat);
00482     for  (int i=0; i<25; i++) {
00483        if (pat[i+4]!='.') { filename[i]=pat[i+4];} else {break;}
00484     }
00485     pc . printf("f : %s\r\n", filename);
00486     TFT.Bitmap(160,0,ncta,nlta,bank);
00487     imagetr.rgbtoyta();
00488     for (int i = 0; i<7; i++) {
00489         imagetr.ytorgbtas(bankta,i);
00490         TFT.Bitmap(40*(i/3),120+30* (i%3),ncta,nlta,bank);
00491     }
00492 }
00493 void loadpated(const char pat[])
00494 {
00495     imagetr.getimage(pat);
00496     for  (int i=0; i<25; i++) {
00497        if (pat[i+4]!='.') { filename[i]=pat[i+4];} else {break;}
00498     }
00499     pc . printf("f : %s\r\n", filename);
00500     TFT.Bitmap(160,0,ncta,nlta,bank);
00501     imagetr.rgbtoytaed();
00502     for (int i = 0; i<7; i++) {
00503         imagetr.ytorgbtas(bankta,i);
00504         TFT.Bitmap(40*(i/3),120+30* (i%3),ncta,nlta,bank);
00505     }
00506 }
00507 void readregister()
00508 {
00509     int tempo ;
00510     pc.printf("PID %02x \r\n", OV7670.ReadReg(REG_PID));
00511     pc.printf("VER %0.2x \r\n", OV7670.ReadReg(REG_VER));
00512 
00513     pc.printf("Lecture Registres...\r\n") ;
00514     pc.printf("AD : +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F") ;
00515     for (int i=0; i<OV7670_REGMAX; i++) {
00516 
00517         tempo = OV7670.ReadReg(i) ; // READ REG
00518         if ((i & 0x0F) == 0) {
00519             pc.printf("\r\n%02X : ",i) ;
00520         }
00521         pc.printf("%02X ",tempo) ;
00522     }
00523     pc.printf("\r\n") ;
00524 }
00525 void testsd(void)
00526 {
00527     //Perform a write test to SD
00528     // Set up the SD
00529     sd.disk_initialize();
00530     pc.printf("\nWriting to SD card...");
00531     fp = fopen("/sd/sdtest.txt", "w");
00532     if (fp != NULL) {
00533         fprintf(fp, "We're writing to an SD card!");
00534         fclose(fp);
00535         pc.printf("success!\r\n");
00536     } else {
00537         pc.printf("failed!\r\n");
00538     }
00539     //Perform a read test
00540     pc.printf("Reading from SD card...");
00541     fp = fopen("/sd/sdtest.txt", "r");
00542     if (fp != NULL) {
00543         char c = fgetc(fp);
00544         if (c == 'W')
00545             pc.printf("success!\r\n");
00546         else
00547             pc.printf("incorrect char (%c)!\r\n", c);
00548         fclose(fp);
00549     } else {
00550         pc.printf("failed!\r\n");
00551     }
00552 }
00553 
00554 void capturecycle(const char des[])
00555 {
00556     strcpy( desfile,des);
00557     if (statc==0||statc==1) {
00558         OV7670.CaptureNext() ;
00559         OV7670.exrgbf(0);
00560         TFT.Bitmap(0,120,160,120,bankf);
00561         OV7670.exrgbf(1);
00562         TFT.Bitmap(160,120,160,120,bankf);
00563         OV7670.exrgbf(2);
00564         TFT.Bitmap(0,0,160,120,bankf);
00565         OV7670.exrgbf(3);
00566         TFT.Bitmap(160,0,160,120,bankf);
00567     }
00568     if (statc==2) {
00569         OV7670.CaptureNext() ;
00570         TFT.fillrect(0,120,160,240,Green);
00571         TFT.fillrect(160,0,320,120,Green);
00572         TFT.foreground(Yellow);
00573         TFT.locate(170,108);
00574         printf("captured picture");
00575         TFT.Bitmap(0,0,160,120,bank);
00576         TFT.Bitmap(160,120,160,120,bankf);
00577     }
00578 }
00579 
00580 
00581 void epatternmatch(const char tar[],const char pat[])
00582 {
00583     loadtarget(tar);
00584     loadpat(pat);
00585     TFT.set_font((unsigned char*) Arial12x12);
00586     TFT.foreground(Red);
00587 }
00588 void epatternmatched(const char tar[],const char pat[])
00589 {
00590     loadtargeted(tar);
00591     loadpated(pat);
00592     TFT.set_font((unsigned char*) Arial12x12);
00593     TFT.foreground(Red);
00594 }
00595 void epatca(const char tar[],const char pat[])
00596 {
00597     loadtargettxt(tar);
00598     loadpat(pat);
00599     TFT.set_font((unsigned char*) Arial12x12);
00600     TFT.foreground(Red);
00601 }
00602 void patternmatch(const char pat[])
00603 {
00604     my_button.fall(&pressedtargca);
00605     OV7670.CaptureNext() ;
00606     TFT.Bitmap(0,0,160,120,bank);
00607     loadpat(pat);
00608     TFT.set_font((unsigned char*) Arial12x12);
00609     TFT.foreground(Red);
00610 }
00611 
00612 void targetfromca(const char des[],const char pat[])
00613 {
00614     OV7670.CaptureNext() ;
00615     TFT.Bitmap(0,0,160,120,bank);
00616     imagetr.rgbtoy();
00617     strcpy( desfile,des);
00618     strcpy( patfile,pat);
00619     my_button.fall(&pressedtargnewca);
00620 }
00621 void loadnewca()
00622 {
00623     OV7670.CaptureNext() ;
00624     TFT.Bitmap(0,0,160,120,bank);
00625     imagetr.rgbtoy();
00626 }
00627 
00628 void targetfromsd(const char sou[],const char des[])
00629 {
00630     int err = imagetr.BMP_tofile(0, 0, sou);
00631     if (err != 1) pc.printf(" - Err: %d",err);
00632     TFT.Bitmap(0,0,160,120,bank);
00633     imagetr.rgbtoy();
00634     strcpy( desfile,des);
00635     TFT.rect(160,120,160+ncta,120+nlta,Red);
00636     my_button.fall(&pressedtargsd);
00637 }
00638 
00639 
00640 int main()
00641 {
00642     myled=0;
00643     statc=0;
00644 
00645 
00646     // Set up the TFT
00647     TFT.claim(stdout);                          // Send stdout to the TFT display
00648     TFT.background(Black);                      // Set background to black
00649     TFT.foreground(White);                      // Set chars to white
00650     TFT.cls();                                  // Clear the screen
00651     TFT.set_font((unsigned char*) Arial12x12);  // Select the font
00652     TFT.set_orientation(3);                     // Select orientation
00653     TFT.locate(0,0);
00654     printf("  Hello Mbed ");
00655     OV7670.Reset();
00656     OV7670.Init("RGB", QQVGA);
00657     pc.printf("Hello World !\r\n");
00658 //////////////////////////////////////////////////////////
00659 // to view camera
00660 
00661     my_button.fall(&pressed);
00662 
00663     while (1) {
00664         capturecycle("/sd/picture.txt");
00665     }
00666 }
00667 
00668 //////////////////////////////////////////////////////////
00669 //////////////////////////////////////////////////////////
00670 // to create a target from a .bmp to sd
00671 /*
00672     targetfromsd("/sd/manchodou.bmp","/sd/manchodou.txt");
00673     while (1) {
00674         viewf();
00675         __disable_irq();    // Disable Interrupts
00676         affinem(true);
00677         __enable_irq();     // Enable Interrupts
00678     }
00679 }
00680 */
00681 //////////////////////////////////////////////////////////
00682 // to recognise a target from bmp and target on sd
00683 /*
00684      epatternmatch("/sd/manchodou.bmp","/sd/manchodou.txt");
00685      while (1) {
00686          viewf();
00687          searchp(filename);
00688      }
00689  }
00690  */
00691 //////////////////////////////////////////////////////////
00692 //////////////////////////////////////////////////////////
00693 // to recognise a target from bmp and target on sd, on edge
00694 /*
00695     epatternmatched("/sd/manchodou.bmp","/sd/manchodou.txt");
00696     while (1) {
00697 
00698         viewf();
00699         searchp(filename);
00700     }
00701 }
00702 */
00703 //////////////////////////////////////////////////////////
00704 //to create a target from camera
00705 /*
00706     targetfromca("/sd/man.txt","/sd/man2.txt");
00707     while (1) {
00708 
00709         __disable_irq();    // Disable Interrupts
00710         if (statc==0) {
00711             loadnewca();
00712         }
00713         affinem(true);
00714         __enable_irq();     // Enable Interrupts
00715 
00716 // if (statc==0) {   searchp();}  else {affinem(false);}
00717         viewf();
00718 
00719     }
00720 }
00721 */
00722 ////////////////////////////////////////////
00723 //to search pattern from .txt
00724 /*
00725  epatca("/sd/man.txt","/sd/man2.txt");
00726   while (1) {
00727      viewf();
00728     searchp(filename);
00729  }
00730 }
00731 */
00732 ////////////////////////////////////////////
00733 //to search pattern from camera
00734 /*
00735     patternmatch("/sd/man2.txt");
00736     while (1) {
00737         loadnewca();
00738          viewf();
00739         if (statc==0) {
00740             searchp(filename);
00741         }  else {
00742             affinem(false);
00743         }
00744     }
00745 }
00746 */
00747 ////////////////////////////////////////////
00748 // to extract edge from image in bmp
00749 /*
00750     loadtarget("/sd/manchodou.bmp");
00751     while (1) {
00752         viewf();
00753         extedgem();
00754     }
00755 }
00756 */