The main function */
| 146 | |
| 147 | /* The main function */ |
| 148 | CV_IMPL float cvCalcEMD2( const CvArr* signature_arr1, |
| 149 | const CvArr* signature_arr2, |
| 150 | int dist_type, |
| 151 | CvDistanceFunction dist_func, |
| 152 | const CvArr* cost_matrix, |
| 153 | CvArr* flow_matrix, |
| 154 | float *lower_bound, |
| 155 | void *user_param ) |
| 156 | { |
| 157 | cv::AutoBuffer<char> local_buf; |
| 158 | CvEMDState state; |
| 159 | float emd = 0; |
| 160 | |
| 161 | memset( &state, 0, sizeof(state)); |
| 162 | |
| 163 | double total_cost = 0; |
| 164 | int result = 0; |
| 165 | float eps, min_delta; |
| 166 | CvNode2D *xp = 0; |
| 167 | CvMat sign_stub1, *signature1 = (CvMat*)signature_arr1; |
| 168 | CvMat sign_stub2, *signature2 = (CvMat*)signature_arr2; |
| 169 | CvMat cost_stub, *cost = &cost_stub; |
| 170 | CvMat flow_stub, *flow = (CvMat*)flow_matrix; |
| 171 | int dims, size1, size2; |
| 172 | |
| 173 | signature1 = cvGetMat( signature1, &sign_stub1 ); |
| 174 | signature2 = cvGetMat( signature2, &sign_stub2 ); |
| 175 | |
| 176 | if( signature1->cols != signature2->cols ) |
| 177 | CV_Error( CV_StsUnmatchedSizes, "The arrays must have equal number of columns (which is number of dimensions but 1)" ); |
| 178 | |
| 179 | dims = signature1->cols - 1; |
| 180 | size1 = signature1->rows; |
| 181 | size2 = signature2->rows; |
| 182 | |
| 183 | if( !CV_ARE_TYPES_EQ( signature1, signature2 )) |
| 184 | CV_Error( CV_StsUnmatchedFormats, "The array must have equal types" ); |
| 185 | |
| 186 | if( CV_MAT_TYPE( signature1->type ) != CV_32FC1 ) |
| 187 | CV_Error( CV_StsUnsupportedFormat, "The signatures must be 32fC1" ); |
| 188 | |
| 189 | if( flow ) |
| 190 | { |
| 191 | flow = cvGetMat( flow, &flow_stub ); |
| 192 | |
| 193 | if( flow->rows != size1 || flow->cols != size2 ) |
| 194 | CV_Error( CV_StsUnmatchedSizes, |
| 195 | "The flow matrix size does not match to the signatures' sizes" ); |
| 196 | |
| 197 | if( CV_MAT_TYPE( flow->type ) != CV_32FC1 ) |
| 198 | CV_Error( CV_StsUnsupportedFormat, "The flow matrix must be 32fC1" ); |
| 199 | } |
| 200 | |
| 201 | cost->data.fl = 0; |
| 202 | cost->step = 0; |
| 203 | |
| 204 | if( dist_type < 0 ) |
| 205 | { |
no test coverage detected