Commit 8e776837 authored by Vladimir Dudnik's avatar Vladimir Dudnik

minor changes: removed trailing spaces in some files

parent dd45fe13
...@@ -156,7 +156,7 @@ icvResizeHaarPattern( const int src[][5], CvSurfHF* dst, int n, int oldSize, int ...@@ -156,7 +156,7 @@ icvResizeHaarPattern( const int src[][5], CvSurfHF* dst, int n, int oldSize, int
* Calculate the determinant and trace of the Hessian for a layer of the * Calculate the determinant and trace of the Hessian for a layer of the
* scale-space pyramid * scale-space pyramid
*/ */
CV_INLINE void CV_INLINE void
icvCalcLayerDetAndTrace( const CvMat* sum, int size, int sampleStep, CvMat *det, CvMat *trace ) icvCalcLayerDetAndTrace( const CvMat* sum, int size, int sampleStep, CvMat *det, CvMat *trace )
{ {
const int NX=3, NY=3, NXY=4; const int NX=3, NY=3, NXY=4;
...@@ -184,7 +184,7 @@ icvCalcLayerDetAndTrace( const CvMat* sum, int size, int sampleStep, CvMat *det, ...@@ -184,7 +184,7 @@ icvCalcLayerDetAndTrace( const CvMat* sum, int size, int sampleStep, CvMat *det,
/* Ignore pixels where some of the kernel is outside the image */ /* Ignore pixels where some of the kernel is outside the image */
margin = (size/2)/sampleStep; margin = (size/2)/sampleStep;
for( i=0; i<samples_i; i++ ) for( i = 0; i < samples_i; i++ )
{ {
sum_ptr = sum->data.i + (i*sampleStep)*sum->cols; sum_ptr = sum->data.i + (i*sampleStep)*sum->cols;
det_ptr = det->data.fl + (i+margin)*det->cols + margin; det_ptr = det->data.fl + (i+margin)*det->cols + margin;
...@@ -275,9 +275,9 @@ icvFindMaximaInLayer( const CvMat *sum, const CvMat* mask_sum, const CvSURFParam ...@@ -275,9 +275,9 @@ icvFindMaximaInLayer( const CvMat *sum, const CvMat* mask_sum, const CvSURFParam
CvSurfHF Dm; CvSurfHF Dm;
int i, j, size, margin, layer_rows, layer_cols; int i, j, size, margin, layer_rows, layer_cols;
float *det_ptr, *trace_ptr; float *det_ptr, *trace_ptr;
size = sizes[layer]; size = sizes[layer];
/* The integral image 'sum' is one pixel bigger than the source image */ /* The integral image 'sum' is one pixel bigger than the source image */
layer_rows = (sum->rows-1)/sampleStep; layer_rows = (sum->rows-1)/sampleStep;
layer_cols = (sum->cols-1)/sampleStep; layer_cols = (sum->cols-1)/sampleStep;
...@@ -287,7 +287,7 @@ icvFindMaximaInLayer( const CvMat *sum, const CvMat* mask_sum, const CvSURFParam ...@@ -287,7 +287,7 @@ icvFindMaximaInLayer( const CvMat *sum, const CvMat* mask_sum, const CvSURFParam
if( mask_sum ) if( mask_sum )
icvResizeHaarPattern( dm, &Dm, NM, 9, size, mask_sum->cols ); icvResizeHaarPattern( dm, &Dm, NM, 9, size, mask_sum->cols );
for( i = margin; i < layer_rows-margin; i++ ) for( i = margin; i < layer_rows-margin; i++ )
{ {
det_ptr = dets[layer]->data.fl + i*dets[layer]->cols; det_ptr = dets[layer]->data.fl + i*dets[layer]->cols;
...@@ -309,13 +309,13 @@ icvFindMaximaInLayer( const CvMat *sum, const CvMat* mask_sum, const CvSURFParam ...@@ -309,13 +309,13 @@ icvFindMaximaInLayer( const CvMat *sum, const CvMat* mask_sum, const CvSURFParam
const float *det1 = dets[layer-1]->data.fl + i*c + j; const float *det1 = dets[layer-1]->data.fl + i*c + j;
const float *det2 = dets[layer]->data.fl + i*c + j; const float *det2 = dets[layer]->data.fl + i*c + j;
const float *det3 = dets[layer+1]->data.fl + i*c + j; const float *det3 = dets[layer+1]->data.fl + i*c + j;
float N9[3][9] = { { det1[-c-1], det1[-c], det1[-c+1], float N9[3][9] = { { det1[-c-1], det1[-c], det1[-c+1],
det1[-1] , det1[0] , det1[1], det1[-1] , det1[0] , det1[1],
det1[c-1] , det1[c] , det1[c+1] }, det1[c-1] , det1[c] , det1[c+1] },
{ det2[-c-1], det2[-c], det2[-c+1], { det2[-c-1], det2[-c], det2[-c+1],
det2[-1] , det2[0] , det2[1], det2[-1] , det2[0] , det2[1],
det2[c-1] , det2[c] , det2[c+1] }, det2[c-1] , det2[c] , det2[c+1] },
{ det3[-c-1], det3[-c], det3[-c+1], { det3[-c-1], det3[-c], det3[-c+1],
det3[-1] , det3[0] , det3[1], det3[-1] , det3[0] , det3[1],
det3[c-1] , det3[c] , det3[c+1] } }; det3[c-1] , det3[c] , det3[c+1] } };
...@@ -343,7 +343,7 @@ icvFindMaximaInLayer( const CvMat *sum, const CvMat* mask_sum, const CvSURFParam ...@@ -343,7 +343,7 @@ icvFindMaximaInLayer( const CvMat *sum, const CvMat* mask_sum, const CvSURFParam
double center_i = sum_i + (double)(size-1)/2; double center_i = sum_i + (double)(size-1)/2;
double center_j = sum_j + (double)(size-1)/2; double center_j = sum_j + (double)(size-1)/2;
CvSURFPoint point = cvSURFPoint( cvPoint2D32f(center_j,center_i), CvSURFPoint point = cvSURFPoint( cvPoint2D32f(center_j,center_i),
CV_SIGN(trace_ptr[j]), sizes[layer], 0, val0 ); CV_SIGN(trace_ptr[j]), sizes[layer], 0, val0 );
/* Interpolate maxima location within the 3x3x3 neighbourhood */ /* Interpolate maxima location within the 3x3x3 neighbourhood */
...@@ -352,14 +352,14 @@ icvFindMaximaInLayer( const CvMat *sum, const CvMat* mask_sum, const CvSURFParam ...@@ -352,14 +352,14 @@ icvFindMaximaInLayer( const CvMat *sum, const CvMat* mask_sum, const CvSURFParam
/* Sometimes the interpolation step gives a negative size etc. */ /* Sometimes the interpolation step gives a negative size etc. */
if( interp_ok ) if( interp_ok )
{ {
/*printf( "KeyPoint %f %f %d\n", point.pt.x, point.pt.y, point.size );*/ /*printf( "KeyPoint %f %f %d\n", point.pt.x, point.pt.y, point.size );*/
#ifdef HAVE_TBB #ifdef HAVE_TBB
static tbb::mutex m; static tbb::mutex m;
tbb::mutex::scoped_lock lock(m); tbb::mutex::scoped_lock lock(m);
#endif #endif
cvSeqPush( points, &point ); cvSeqPush( points, &point );
} }
} }
} }
} }
...@@ -381,13 +381,13 @@ struct SURFBuildInvoker ...@@ -381,13 +381,13 @@ struct SURFBuildInvoker
dets = _dets; dets = _dets;
traces = _traces; traces = _traces;
} }
void operator()(const BlockedRange& range) const void operator()(const BlockedRange& range) const
{ {
for( int i=range.begin(); i<range.end(); i++ ) for( int i=range.begin(); i<range.end(); i++ )
icvCalcLayerDetAndTrace( sum, sizes[i], sampleSteps[i], dets[i], traces[i] ); icvCalcLayerDetAndTrace( sum, sizes[i], sampleSteps[i], dets[i], traces[i] );
} }
const CvMat *sum; const CvMat *sum;
const int *sizes; const int *sizes;
const int *sampleSteps; const int *sampleSteps;
...@@ -422,7 +422,7 @@ struct SURFFindInvoker ...@@ -422,7 +422,7 @@ struct SURFFindInvoker
icvFindMaximaInLayer( sum, mask_sum, params, dets, traces, sizes, layer, icvFindMaximaInLayer( sum, mask_sum, params, dets, traces, sizes, layer,
sampleSteps[layer], points ); sampleSteps[layer], points );
} }
} }
const CvMat *sum; const CvMat *sum;
const CvMat *mask_sum; const CvMat *mask_sum;
...@@ -440,7 +440,7 @@ struct SURFFindInvoker ...@@ -440,7 +440,7 @@ struct SURFFindInvoker
/* Wavelet size at first layer of first octave. */ /* Wavelet size at first layer of first octave. */
const int HAAR_SIZE0 = 9; const int HAAR_SIZE0 = 9;
/* Wavelet size increment between layers. This should be an even number, /* Wavelet size increment between layers. This should be an even number,
such that the wavelet sizes in an octave are either all even or all odd. such that the wavelet sizes in an octave are either all even or all odd.
...@@ -468,7 +468,7 @@ static CvSeq* icvFastHessianDetector( const CvMat* sum, const CvMat* mask_sum, ...@@ -468,7 +468,7 @@ static CvSeq* icvFastHessianDetector( const CvMat* sum, const CvMat* mask_sum,
cv::AutoBuffer<int> sampleSteps(nTotalLayers); cv::AutoBuffer<int> sampleSteps(nTotalLayers);
cv::AutoBuffer<int> middleIndices(nMiddleLayers); cv::AutoBuffer<int> middleIndices(nMiddleLayers);
int octave, layer, step, index, middleIndex; int octave, layer, step, index, middleIndex;
/* Allocate space and calculate properties of each layer */ /* Allocate space and calculate properties of each layer */
index = 0; index = 0;
middleIndex = 0; middleIndex = 0;
...@@ -514,17 +514,17 @@ namespace cv ...@@ -514,17 +514,17 @@ namespace cv
{ {
/* Methods to free data allocated in SURFInvoker constructor */ /* Methods to free data allocated in SURFInvoker constructor */
template<> inline void Ptr<float>::delete_obj(){ cvFree(&obj); } template<> inline void Ptr<float>::delete_obj() { cvFree(&obj); }
template<> inline void Ptr<CvPoint>::delete_obj(){ cvFree(&obj); } template<> inline void Ptr<CvPoint>::delete_obj() { cvFree(&obj); }
struct SURFInvoker struct SURFInvoker
{ {
enum { ORI_RADIUS = 6, ORI_WIN = 60, PATCH_SZ = 20 }; enum { ORI_RADIUS = 6, ORI_WIN = 60, PATCH_SZ = 20 };
static const int ORI_SEARCH_INC; static const int ORI_SEARCH_INC;
static const float ORI_SIGMA; static const float ORI_SIGMA;
static const float DESC_SIGMA; static const float DESC_SIGMA;
SURFInvoker( const CvSURFParams* _params, SURFInvoker( const CvSURFParams* _params,
CvSeq* _keypoints, CvSeq* _descriptors, CvSeq* _keypoints, CvSeq* _descriptors,
const CvMat* _img, const CvMat* _sum ) const CvMat* _img, const CvMat* _sum )
...@@ -537,7 +537,7 @@ struct SURFInvoker ...@@ -537,7 +537,7 @@ struct SURFInvoker
/* Simple bound for number of grid points in circle of radius ORI_RADIUS */ /* Simple bound for number of grid points in circle of radius ORI_RADIUS */
const int nOriSampleBound = (2*ORI_RADIUS+1)*(2*ORI_RADIUS+1); const int nOriSampleBound = (2*ORI_RADIUS+1)*(2*ORI_RADIUS+1);
/* Allocate arrays */ /* Allocate arrays */
apt = (CvPoint*)cvAlloc(nOriSampleBound*sizeof(CvPoint)); apt = (CvPoint*)cvAlloc(nOriSampleBound*sizeof(CvPoint));
aptw = (float*)cvAlloc(nOriSampleBound*sizeof(float)); aptw = (float*)cvAlloc(nOriSampleBound*sizeof(float));
...@@ -567,13 +567,14 @@ struct SURFInvoker ...@@ -567,13 +567,14 @@ struct SURFInvoker
DW[i*PATCH_SZ+j] = G_desc.at<float>(i,0) * G_desc.at<float>(j,0); DW[i*PATCH_SZ+j] = G_desc.at<float>(i,0) * G_desc.at<float>(j,0);
} }
} }
void operator()(const BlockedRange& range) const void operator()(const BlockedRange& range) const
{ {
/* X and Y gradient wavelet data */ /* X and Y gradient wavelet data */
const int NX=2, NY=2; const int NX=2, NY=2;
const int dx_s[NX][5] = {{0, 0, 2, 4, -1}, {2, 0, 4, 4, 1}}; const int dx_s[NX][5] = {{0, 0, 2, 4, -1}, {2, 0, 4, 4, 1}};
const int dy_s[NY][5] = {{0, 0, 4, 2, 1}, {0, 2, 4, 4, -1}}; const int dy_s[NY][5] = {{0, 0, 4, 2, 1}, {0, 2, 4, 4, -1}};
const int descriptor_size = params->extended ? 128 : 64; const int descriptor_size = params->extended ? 128 : 64;
/* Optimisation is better using nOriSampleBound than nOriSamples for /* Optimisation is better using nOriSampleBound than nOriSamples for
array lengths. Maybe because it is a constant known at compile time */ array lengths. Maybe because it is a constant known at compile time */
...@@ -586,7 +587,7 @@ struct SURFInvoker ...@@ -586,7 +587,7 @@ struct SURFInvoker
CvMat matY = cvMat(1, nOriSampleBound, CV_32F, Y); CvMat matY = cvMat(1, nOriSampleBound, CV_32F, Y);
CvMat _angle = cvMat(1, nOriSampleBound, CV_32F, angle); CvMat _angle = cvMat(1, nOriSampleBound, CV_32F, angle);
CvMat _patch = cvMat(PATCH_SZ+1, PATCH_SZ+1, CV_8U, PATCH); CvMat _patch = cvMat(PATCH_SZ+1, PATCH_SZ+1, CV_8U, PATCH);
int k, k1 = range.begin(), k2 = range.end(); int k, k1 = range.begin(), k2 = range.end();
int maxSize = 0; int maxSize = 0;
for( k = k1; k < k2; k++ ) for( k = k1; k < k2; k++ )
...@@ -649,7 +650,7 @@ struct SURFInvoker ...@@ -649,7 +650,7 @@ struct SURFInvoker
} }
matX.cols = matY.cols = _angle.cols = nangle; matX.cols = matY.cols = _angle.cols = nangle;
cvCartToPolar( &matX, &matY, 0, &_angle, 1 ); cvCartToPolar( &matX, &matY, 0, &_angle, 1 );
float bestx = 0, besty = 0, descriptor_mod = 0; float bestx = 0, besty = 0, descriptor_mod = 0;
for( i = 0; i < 360; i += ORI_SEARCH_INC ) for( i = 0; i < 360; i += ORI_SEARCH_INC )
{ {
...@@ -682,7 +683,7 @@ struct SURFInvoker ...@@ -682,7 +683,7 @@ struct SURFInvoker
CvMat win = cvMat(win_size, win_size, CV_8U, winbuf->data.ptr); CvMat win = cvMat(win_size, win_size, CV_8U, winbuf->data.ptr);
float sin_dir = sin(descriptor_dir); float sin_dir = sin(descriptor_dir);
float cos_dir = cos(descriptor_dir) ; float cos_dir = cos(descriptor_dir) ;
/* Subpixel interpolation version (slower). Subpixel not required since /* Subpixel interpolation version (slower). Subpixel not required since
the pixels will all get averaged when we scale down to 20 pixels */ the pixels will all get averaged when we scale down to 20 pixels */
/* /*
...@@ -798,17 +799,17 @@ struct SURFInvoker ...@@ -798,17 +799,17 @@ struct SURFInvoker
const CvMat* sum; const CvMat* sum;
CvSeq* keypoints; CvSeq* keypoints;
CvSeq* descriptors; CvSeq* descriptors;
/* Pre-calculated values */ /* Pre-calculated values */
int nOriSamples; int nOriSamples;
cv::Ptr<CvPoint> apt; cv::Ptr<CvPoint> apt;
cv::Ptr<float> aptw; cv::Ptr<float> aptw;
cv::Ptr<float> DW; cv::Ptr<float> DW;
}; };
const int SURFInvoker::ORI_SEARCH_INC = 5; const int SURFInvoker::ORI_SEARCH_INC = 5;
const float SURFInvoker::ORI_SIGMA = 2.5f; const float SURFInvoker::ORI_SIGMA = 2.5f;
const float SURFInvoker::DESC_SIGMA = 3.3f; const float SURFInvoker::DESC_SIGMA = 3.3f;
} }
...@@ -870,9 +871,9 @@ cvExtractSURF( const CvArr* _img, const CvArr* _mask, ...@@ -870,9 +871,9 @@ cvExtractSURF( const CvArr* _img, const CvArr* _mask,
cvSeqPushMulti( descriptors, 0, N ); cvSeqPushMulti( descriptors, 0, N );
} }
if ( N > 0 ) if ( N > 0 )
cv::parallel_for(cv::BlockedRange(0, N), cv::parallel_for(cv::BlockedRange(0, N),
cv::SURFInvoker(&params, keypoints, descriptors, img, sum) ); cv::SURFInvoker(&params, keypoints, descriptors, img, sum) );
......
...@@ -10,14 +10,15 @@ ...@@ -10,14 +10,15 @@
#define min(a,b) (((a) < (b)) ? (a) : (b)) #define min(a,b) (((a) < (b)) ? (a) : (b))
#endif #endif
static inline int sign(float r){ static inline int sign(float r)
{
if(r > 0.0001f) return 1; if(r > 0.0001f) return 1;
if(r < -0.0001f) return -1; if(r < -0.0001f) return -1;
return 0; return 0;
} }
/* /*
// Getting feature map for the selected subimage // Getting feature map for the selected subimage
// //
// API // API
// int getFeatureMaps(const IplImage * image, const int k, featureMap **map); // int getFeatureMaps(const IplImage * image, const int k, featureMap **map);
...@@ -29,7 +30,7 @@ static inline int sign(float r){ ...@@ -29,7 +30,7 @@ static inline int sign(float r){
// RESULT // RESULT
// Error status // Error status
*/ */
int getFeatureMaps_dp(const IplImage * image,const int k, CvLSVMFeatureMap **map) int getFeatureMaps_dp(const IplImage* image,const int k, CvLSVMFeatureMap **map)
{ {
int sizeX, sizeY; int sizeX, sizeY;
int p, px, strsz; int p, px, strsz;
......
...@@ -123,7 +123,7 @@ void HOGDescriptor::write(FileStorage& fs, const String& objName) const ...@@ -123,7 +123,7 @@ void HOGDescriptor::write(FileStorage& fs, const String& objName) const
{ {
if( !objName.empty() ) if( !objName.empty() )
fs << objName; fs << objName;
fs << "{" CV_TYPE_NAME_HOG_DESCRIPTOR fs << "{" CV_TYPE_NAME_HOG_DESCRIPTOR
<< "winSize" << winSize << "winSize" << winSize
<< "blockSize" << blockSize << "blockSize" << blockSize
...@@ -139,7 +139,7 @@ void HOGDescriptor::write(FileStorage& fs, const String& objName) const ...@@ -139,7 +139,7 @@ void HOGDescriptor::write(FileStorage& fs, const String& objName) const
fs << "SVMDetector" << "[:" << svmDetector << "]"; fs << "SVMDetector" << "[:" << svmDetector << "]";
fs << "}"; fs << "}";
} }
bool HOGDescriptor::load(const String& filename, const String& objname) bool HOGDescriptor::load(const String& filename, const String& objname)
{ {
FileStorage fs(filename, FileStorage::READ); FileStorage fs(filename, FileStorage::READ);
...@@ -167,12 +167,12 @@ void HOGDescriptor::copyTo(HOGDescriptor& c) const ...@@ -167,12 +167,12 @@ void HOGDescriptor::copyTo(HOGDescriptor& c) const
c.gammaCorrection = gammaCorrection; c.gammaCorrection = gammaCorrection;
c.svmDetector = svmDetector; c.svmDetector = svmDetector;
} }
void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle, void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle,
Size paddingTL, Size paddingBR) const Size paddingTL, Size paddingBR) const
{ {
CV_Assert( img.type() == CV_8U || img.type() == CV_8UC3 ); CV_Assert( img.type() == CV_8U || img.type() == CV_8UC3 );
Size gradsize(img.cols + paddingTL.width + paddingBR.width, Size gradsize(img.cols + paddingTL.width + paddingBR.width,
img.rows + paddingTL.height + paddingBR.height); img.rows + paddingTL.height + paddingBR.height);
grad.create(gradsize, CV_32FC2); // <magnitude*(1-alpha), magnitude*alpha> grad.create(gradsize, CV_32FC2); // <magnitude*(1-alpha), magnitude*alpha>
...@@ -221,13 +221,13 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle, ...@@ -221,13 +221,13 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle,
#ifdef HAVE_IPP #ifdef HAVE_IPP
Mat lutimg(img.rows,img.cols,CV_MAKETYPE(CV_32F,cn)); Mat lutimg(img.rows,img.cols,CV_MAKETYPE(CV_32F,cn));
Mat hidxs(1, width, CV_32F); Mat hidxs(1, width, CV_32F);
Ipp32f *pHidxs = (Ipp32f*)hidxs.data; Ipp32f* pHidxs = (Ipp32f*)hidxs.data;
Ipp32f *pAngles = (Ipp32f*)Angle.data; Ipp32f* pAngles = (Ipp32f*)Angle.data;
IppiSize roiSize; IppiSize roiSize;
roiSize.width = img.cols; roiSize.width = img.cols;
roiSize.height = img.rows; roiSize.height = img.rows;
for( y = 0; y < roiSize.height; y++ ) for( y = 0; y < roiSize.height; y++ )
{ {
const uchar* imgPtr = img.data + y*img.step; const uchar* imgPtr = img.data + y*img.step;
...@@ -238,22 +238,22 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle, ...@@ -238,22 +238,22 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle,
imglutPtr[x] = lut[imgPtr[x]]; imglutPtr[x] = lut[imgPtr[x]];
} }
} }
#endif #endif
for( y = 0; y < gradsize.height; y++ ) for( y = 0; y < gradsize.height; y++ )
{ {
#ifdef HAVE_IPP #ifdef HAVE_IPP
const float* imgPtr = (float*)(lutimg.data + lutimg.step*ymap[y]); const float* imgPtr = (float*)(lutimg.data + lutimg.step*ymap[y]);
const float* prevPtr = (float*)(lutimg.data + lutimg.step*ymap[y-1]); const float* prevPtr = (float*)(lutimg.data + lutimg.step*ymap[y-1]);
const float* nextPtr = (float*)(lutimg.data + lutimg.step*ymap[y+1]); const float* nextPtr = (float*)(lutimg.data + lutimg.step*ymap[y+1]);
#else #else
const uchar* imgPtr = img.data + img.step*ymap[y]; const uchar* imgPtr = img.data + img.step*ymap[y];
const uchar* prevPtr = img.data + img.step*ymap[y-1]; const uchar* prevPtr = img.data + img.step*ymap[y-1];
const uchar* nextPtr = img.data + img.step*ymap[y+1]; const uchar* nextPtr = img.data + img.step*ymap[y+1];
#endif #endif
float* gradPtr = (float*)grad.ptr(y); float* gradPtr = (float*)grad.ptr(y);
uchar* qanglePtr = (uchar*)qangle.ptr(y); uchar* qanglePtr = (uchar*)qangle.ptr(y);
if( cn == 1 ) if( cn == 1 )
{ {
for( x = 0; x < width; x++ ) for( x = 0; x < width; x++ )
...@@ -281,18 +281,18 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle, ...@@ -281,18 +281,18 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle,
dx0 = p2[2] - p0[2]; dx0 = p2[2] - p0[2];
dy0 = nextPtr[x1+2] - prevPtr[x1+2]; dy0 = nextPtr[x1+2] - prevPtr[x1+2];
mag0 = dx0*dx0 + dy0*dy0; mag0 = dx0*dx0 + dy0*dy0;
dx = p2[1] - p0[1]; dx = p2[1] - p0[1];
dy = nextPtr[x1+1] - prevPtr[x1+1]; dy = nextPtr[x1+1] - prevPtr[x1+1];
mag = dx*dx + dy*dy; mag = dx*dx + dy*dy;
if( mag0 < mag ) if( mag0 < mag )
{ {
dx0 = dx; dx0 = dx;
dy0 = dy; dy0 = dy;
mag0 = mag; mag0 = mag;
} }
dx = p2[0] - p0[0]; dx = p2[0] - p0[0];
dy = nextPtr[x1] - prevPtr[x1]; dy = nextPtr[x1] - prevPtr[x1];
mag = dx*dx + dy*dy; mag = dx*dx + dy*dy;
...@@ -303,18 +303,18 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle, ...@@ -303,18 +303,18 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle,
dx0 = lut[p2[2]] - lut[p0[2]]; dx0 = lut[p2[2]] - lut[p0[2]];
dy0 = lut[nextPtr[x1+2]] - lut[prevPtr[x1+2]]; dy0 = lut[nextPtr[x1+2]] - lut[prevPtr[x1+2]];
mag0 = dx0*dx0 + dy0*dy0; mag0 = dx0*dx0 + dy0*dy0;
dx = lut[p2[1]] - lut[p0[1]]; dx = lut[p2[1]] - lut[p0[1]];
dy = lut[nextPtr[x1+1]] - lut[prevPtr[x1+1]]; dy = lut[nextPtr[x1+1]] - lut[prevPtr[x1+1]];
mag = dx*dx + dy*dy; mag = dx*dx + dy*dy;
if( mag0 < mag ) if( mag0 < mag )
{ {
dx0 = dx; dx0 = dx;
dy0 = dy; dy0 = dy;
mag0 = mag; mag0 = mag;
} }
dx = lut[p2[0]] - lut[p0[0]]; dx = lut[p2[0]] - lut[p0[0]];
dy = lut[nextPtr[x1]] - lut[prevPtr[x1]]; dy = lut[nextPtr[x1]] - lut[prevPtr[x1]];
mag = dx*dx + dy*dy; mag = dx*dx + dy*dy;
...@@ -334,10 +334,10 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle, ...@@ -334,10 +334,10 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle,
ippsCartToPolar_32f((const Ipp32f*)Dx.data, (const Ipp32f*)Dy.data, (Ipp32f*)Mag.data, pAngles, width); ippsCartToPolar_32f((const Ipp32f*)Dx.data, (const Ipp32f*)Dy.data, (Ipp32f*)Mag.data, pAngles, width);
for( x = 0; x < width; x++ ) for( x = 0; x < width; x++ )
{ {
if(pAngles[x] < 0.f) pAngles[x]+=(Ipp32f)(CV_PI*2.); if(pAngles[x] < 0.f)
pAngles[x] += (Ipp32f)(CV_PI*2.);
} }
ippsNormalize_32f(pAngles, pAngles, width, 0.5f/angleScale, 1.f/angleScale); ippsNormalize_32f(pAngles, pAngles, width, 0.5f/angleScale, 1.f/angleScale);
ippsFloor_32f(pAngles,(Ipp32f*)hidxs.data,width); ippsFloor_32f(pAngles,(Ipp32f*)hidxs.data,width);
ippsSub_32f_I((Ipp32f*)hidxs.data,pAngles,width); ippsSub_32f_I((Ipp32f*)hidxs.data,pAngles,width);
...@@ -369,7 +369,7 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle, ...@@ -369,7 +369,7 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle,
hidx++; hidx++;
hidx &= hidx < _nbins ? -1 : 0; hidx &= hidx < _nbins ? -1 : 0;
qanglePtr[x*2+1] = (uchar)hidx; qanglePtr[x*2+1] = (uchar)hidx;
} }
} }
} }
...@@ -405,7 +405,7 @@ struct HOGCache ...@@ -405,7 +405,7 @@ struct HOGCache
const float* getBlock(Point pt, float* buf); const float* getBlock(Point pt, float* buf);
virtual void normalizeBlockHistogram(float* histogram) const; virtual void normalizeBlockHistogram(float* histogram) const;
vector<PixData> pixData; vector<PixData> pixData;
vector<BlockData> blockData; vector<BlockData> blockData;
...@@ -525,7 +525,7 @@ void HOGCache::init(const HOGDescriptor* _descriptor, ...@@ -525,7 +525,7 @@ void HOGCache::init(const HOGDescriptor* _descriptor,
int icellX1 = icellX0 + 1, icellY1 = icellY0 + 1; int icellX1 = icellX0 + 1, icellY1 = icellY0 + 1;
cellX -= icellX0; cellX -= icellX0;
cellY -= icellY0; cellY -= icellY0;
if( (unsigned)icellX0 < (unsigned)ncells.width && if( (unsigned)icellX0 < (unsigned)ncells.width &&
(unsigned)icellX1 < (unsigned)ncells.width ) (unsigned)icellX1 < (unsigned)ncells.width )
{ {
...@@ -626,7 +626,7 @@ const float* HOGCache::getBlock(Point pt, float* buf) ...@@ -626,7 +626,7 @@ const float* HOGCache::getBlock(Point pt, float* buf)
CV_Assert( (unsigned)pt.x <= (unsigned)(grad.cols - blockSize.width) && CV_Assert( (unsigned)pt.x <= (unsigned)(grad.cols - blockSize.width) &&
(unsigned)pt.y <= (unsigned)(grad.rows - blockSize.height) ); (unsigned)pt.y <= (unsigned)(grad.rows - blockSize.height) );
if( useCache ) if( useCache )
{ {
CV_Assert( pt.x % cacheStride.width == 0 && CV_Assert( pt.x % cacheStride.width == 0 &&
...@@ -658,7 +658,7 @@ const float* HOGCache::getBlock(Point pt, float* buf) ...@@ -658,7 +658,7 @@ const float* HOGCache::getBlock(Point pt, float* buf)
for( k = 0; k < blockHistogramSize; k++ ) for( k = 0; k < blockHistogramSize; k++ )
blockHist[k] = 0.f; blockHist[k] = 0.f;
#endif #endif
const PixData* _pixData = &pixData[0]; const PixData* _pixData = &pixData[0];
for( k = 0; k < C1; k++ ) for( k = 0; k < C1; k++ )
...@@ -681,13 +681,13 @@ const float* HOGCache::getBlock(Point pt, float* buf) ...@@ -681,13 +681,13 @@ const float* HOGCache::getBlock(Point pt, float* buf)
float w, t0, t1, a0 = a[0], a1 = a[1]; float w, t0, t1, a0 = a[0], a1 = a[1];
const uchar* h = qanglePtr + pk.qangleOfs; const uchar* h = qanglePtr + pk.qangleOfs;
int h0 = h[0], h1 = h[1]; int h0 = h[0], h1 = h[1];
float* hist = blockHist + pk.histOfs[0]; float* hist = blockHist + pk.histOfs[0];
w = pk.gradWeight*pk.histWeights[0]; w = pk.gradWeight*pk.histWeights[0];
t0 = hist[h0] + a0*w; t0 = hist[h0] + a0*w;
t1 = hist[h1] + a1*w; t1 = hist[h1] + a1*w;
hist[h0] = t0; hist[h1] = t1; hist[h0] = t0; hist[h1] = t1;
hist = blockHist + pk.histOfs[1]; hist = blockHist + pk.histOfs[1];
w = pk.gradWeight*pk.histWeights[1]; w = pk.gradWeight*pk.histWeights[1];
t0 = hist[h0] + a0*w; t0 = hist[h0] + a0*w;
...@@ -702,13 +702,13 @@ const float* HOGCache::getBlock(Point pt, float* buf) ...@@ -702,13 +702,13 @@ const float* HOGCache::getBlock(Point pt, float* buf)
float w, t0, t1, a0 = a[0], a1 = a[1]; float w, t0, t1, a0 = a[0], a1 = a[1];
const uchar* h = qanglePtr + pk.qangleOfs; const uchar* h = qanglePtr + pk.qangleOfs;
int h0 = h[0], h1 = h[1]; int h0 = h[0], h1 = h[1];
float* hist = blockHist + pk.histOfs[0]; float* hist = blockHist + pk.histOfs[0];
w = pk.gradWeight*pk.histWeights[0]; w = pk.gradWeight*pk.histWeights[0];
t0 = hist[h0] + a0*w; t0 = hist[h0] + a0*w;
t1 = hist[h1] + a1*w; t1 = hist[h1] + a1*w;
hist[h0] = t0; hist[h1] = t1; hist[h0] = t0; hist[h1] = t1;
hist = blockHist + pk.histOfs[1]; hist = blockHist + pk.histOfs[1];
w = pk.gradWeight*pk.histWeights[1]; w = pk.gradWeight*pk.histWeights[1];
t0 = hist[h0] + a0*w; t0 = hist[h0] + a0*w;
...@@ -750,7 +750,7 @@ void HOGCache::normalizeBlockHistogram(float* _hist) const ...@@ -750,7 +750,7 @@ void HOGCache::normalizeBlockHistogram(float* _hist) const
for( i = 0; i < sz; i++ ) for( i = 0; i < sz; i++ )
sum += hist[i]*hist[i]; sum += hist[i]*hist[i];
#endif #endif
float scale = 1.f/(std::sqrt(sum)+sz*0.1f), thresh = (float)descriptor->L2HysThreshold; float scale = 1.f/(std::sqrt(sum)+sz*0.1f), thresh = (float)descriptor->L2HysThreshold;
#ifdef HAVE_IPP #ifdef HAVE_IPP
ippsMulC_32f_I(scale,hist,sz); ippsMulC_32f_I(scale,hist,sz);
...@@ -772,8 +772,8 @@ void HOGCache::normalizeBlockHistogram(float* _hist) const ...@@ -772,8 +772,8 @@ void HOGCache::normalizeBlockHistogram(float* _hist) const
hist[i] *= scale; hist[i] *= scale;
#endif #endif
} }
Size HOGCache::windowsInImage(Size imageSize, Size winStride) const Size HOGCache::windowsInImage(Size imageSize, Size winStride) const
{ {
return Size((imageSize.width - winSize.width)/winStride.width + 1, return Size((imageSize.width - winSize.width)/winStride.width + 1,
...@@ -801,7 +801,7 @@ void HOGDescriptor::compute(const Mat& img, vector<float>& descriptors, ...@@ -801,7 +801,7 @@ void HOGDescriptor::compute(const Mat& img, vector<float>& descriptors,
padding.width = (int)alignSize(std::max(padding.width, 0), cacheStride.width); padding.width = (int)alignSize(std::max(padding.width, 0), cacheStride.width);
padding.height = (int)alignSize(std::max(padding.height, 0), cacheStride.height); padding.height = (int)alignSize(std::max(padding.height, 0), cacheStride.height);
Size paddedImgSize(img.cols + padding.width*2, img.rows + padding.height*2); Size paddedImgSize(img.cols + padding.width*2, img.rows + padding.height*2);
HOGCache cache(this, img, padding, padding, nwindows == 0, cacheStride); HOGCache cache(this, img, padding, padding, nwindows == 0, cacheStride);
if( !nwindows ) if( !nwindows )
...@@ -858,7 +858,7 @@ void HOGDescriptor::detect(const Mat& img, ...@@ -858,7 +858,7 @@ void HOGDescriptor::detect(const Mat& img,
hits.clear(); hits.clear();
if( svmDetector.empty() ) if( svmDetector.empty() )
return; return;
if( winStride == Size() ) if( winStride == Size() )
winStride = cellSize; winStride = cellSize;
Size cacheStride(gcd(winStride.width, blockStride.width), Size cacheStride(gcd(winStride.width, blockStride.width),
...@@ -867,7 +867,7 @@ void HOGDescriptor::detect(const Mat& img, ...@@ -867,7 +867,7 @@ void HOGDescriptor::detect(const Mat& img,
padding.width = (int)alignSize(std::max(padding.width, 0), cacheStride.width); padding.width = (int)alignSize(std::max(padding.width, 0), cacheStride.width);
padding.height = (int)alignSize(std::max(padding.height, 0), cacheStride.height); padding.height = (int)alignSize(std::max(padding.height, 0), cacheStride.height);
Size paddedImgSize(img.cols + padding.width*2, img.rows + padding.height*2); Size paddedImgSize(img.cols + padding.width*2, img.rows + padding.height*2);
HOGCache cache(this, img, padding, padding, nwindows == 0, cacheStride); HOGCache cache(this, img, padding, padding, nwindows == 0, cacheStride);
if( !nwindows ) if( !nwindows )
...@@ -927,7 +927,7 @@ void HOGDescriptor::detect(const Mat& img, ...@@ -927,7 +927,7 @@ void HOGDescriptor::detect(const Mat& img,
} }
} }
struct HOGInvoker struct HOGInvoker
{ {
HOGInvoker( const HOGDescriptor* _hog, const Mat& _img, HOGInvoker( const HOGDescriptor* _hog, const Mat& _img,
...@@ -942,7 +942,7 @@ struct HOGInvoker ...@@ -942,7 +942,7 @@ struct HOGInvoker
levelScale = _levelScale; levelScale = _levelScale;
vec = _vec; vec = _vec;
} }
void operator()( const BlockedRange& range ) const void operator()( const BlockedRange& range ) const
{ {
int i, i1 = range.begin(), i2 = range.end(); int i, i1 = range.begin(), i2 = range.end();
...@@ -950,7 +950,7 @@ struct HOGInvoker ...@@ -950,7 +950,7 @@ struct HOGInvoker
Size maxSz(cvCeil(img.cols/minScale), cvCeil(img.rows/minScale)); Size maxSz(cvCeil(img.cols/minScale), cvCeil(img.rows/minScale));
Mat smallerImgBuf(maxSz, img.type()); Mat smallerImgBuf(maxSz, img.type());
vector<Point> locations; vector<Point> locations;
for( i = i1; i < i2; i++ ) for( i = i1; i < i2; i++ )
{ {
double scale = levelScale[i]; double scale = levelScale[i];
...@@ -968,7 +968,7 @@ struct HOGInvoker ...@@ -968,7 +968,7 @@ struct HOGInvoker
scaledWinSize.width, scaledWinSize.height)); scaledWinSize.width, scaledWinSize.height));
} }
} }
const HOGDescriptor* hog; const HOGDescriptor* hog;
Mat img; Mat img;
double hitThreshold; double hitThreshold;
...@@ -1001,22 +1001,22 @@ void HOGDescriptor::detectMultiScale( ...@@ -1001,22 +1001,22 @@ void HOGDescriptor::detectMultiScale(
levelScale.resize(levels); levelScale.resize(levels);
ConcurrentRectVector allCandidates; ConcurrentRectVector allCandidates;
parallel_for(BlockedRange(0, (int)levelScale.size()), parallel_for(BlockedRange(0, (int)levelScale.size()),
HOGInvoker(this, img, hitThreshold, winStride, padding, &levelScale[0], &allCandidates)); HOGInvoker(this, img, hitThreshold, winStride, padding, &levelScale[0], &allCandidates));
foundLocations.resize(allCandidates.size()); foundLocations.resize(allCandidates.size());
std::copy(allCandidates.begin(), allCandidates.end(), foundLocations.begin()); std::copy(allCandidates.begin(), allCandidates.end(), foundLocations.begin());
groupRectangles(foundLocations, groupThreshold, 0.2); groupRectangles(foundLocations, groupThreshold, 0.2);
} }
typedef RTTIImpl<HOGDescriptor> HOGRTTI; typedef RTTIImpl<HOGDescriptor> HOGRTTI;
CvType hog_type( CV_TYPE_NAME_HOG_DESCRIPTOR, HOGRTTI::isInstance, CvType hog_type( CV_TYPE_NAME_HOG_DESCRIPTOR, HOGRTTI::isInstance,
HOGRTTI::release, HOGRTTI::read, HOGRTTI::write, HOGRTTI::clone); HOGRTTI::release, HOGRTTI::read, HOGRTTI::write, HOGRTTI::clone);
vector<float> HOGDescriptor::getDefaultPeopleDetector() vector<float> HOGDescriptor::getDefaultPeopleDetector()
{ {
static const float detector[] = { static const float detector[] = {
......
...@@ -4,8 +4,9 @@ ...@@ -4,8 +4,9 @@
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
IplImage * resize_opencv (IplImage * img, float scale){ IplImage* resize_opencv(IplImage* img, float scale)
IplImage * imgTmp; {
IplImage* imgTmp;
int W, H, tW, tH; int W, H, tW, tH;
...@@ -14,14 +15,10 @@ IplImage * resize_opencv (IplImage * img, float scale){ ...@@ -14,14 +15,10 @@ IplImage * resize_opencv (IplImage * img, float scale){
tW = (int)(((float)W) * scale + 0.5); tW = (int)(((float)W) * scale + 0.5);
tH = (int)(((float)H) * scale + 0.5); tH = (int)(((float)H) * scale + 0.5);
imgTmp = cvCreateImage(cvSize(tW , tH), img->depth, img->nChannels); imgTmp = cvCreateImage(cvSize(tW , tH), img->depth, img->nChannels);
cvResize( cvResize(img, imgTmp, CV_INTER_AREA);
img,
imgTmp,
CV_INTER_AREA
);
return imgTmp; return imgTmp;
} }
...@@ -42,7 +39,7 @@ IplImage * resize_opencv (IplImage * img, float scale){ ...@@ -42,7 +39,7 @@ IplImage * resize_opencv (IplImage * img, float scale){
// int i; // int i;
// for(i = 0; i < n; i++){ // for(i = 0; i < n; i++){
// dst[ofs[i].di] += ofs[i].alpha * src[ofs[i].si]; // dst[ofs[i].di] += ofs[i].alpha * src[ofs[i].si];
// } // }
//} //}
// //
//int round(float val){ //int round(float val){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment