src/vapiCameraCalibrate.c

Ir para a documentação deste ficheiro.
00001 
00007 #include <stdio.h>
00008 #include "vapiTypes.h"
00009 #include "vapi.h"
00010 #include "vapiAux.h"
00011 #include "vapiString.h"
00012 #include "vapiImagesAux.h"
00013 #include "vapiMacro.h"
00014 #include "vapiOperationList.h"
00015 #include "vapiOperationOptions.h"
00016 #include "vapiCameraCalibrate.h"
00017 #include "vapiGtkAuxWindow.h"   /* isto deve ser removido */
00018 
00024 void
00025 vapiCalibrateCameraCreateMacro (vOperationList * OperationList,
00026                                 vMacro * Macro, vapi3Options * Options,
00027                                 vBoolean CalculateConstant)
00028 {
00029         vEffect *tempOperation;
00030         vOptions *tempOptions;
00031 
00032         /*
00033          * Filtro de Cor
00034          */
00035         tempOperation = vapiOperationListSelectOperation
00036                 (OperationList, "Filtro de Cor");
00037 
00038         vapiMacroAddItem (Macro, tempOperation, Options->Option0);
00039 
00040         /*
00041          * Binarizar
00042          */
00043         tempOperation = vapiOperationListSelectOperation
00044                 (OperationList, "Binarizar");
00045 
00046         tempOptions = vapiOperationOptionsInit (tempOperation);
00047         tempOptions->ints[0] = 0;
00048 
00049         vapiMacroAddItem (Macro, tempOperation, tempOptions);
00050 
00051         /*
00052          * Filtro de Pontos isolados
00053          */
00054         tempOperation = vapiOperationListSelectOperation
00055                 (OperationList, "Filtro de Pontos Isolados");
00056 
00057         tempOptions = vapiOperationOptionsInit (tempOperation);
00058 
00059         vapiMacroAddItem (Macro, tempOperation, tempOptions);
00060         //vOptionsFree(tempOptions, tempOperation);
00061         /*
00062          * Erode
00063          */
00064         if (((vEffectOptions *) Options->Option1->CustomOptions)->times != 0)
00065         {
00066                 tempOperation = vapiOperationListSelectOperation
00067                         (OperationList, "Erode");
00068 
00069                 vapiMacroAddItem (Macro, tempOperation, Options->Option1);
00070         }
00071         /*
00072          * Dilate
00073          */
00074         if (((vEffectOptions *) Options->Option2->CustomOptions)->times != 0)
00075         {
00076                 tempOperation = vapiOperationListSelectOperation
00077                         (OperationList, "Dilate");
00078 
00079                 vapiMacroAddItem (Macro, tempOperation, Options->Option2);
00080         }
00081         /*
00082          * Centro Geométrico
00083          */
00084         tempOperation = vapiOperationListSelectOperation
00085                 (OperationList, "Contagem de objectos");
00086         tempOptions = vapiOperationOptionsInit (tempOperation);
00087         /*
00088          * Se não vamos calcular a constante, não vale a pena detectar pontos.
00089          * Esta é uma maneira de prevenir durante testes que se encontrem 
00090          * milhares de pontos.
00091          */
00092         tempOptions->booleans[0] = CalculateConstant;
00093 
00094         vapiMacroAddItem (Macro, tempOperation, tempOptions);
00095 
00096 
00097 }
00098 
00099 
00100 
00101 vapiCalibrateCameraReturn *
00102 vapiCalibrateCameraGetConstant (vOperationList * OperationList,
00103                                 vImages * Images,
00104                                 vapi3Options * OptionsA,
00105                                 vapi3Options * OptionsB,
00106                                 double distanceRealA, double distanceRealB,
00107                                 vBoolean CalculateConstant)
00108 {
00109         vMacroHeader *MacroA = vapiMacroNew ("A");
00110         vMacroHeader *MacroB = vapiMacroNew ("B");
00111         vMacroResult *ResultA, *ResultB;
00112         vapiCalibrateCameraReturn *OutResults =
00113                 malloc (sizeof (vapiCalibrateCameraReturn));
00114         int distanceImageA1, distanceImageA2, distanceImageA;
00115         int distanceImageB1, distanceImageB2, distanceImageB;
00116         double kA, kB, k;
00117 
00118         ResultA = vapiMacroResultInit ();
00119         ResultB = vapiMacroResultInit ();
00120 
00121         /*
00122          * Criar Macro
00123          */
00124         vapiCalibrateCameraCreateMacro (OperationList,
00125                                         MacroA->Macro, OptionsA,
00126                                         CalculateConstant);
00127         vapiCalibrateCameraCreateMacro (OperationList,
00128                                         MacroB->Macro, OptionsB,
00129                                         CalculateConstant);
00130         /*
00131          * Executar Tarefas, colocar sempre a original.
00132          */
00133         vImagesFreeActual (Images);
00134         vapiOriginal2Actual (Images);
00135         vapiApplyMacro (MacroA, Images, vFALSE, vFALSE);
00136         OutResults->imResultA = Images->Actual;
00137         vapiOriginal2Actual (Images);
00138         vapiApplyMacro (MacroB, Images, vFALSE, vFALSE);
00139         OutResults->imResultB = Images->Actual;
00140         vapiOriginal2Actual (Images);
00141         /*
00142          * calcular as distâncias, em Pixeis.
00143          */
00144         if (!CalculateConstant)
00145         {
00146                 goto FreeAndReturn;
00147         }
00148         /*
00149          * Verificar que temos 2 pontos em cada Resultado.
00150          */
00151         if (MacroA->PreviousResult->pointsNumber != 2)
00152         {
00153                 v_info ("CalibrateCamera: Numero de Pontos no resultado A diferente de 2");
00154                 goto FreeAndReturn;
00155         }
00156         if (MacroB->PreviousResult->pointsNumber != 2)
00157         {
00158                 v_info ("CalibrateCamera: Numero de Pontos no resultado B diferente de 2");
00159                 goto FreeAndReturn;
00160         }
00161         /*
00162          * Par A.
00163          */
00164         distanceImageA1 =
00165                 MacroA->PreviousResult->points[0].x -
00166                 MacroA->PreviousResult->points[1].x;
00167         if (distanceImageA1 < 0)
00168         {
00169                 distanceImageA1 = distanceImageA1 * (-1);
00170         }
00171         distanceImageA2 =
00172                 MacroA->PreviousResult->points[0].y -
00173                 MacroA->PreviousResult->points[1].y;
00174         if (distanceImageA2 < 0)
00175         {
00176                 distanceImageA2 = distanceImageA2 * (-1);
00177         }
00178 
00179         v_debug ("distanceA %d, %d", distanceImageA1, distanceImageA2);
00180 
00181         if (distanceImageA2 > distanceImageA1)
00182         {
00183                 distanceImageA = distanceImageA2;
00184         }
00185         else
00186         {
00187                 distanceImageA = distanceImageA1;
00188         }
00189         /*
00190          * Par B.
00191          */
00192         distanceImageB1 =
00193                 MacroB->PreviousResult->points[0].x -
00194                 MacroB->PreviousResult->points[1].x;
00195         if (distanceImageB1 < 0)
00196         {
00197                 distanceImageB1 = distanceImageB1 * (-1);
00198         }
00199         distanceImageB2 =
00200                 MacroB->PreviousResult->points[0].y -
00201                 MacroB->PreviousResult->points[1].y;
00202         if (distanceImageB2 < 0)
00203         {
00204                 distanceImageB2 = distanceImageB2 * (-1);
00205         }
00206 
00207         v_debug ("distanceB %d, %d", distanceImageB1, distanceImageB2);
00208 
00209         if (distanceImageB2 > distanceImageB1)
00210         {
00211                 distanceImageB = distanceImageB2;
00212         }
00213         else
00214         {
00215                 distanceImageB = distanceImageB1;
00216         }
00217 
00218         v_debug ("distancia A: %d , distancia B: %d", distanceImageA,
00219                  distanceImageB);
00220 
00221         /*
00222          * Calcular Constantes e constante média
00223          */
00224         if (!(distanceRealA > 0) || !(distanceRealB > 0))
00225         {
00226                 goto FreeAndReturn;
00227         }
00228 
00229         v_debug ("distancia Real A: %1.2f , distancia Real B: %1.2f",
00230                  distanceRealA, distanceRealB);
00231 
00232         /*
00233          * Cor A.
00234          */
00235         kA = distanceImageA / distanceRealA;
00236         /*
00237          * Cor B.
00238          */
00239         kB = distanceImageB / distanceRealB;
00240 
00241         v_debug ("valor da constante kA %1.2f e kB %1.2f", kA, kB);
00242 
00243         /*
00244          * Média.
00245          */
00246 
00247         k = (kB + kA) / 2;
00248 
00249         v_debug ("valor da constante %1.2f", k);
00250 
00251         OutResults->constant = k;
00252         /*
00253          * Libertar Espaço e encerrar função.
00254          */
00255 
00256       FreeAndReturn:
00257         vapiMacroDelete (MacroA);
00258         vapiMacroDelete (MacroB);
00259         vResultFree (ResultA);
00260         vResultFree (ResultB);
00261         return OutResults;
00262 }
00263 
00264 vapi3Options *
00265 vapi3OptionsInit ()
00266 {
00267         vapi3Options *Options = malloc (sizeof (vapi3Options));
00268         return Options;
00269 }
00270 
00271 void
00272 v3OptionsFree (vapi3Options * Options)
00273 {
00274         free (Options);
00275 }
00276 
00277 void
00278 vCalibrateCamerReturnFree (vapiCalibrateCameraReturn * calibrateReturn)
00279 {
00280         cvReleaseImage (&calibrateReturn->imResultA);
00281         cvReleaseImage (&calibrateReturn->imResultB);
00282         free (calibrateReturn);
00283 }

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