00001
00018 #include "vetVision.h"
00019
00020
00027 vetVision::vetVision()
00028 {
00029 alertCall = NULL;
00030 alertCallArgument = NULL;
00031
00032 setName("Abstract Motion Detector");
00033 setDescription("Abstract Class");
00034 setVersion(0.0);
00035 }
00036
00037
00041 vetVision::~vetVision()
00042 {
00043
00044
00045 }
00046
00047
00048 void vetVision::doAlert()
00049 {
00050 if (alertCall != NULL)
00051 alertCall(alertCallArgument);
00052
00053 }
00054
00055
00056 int vetVision::getDifference(vetFrameYUV420& diff_img, vetFrameYUV420& source_img, vetFrameYUV420& second_img)
00057 {
00058 INFO("")
00059
00060 unsigned char* diff_ptr = diff_img.data;
00061 unsigned char* source_ptr = source_img.data;
00062 unsigned char* second_ptr = second_img.data;
00063
00064 for (unsigned int i=0; i<source_img.height*source_img.width*3; i++, diff_ptr++, source_ptr++, second_ptr++)
00065 {
00066 *diff_ptr = *source_ptr - *second_ptr;
00067 }
00068
00069 return VETRET_OK;
00070 }
00071
00072 int vetVision::getDifference(vetFrameRGB24& diff_img, vetFrameRGB24& source_img, vetFrameRGB24& second_img)
00073 {
00074 INFO("")
00075
00076 unsigned char* diff_ptr = diff_img.data[0];
00077 unsigned char* source_ptr = source_img.data[0];
00078 unsigned char* second_ptr = second_img.data[0];
00079
00080 for (unsigned int i=0; i<source_img.height*source_img.width*3; i++, diff_ptr++, source_ptr++, second_ptr++)
00081 {
00082 *diff_ptr = *source_ptr - *second_ptr;
00083 }
00084
00085 return VETRET_OK;
00086 }
00087
00088
00089 template<class T, class S, class J>
00090 static int getDifference(vetFrameT<T>& diff_img, vetFrameT<S>& source_img, vetFrameT<J>& second_img)
00091 {
00092 INFO("")
00093
00094 T* diff_ptr = diff_img.data[0];
00095 S* source_ptr = source_img.data[0];
00096 J* second_ptr = second_img.data[0];
00097
00098 for (unsigned int i=0; i<source_img.height*source_img.width*source_img.channelCount; i++, diff_ptr++, source_ptr++, second_ptr++)
00099 {
00100 *diff_ptr = (J)( *source_ptr - *second_ptr );
00101 }
00102
00103 return VETRET_OK;
00104 };
00105
00106
00107 int vetVision::getDifference(vetFrameT<unsigned char>& diff_img, vetFrameT<unsigned char>& source_img, vetFrameT<unsigned char>& second_img)
00108 {
00109 INFO("")
00110
00111 unsigned char* diff_ptr = diff_img.data;
00112 unsigned char* source_ptr = source_img.data;
00113 unsigned char* second_ptr = second_img.data;
00114
00115 for (unsigned int i=0; i<source_img.height*source_img.width; i++, diff_ptr++, source_ptr++, second_ptr++)
00116 {
00117 *diff_ptr = *source_ptr - *second_ptr;
00118 }
00119
00120 return VETRET_OK;
00121 }
00122
00123 int vetVision::getDifference(vetFrameT<int>& diff_img, vetFrameT<int>& source_img, vetFrameT<int>& second_img)
00124 {
00125 INFO("")
00126
00127 int* diff_ptr = diff_img.data;
00128 int* source_ptr = source_img.data;
00129 int* second_ptr = second_img.data;
00130
00131 for (unsigned int i=0; i<source_img.height*source_img.width; i++, diff_ptr++, source_ptr++, second_ptr++)
00132 {
00133 *diff_ptr = *source_ptr - *second_ptr;
00134 }
00135
00136 return VETRET_OK;
00137 }
00138
00139 int vetVision::getDifference(vetFrameT<float>& diff_img, vetFrameT<float>& source_img, vetFrameT<float>& second_img)
00140 {
00141 INFO("")
00142
00143 float* diff_ptr = diff_img.data;
00144 float* source_ptr = source_img.data;
00145 float* second_ptr = second_img.data;
00146
00147 for (unsigned int i=0; i<source_img.height*source_img.width; i++, diff_ptr++, source_ptr++, second_ptr++)
00148 {
00149 *diff_ptr = *source_ptr - *second_ptr;
00150 }
00151
00152 return VETRET_OK;
00153 }
00154
00155
00156
00157
00158 void vetVisionParameters::setDoEval(bool value)
00159 {
00160 doEval = value;
00161 }
00162
00163 void vetVisionParameters::setDoAlert(bool value)
00164 {
00165 doAlert = value;
00166 }
00167
00168
00169 int vetVisionParameters::saveToXML(const char* filename)
00170 {
00171 FILE *fp;
00172 int ret = VETRET_OK;
00173
00174 if ( (fp = fopen(filename, "w")) == NULL )
00175 return VETRET_PARAM_ERR;
00176
00177 if( fprintf(fp, "<?xml version=\"1.0\" ?>\n\n") == EOF )
00178 {
00179 fclose(fp);
00180 return VETRET_INTERNAL_ERR;
00181 }
00182
00183 ret = saveToStreamXML(fp);
00184
00185 fclose(fp);
00186
00187 return ret;
00188
00189 }
00190
00191
00192 int vetVisionParameters::loadFromXML(const char* filename)
00193 {
00194 FILE *fp;
00195 int ret = VETRET_OK;
00196
00197 if ( (fp=fopen(filename,"r")) == NULL )
00198 return VETRET_PARAM_ERR;
00199
00200 float xmlversion = 0;
00201
00202 fscanf(fp, "<?xml version=\"%f\" ?>\n\n", &xmlversion);
00203
00204 if (xmlversion == 0)
00205 throw "Incompatible XML file format";
00206
00207 ret = loadFromStreamXML(fp);
00208
00209
00210
00211 fclose(fp);
00212
00213 return ret;
00214 }
00215
00216