Go to the documentation of this file.00001
00024 #include <opencv/cv.h>
00025 #include "Geometry.h"
00026 #include "Types.h"
00027
00028 using namespace DUtilsCV;
00029
00030
00031
00032 double Geometry::sqDistance(const cv::Mat &a, const cv::Mat &b)
00033 {
00034 assert( (a.rows == 1 || a.cols == 1) && (b.rows == 1 || b.cols == 1) );
00035 assert( a.rows*a.cols == b.rows*b.cols );
00036
00037 int N = (a.rows > 1 ? a.rows : a.cols);
00038
00039
00040
00041 double *adata = new double[N];
00042 double *bdata = new double[N];
00043
00044 Types::vectorize<double>(a, adata);
00045 Types::vectorize<double>(b, bdata);
00046
00047 double ret = 0.0;
00048
00049 if( N % 4 == 0)
00050 {
00051 for(int i = 0; i < N; i += 4)
00052 {
00053 ret += (adata[ i ]-bdata[ i ]) * (adata[ i ]-bdata[ i ]);
00054 ret += (adata[i+1]-bdata[i+1]) * (adata[i+1]-bdata[i+1]);
00055 ret += (adata[i+2]-bdata[i+2]) * (adata[i+2]-bdata[i+2]);
00056 ret += (adata[i+3]-bdata[i+3]) * (adata[i+3]-bdata[i+3]);
00057 }
00058 }
00059 else
00060 {
00061 for(int i = 0; i < N; ++i)
00062 ret += (adata[i]-bdata[i]) * (adata[i]-bdata[i]);
00063 }
00064
00065 delete [] adata;
00066 delete [] bdata;
00067
00068 return ret;
00069
00070 }
00071
00072
00073