src/vapiCameraAcquisition.c

Ir para a documentação deste ficheiro.
00001 #include <stdio.h>
00002 #include <cxcore.h>
00003 #include <cv.h>
00004 #include <highgui.h>
00005 #include <cvaux.h>
00006 #include "vapiCameraAcquisition.h"
00007 #include "vapiAux.h"
00008 #include "vapiImagesAux.h"
00009 #include "vapiGtkAux.h"
00010 #include "vapi.h"
00011 #include "vapiTypes.h"
00012 #include "vapiOperationsDefault.h"
00013 #include "vapiCameraSettings.h"
00014 #ifndef VAPI_WITHOUT_INTERFACE
00015 #include "vapiGtkInterface.h"
00016 #endif
00017 
00018 static double NUMBER_OF_ACQUISITION_STEPS;
00019 
00020 int
00021 vapiGetSnapshotLocalCamera (vImages * Images,
00022                             vCameraSettings * CameraSettings)
00023 {
00024 
00025         IplImage *frame;
00026         int camera;
00027 
00028         v_debug ("Inicio de Captura com Câmara Local ");
00029 
00030         camera = vapiCameraSettingsGetLocalCameraNumber (CameraSettings);
00031 
00032         if (camera == -2)
00033         {
00034                 v_debug ("Saiu Com Erro ");
00035 
00036                 return 1;
00037         }
00038 
00039         vapiCameraAcquisitionLoadingStatus ("A iniciar Câmara",
00040                                             (1.0 /
00041                                              NUMBER_OF_ACQUISITION_STEPS));
00042 
00043         if (CameraSettings->LocalCameraFirstCapture)
00044         {
00045                 v_debug ("Primeira Captura");
00046 
00047                 vapiCameraSettingsSetCapture (CameraSettings,
00048                                               cvCaptureFromCAM (camera));
00049         }
00050 
00051 
00052         if (!cvGrabFrame (vapiCameraSettingsGetCapture (CameraSettings)))
00053         {
00054                 vapiCameraSettingsSetNoCapture (CameraSettings);
00055                 return 1;
00056         }
00057         v_debug ("Vai descarregar a frame da Câmara");
00058 
00059         //Grab frame
00060         vapiCameraAcquisitionLoadingStatus ("A Descarregar a Frame",
00061                                             (1.0 /
00062                                              NUMBER_OF_ACQUISITION_STEPS));
00063 
00064         frame = cvRetrieveFrame (vapiCameraSettingsGetCapture
00065                                  (CameraSettings));
00066         v_debug ("já tem a frame");
00067 
00068         if (!frame)
00069         {
00070                 vapiCameraSettingsSetNoCapture (CameraSettings);
00071                 cvReleaseImage (&frame);
00072                 return 1;
00073         }
00074 
00075         //Copy frame
00076 
00077         v_debug ("Tem a Frame, vai converter na imagem ");
00078 
00079         Images->Original = vapiImagesSameSize (frame, frame->nChannels);
00080 
00081         //check if frame is upside down
00082         if (frame->origin == IPL_ORIGIN_TL)
00083         {
00084                 cvCopy (frame, Images->Original, NULL);
00085         }
00086         else
00087         {
00088                 cvFlip (frame, Images->Original, 0);
00089         }
00090         //cvReleaseImage(&frame);
00091 
00092         return 0;
00093 
00094 
00095 
00096 }
00097 
00098 int
00099 vapiGetSnapshotLocalFile (vImages * Images, vCameraSettings * CameraSettings)
00100 {
00101 
00102         char *FileName;
00103 
00104         vapiCameraAcquisitionLoadingStatus ("A abrir o Ficheiro", (1.0 /
00105                                                                    NUMBER_OF_ACQUISITION_STEPS));
00106 
00107         FileName = vapiCameraSettingsGetLocalFilename (CameraSettings);
00108         if (FileName == NULL
00109             || !vapiFileIsReadable (CameraSettings->LocalFileName))
00110         {
00111                 return 1;
00112         }
00113         Images->Original = cvLoadImage (FileName, 3);
00114 
00115         return 0;
00116 }
00117 
00118 int
00119 vapiGetSnapshot (vImages * Images, vCameraSettings * CameraSettings)
00120 {
00121         int CameraERROR = 1;
00122         extern vBoolean HaveAcquisitionLoadingProgress;
00123         extern double NUMBER_OF_ACQUISITION_STEPS;
00124 
00125         if (MainLoadDone && HaveAcquisitionLoadingProgress)
00126         {
00127                 vapi_loading_progress_reset ();
00128         }
00129 
00130         switch (CameraSettings->CameraType)
00131         {
00132         case vCameraLocal:
00133         {
00134                 NUMBER_OF_ACQUISITION_STEPS = 3;
00135                 CameraERROR =
00136                         vapiGetSnapshotLocalCamera (Images, CameraSettings);
00137                 break;
00138         }
00139         case vCameraLocalFile:
00140         {
00141                 NUMBER_OF_ACQUISITION_STEPS = 2;
00142                 CameraERROR =
00143                         vapiGetSnapshotLocalFile (Images, CameraSettings);
00144 
00145         }
00146         }
00147         if (CameraERROR)
00148         {
00149                 NUMBER_OF_ACQUISITION_STEPS = 2;
00150                 vapiCameraAcquisitionLoadingStatus
00151                         ("Erro a Carregar Imagem", 1.0 /
00152                          NUMBER_OF_ACQUISITION_STEPS);
00153                 Images->Original =
00154                         cvLoadImage ("pixmaps/vapiErroDeCamara.png", 3);
00155         }
00156 
00157         vapiCameraAcquisitionLoadingStatus
00158                 ("Captura Terminada", (1.0 / NUMBER_OF_ACQUISITION_STEPS));
00159 
00160         HaveAcquisitionLoadingProgress = vFALSE;
00161 
00162         return CameraERROR;
00163 }
00164 
00165 
00166 int
00167 vapiGetHowManyCameras ()
00168 {
00169 
00170         IplImage *frame;
00171         CvCapture *capture;
00172         int i = 0;
00173 
00174         for (;;)
00175         {
00176 
00177                 //capture init
00178                 capture = cvCaptureFromCAM (i);
00179 
00180 
00181                 if (!cvGrabFrame (capture))
00182                 {
00183                         cvReleaseCapture (&capture);
00184                         return i;
00185                 }
00186 
00187                 //Grab frame
00188                 frame = cvRetrieveFrame (capture);
00189 
00190                 if (!frame)
00191                 {
00192                         cvReleaseCapture (&capture);
00193                         cvReleaseImage (&frame);
00194                         return i;
00195                 }
00196                 cvReleaseCapture (&capture);
00197 
00198                 ++i;
00199         }
00200 }
00201 
00202 
00203 void
00204 vapiCameraAcquisitionLoadingStatus (const char *Message, double steps)
00205 {
00206         extern vBoolean MainLoadDone;
00207         extern vBoolean HaveAcquisitionLoadingProgress;
00208 
00209         if (MainLoadDone && HaveAcquisitionLoadingProgress)
00210         {
00211                 vapi_loading_progress_step (Message, steps);
00212         }
00213 
00214         if (!MainLoadDone)
00215         {
00216 
00217                 vapi_loading_progress_main_steps (Message, steps);
00218         }
00219 }

Gerado em Tue Jul 24 10:34:58 2007 para Vapi por  doxygen 1.5.1