From 8e7768379ffecf83327a4fd3255703fa487c9166 Mon Sep 17 00:00:00 2001 From: Vladimir Dudnik Date: Mon, 18 Apr 2011 19:34:51 +0000 Subject: [PATCH] minor changes: removed trailing spaces in some files --- modules/features2d/src/surf.cpp | 77 +++++++++++----------- modules/objdetect/src/featurepyramid.cpp | 7 +- modules/objdetect/src/hog.cpp | 84 ++++++++++++------------ modules/objdetect/src/resizeimg.cpp | 17 ++--- 4 files changed, 92 insertions(+), 93 deletions(-) diff --git a/modules/features2d/src/surf.cpp b/modules/features2d/src/surf.cpp index 0b32dac27c..e9167759c7 100644 --- a/modules/features2d/src/surf.cpp +++ b/modules/features2d/src/surf.cpp @@ -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 * scale-space pyramid */ -CV_INLINE void +CV_INLINE void icvCalcLayerDetAndTrace( const CvMat* sum, int size, int sampleStep, CvMat *det, CvMat *trace ) { const int NX=3, NY=3, NXY=4; @@ -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 */ margin = (size/2)/sampleStep; - for( i=0; idata.i + (i*sampleStep)*sum->cols; det_ptr = det->data.fl + (i+margin)*det->cols + margin; @@ -275,9 +275,9 @@ icvFindMaximaInLayer( const CvMat *sum, const CvMat* mask_sum, const CvSURFParam CvSurfHF Dm; int i, j, size, margin, layer_rows, layer_cols; float *det_ptr, *trace_ptr; - + size = sizes[layer]; - + /* The integral image 'sum' is one pixel bigger than the source image */ layer_rows = (sum->rows-1)/sampleStep; layer_cols = (sum->cols-1)/sampleStep; @@ -287,7 +287,7 @@ icvFindMaximaInLayer( const CvMat *sum, const CvMat* mask_sum, const CvSURFParam if( mask_sum ) icvResizeHaarPattern( dm, &Dm, NM, 9, size, mask_sum->cols ); - + for( i = margin; i < layer_rows-margin; i++ ) { det_ptr = dets[layer]->data.fl + i*dets[layer]->cols; @@ -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 *det2 = dets[layer]->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[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[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[c-1] , det3[c] , det3[c+1] } }; @@ -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_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 ); /* Interpolate maxima location within the 3x3x3 neighbourhood */ @@ -352,14 +352,14 @@ icvFindMaximaInLayer( const CvMat *sum, const CvMat* mask_sum, const CvSURFParam /* Sometimes the interpolation step gives a negative size etc. */ if( interp_ok ) - { + { /*printf( "KeyPoint %f %f %d\n", point.pt.x, point.pt.y, point.size );*/ #ifdef HAVE_TBB static tbb::mutex m; tbb::mutex::scoped_lock lock(m); - #endif + #endif cvSeqPush( points, &point ); - } + } } } } @@ -381,13 +381,13 @@ struct SURFBuildInvoker dets = _dets; traces = _traces; } - + void operator()(const BlockedRange& range) const - { + { for( int i=range.begin(); i sampleSteps(nTotalLayers); cv::AutoBuffer middleIndices(nMiddleLayers); int octave, layer, step, index, middleIndex; - + /* Allocate space and calculate properties of each layer */ index = 0; middleIndex = 0; @@ -514,17 +514,17 @@ namespace cv { /* Methods to free data allocated in SURFInvoker constructor */ -template<> inline void Ptr::delete_obj(){ cvFree(&obj); } -template<> inline void Ptr::delete_obj(){ cvFree(&obj); } +template<> inline void Ptr::delete_obj() { cvFree(&obj); } +template<> inline void Ptr::delete_obj() { cvFree(&obj); } struct SURFInvoker { 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 DESC_SIGMA; - + SURFInvoker( const CvSURFParams* _params, CvSeq* _keypoints, CvSeq* _descriptors, const CvMat* _img, const CvMat* _sum ) @@ -537,7 +537,7 @@ struct SURFInvoker /* Simple bound for number of grid points in circle of radius ORI_RADIUS */ const int nOriSampleBound = (2*ORI_RADIUS+1)*(2*ORI_RADIUS+1); - + /* Allocate arrays */ apt = (CvPoint*)cvAlloc(nOriSampleBound*sizeof(CvPoint)); aptw = (float*)cvAlloc(nOriSampleBound*sizeof(float)); @@ -567,13 +567,14 @@ struct SURFInvoker DW[i*PATCH_SZ+j] = G_desc.at(i,0) * G_desc.at(j,0); } } + void operator()(const BlockedRange& range) const { /* X and Y gradient wavelet data */ const int NX=2, NY=2; 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 descriptor_size = params->extended ? 128 : 64; /* Optimisation is better using nOriSampleBound than nOriSamples for array lengths. Maybe because it is a constant known at compile time */ @@ -586,7 +587,7 @@ struct SURFInvoker CvMat matY = cvMat(1, nOriSampleBound, CV_32F, Y); CvMat _angle = cvMat(1, nOriSampleBound, CV_32F, angle); CvMat _patch = cvMat(PATCH_SZ+1, PATCH_SZ+1, CV_8U, PATCH); - + int k, k1 = range.begin(), k2 = range.end(); int maxSize = 0; for( k = k1; k < k2; k++ ) @@ -649,7 +650,7 @@ struct SURFInvoker } matX.cols = matY.cols = _angle.cols = nangle; cvCartToPolar( &matX, &matY, 0, &_angle, 1 ); - + float bestx = 0, besty = 0, descriptor_mod = 0; for( i = 0; i < 360; i += ORI_SEARCH_INC ) { @@ -682,7 +683,7 @@ struct SURFInvoker CvMat win = cvMat(win_size, win_size, CV_8U, winbuf->data.ptr); float sin_dir = sin(descriptor_dir); float cos_dir = cos(descriptor_dir) ; - + /* Subpixel interpolation version (slower). Subpixel not required since the pixels will all get averaged when we scale down to 20 pixels */ /* @@ -798,17 +799,17 @@ struct SURFInvoker const CvMat* sum; CvSeq* keypoints; CvSeq* descriptors; - + /* Pre-calculated values */ int nOriSamples; - cv::Ptr apt; - cv::Ptr aptw; + cv::Ptr apt; + cv::Ptr aptw; cv::Ptr DW; }; - -const int SURFInvoker::ORI_SEARCH_INC = 5; -const float SURFInvoker::ORI_SIGMA = 2.5f; -const float SURFInvoker::DESC_SIGMA = 3.3f; + +const int SURFInvoker::ORI_SEARCH_INC = 5; +const float SURFInvoker::ORI_SIGMA = 2.5f; +const float SURFInvoker::DESC_SIGMA = 3.3f; } @@ -870,9 +871,9 @@ cvExtractSURF( const CvArr* _img, const CvArr* _mask, cvSeqPushMulti( descriptors, 0, N ); } - - if ( N > 0 ) - cv::parallel_for(cv::BlockedRange(0, N), + + if ( N > 0 ) + cv::parallel_for(cv::BlockedRange(0, N), cv::SURFInvoker(¶ms, keypoints, descriptors, img, sum) ); diff --git a/modules/objdetect/src/featurepyramid.cpp b/modules/objdetect/src/featurepyramid.cpp index f5d4c51f0e..111c1fc4e1 100644 --- a/modules/objdetect/src/featurepyramid.cpp +++ b/modules/objdetect/src/featurepyramid.cpp @@ -10,14 +10,15 @@ #define min(a,b) (((a) < (b)) ? (a) : (b)) #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; return 0; } /* -// Getting feature map for the selected subimage +// Getting feature map for the selected subimage // // API // int getFeatureMaps(const IplImage * image, const int k, featureMap **map); @@ -29,7 +30,7 @@ static inline int sign(float r){ // RESULT // 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 p, px, strsz; diff --git a/modules/objdetect/src/hog.cpp b/modules/objdetect/src/hog.cpp index 093614ba7d..09ab7a874a 100644 --- a/modules/objdetect/src/hog.cpp +++ b/modules/objdetect/src/hog.cpp @@ -123,7 +123,7 @@ void HOGDescriptor::write(FileStorage& fs, const String& objName) const { if( !objName.empty() ) fs << objName; - + fs << "{" CV_TYPE_NAME_HOG_DESCRIPTOR << "winSize" << winSize << "blockSize" << blockSize @@ -139,7 +139,7 @@ void HOGDescriptor::write(FileStorage& fs, const String& objName) const fs << "SVMDetector" << "[:" << svmDetector << "]"; fs << "}"; } - + bool HOGDescriptor::load(const String& filename, const String& objname) { FileStorage fs(filename, FileStorage::READ); @@ -167,12 +167,12 @@ void HOGDescriptor::copyTo(HOGDescriptor& c) const c.gammaCorrection = gammaCorrection; c.svmDetector = svmDetector; } - + void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle, Size paddingTL, Size paddingBR) const { CV_Assert( img.type() == CV_8U || img.type() == CV_8UC3 ); - + Size gradsize(img.cols + paddingTL.width + paddingBR.width, img.rows + paddingTL.height + paddingBR.height); grad.create(gradsize, CV_32FC2); // @@ -221,13 +221,13 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle, #ifdef HAVE_IPP Mat lutimg(img.rows,img.cols,CV_MAKETYPE(CV_32F,cn)); Mat hidxs(1, width, CV_32F); - Ipp32f *pHidxs = (Ipp32f*)hidxs.data; - Ipp32f *pAngles = (Ipp32f*)Angle.data; + Ipp32f* pHidxs = (Ipp32f*)hidxs.data; + Ipp32f* pAngles = (Ipp32f*)Angle.data; IppiSize roiSize; roiSize.width = img.cols; roiSize.height = img.rows; - + for( y = 0; y < roiSize.height; y++ ) { const uchar* imgPtr = img.data + y*img.step; @@ -238,22 +238,22 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle, imglutPtr[x] = lut[imgPtr[x]]; } } - + #endif for( y = 0; y < gradsize.height; y++ ) { #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* nextPtr = (float*)(lutimg.data + lutimg.step*ymap[y+1]); #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* nextPtr = img.data + img.step*ymap[y+1]; #endif float* gradPtr = (float*)grad.ptr(y); uchar* qanglePtr = (uchar*)qangle.ptr(y); - + if( cn == 1 ) { for( x = 0; x < width; x++ ) @@ -281,18 +281,18 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle, dx0 = p2[2] - p0[2]; dy0 = nextPtr[x1+2] - prevPtr[x1+2]; mag0 = dx0*dx0 + dy0*dy0; - + dx = p2[1] - p0[1]; dy = nextPtr[x1+1] - prevPtr[x1+1]; mag = dx*dx + dy*dy; - + if( mag0 < mag ) { dx0 = dx; dy0 = dy; mag0 = mag; } - + dx = p2[0] - p0[0]; dy = nextPtr[x1] - prevPtr[x1]; mag = dx*dx + dy*dy; @@ -303,18 +303,18 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle, dx0 = lut[p2[2]] - lut[p0[2]]; dy0 = lut[nextPtr[x1+2]] - lut[prevPtr[x1+2]]; mag0 = dx0*dx0 + dy0*dy0; - + dx = lut[p2[1]] - lut[p0[1]]; dy = lut[nextPtr[x1+1]] - lut[prevPtr[x1+1]]; mag = dx*dx + dy*dy; - + if( mag0 < mag ) { dx0 = dx; dy0 = dy; mag0 = mag; } - + dx = lut[p2[0]] - lut[p0[0]]; dy = lut[nextPtr[x1]] - lut[prevPtr[x1]]; mag = dx*dx + dy*dy; @@ -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); 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); ippsFloor_32f(pAngles,(Ipp32f*)hidxs.data,width); ippsSub_32f_I((Ipp32f*)hidxs.data,pAngles,width); @@ -369,7 +369,7 @@ void HOGDescriptor::computeGradient(const Mat& img, Mat& grad, Mat& qangle, hidx++; hidx &= hidx < _nbins ? -1 : 0; qanglePtr[x*2+1] = (uchar)hidx; - } + } } } @@ -405,7 +405,7 @@ struct HOGCache const float* getBlock(Point pt, float* buf); virtual void normalizeBlockHistogram(float* histogram) const; - + vector pixData; vector blockData; @@ -525,7 +525,7 @@ void HOGCache::init(const HOGDescriptor* _descriptor, int icellX1 = icellX0 + 1, icellY1 = icellY0 + 1; cellX -= icellX0; cellY -= icellY0; - + if( (unsigned)icellX0 < (unsigned)ncells.width && (unsigned)icellX1 < (unsigned)ncells.width ) { @@ -626,7 +626,7 @@ const float* HOGCache::getBlock(Point pt, float* buf) CV_Assert( (unsigned)pt.x <= (unsigned)(grad.cols - blockSize.width) && (unsigned)pt.y <= (unsigned)(grad.rows - blockSize.height) ); - + if( useCache ) { CV_Assert( pt.x % cacheStride.width == 0 && @@ -658,7 +658,7 @@ const float* HOGCache::getBlock(Point pt, float* buf) for( k = 0; k < blockHistogramSize; k++ ) blockHist[k] = 0.f; #endif - + const PixData* _pixData = &pixData[0]; for( k = 0; k < C1; k++ ) @@ -681,13 +681,13 @@ const float* HOGCache::getBlock(Point pt, float* buf) float w, t0, t1, a0 = a[0], a1 = a[1]; const uchar* h = qanglePtr + pk.qangleOfs; int h0 = h[0], h1 = h[1]; - + float* hist = blockHist + pk.histOfs[0]; w = pk.gradWeight*pk.histWeights[0]; t0 = hist[h0] + a0*w; t1 = hist[h1] + a1*w; hist[h0] = t0; hist[h1] = t1; - + hist = blockHist + pk.histOfs[1]; w = pk.gradWeight*pk.histWeights[1]; t0 = hist[h0] + a0*w; @@ -702,13 +702,13 @@ const float* HOGCache::getBlock(Point pt, float* buf) float w, t0, t1, a0 = a[0], a1 = a[1]; const uchar* h = qanglePtr + pk.qangleOfs; int h0 = h[0], h1 = h[1]; - + float* hist = blockHist + pk.histOfs[0]; w = pk.gradWeight*pk.histWeights[0]; t0 = hist[h0] + a0*w; t1 = hist[h1] + a1*w; hist[h0] = t0; hist[h1] = t1; - + hist = blockHist + pk.histOfs[1]; w = pk.gradWeight*pk.histWeights[1]; t0 = hist[h0] + a0*w; @@ -750,7 +750,7 @@ void HOGCache::normalizeBlockHistogram(float* _hist) const for( i = 0; i < sz; i++ ) sum += hist[i]*hist[i]; #endif - + float scale = 1.f/(std::sqrt(sum)+sz*0.1f), thresh = (float)descriptor->L2HysThreshold; #ifdef HAVE_IPP ippsMulC_32f_I(scale,hist,sz); @@ -772,8 +772,8 @@ void HOGCache::normalizeBlockHistogram(float* _hist) const hist[i] *= scale; #endif } - - + + Size HOGCache::windowsInImage(Size imageSize, Size winStride) const { return Size((imageSize.width - winSize.width)/winStride.width + 1, @@ -801,7 +801,7 @@ void HOGDescriptor::compute(const Mat& img, vector& descriptors, padding.width = (int)alignSize(std::max(padding.width, 0), cacheStride.width); padding.height = (int)alignSize(std::max(padding.height, 0), cacheStride.height); Size paddedImgSize(img.cols + padding.width*2, img.rows + padding.height*2); - + HOGCache cache(this, img, padding, padding, nwindows == 0, cacheStride); if( !nwindows ) @@ -858,7 +858,7 @@ void HOGDescriptor::detect(const Mat& img, hits.clear(); if( svmDetector.empty() ) return; - + if( winStride == Size() ) winStride = cellSize; Size cacheStride(gcd(winStride.width, blockStride.width), @@ -867,7 +867,7 @@ void HOGDescriptor::detect(const Mat& img, padding.width = (int)alignSize(std::max(padding.width, 0), cacheStride.width); padding.height = (int)alignSize(std::max(padding.height, 0), cacheStride.height); Size paddedImgSize(img.cols + padding.width*2, img.rows + padding.height*2); - + HOGCache cache(this, img, padding, padding, nwindows == 0, cacheStride); if( !nwindows ) @@ -927,7 +927,7 @@ void HOGDescriptor::detect(const Mat& img, } } - + struct HOGInvoker { HOGInvoker( const HOGDescriptor* _hog, const Mat& _img, @@ -942,7 +942,7 @@ struct HOGInvoker levelScale = _levelScale; vec = _vec; } - + void operator()( const BlockedRange& range ) const { int i, i1 = range.begin(), i2 = range.end(); @@ -950,7 +950,7 @@ struct HOGInvoker Size maxSz(cvCeil(img.cols/minScale), cvCeil(img.rows/minScale)); Mat smallerImgBuf(maxSz, img.type()); vector locations; - + for( i = i1; i < i2; i++ ) { double scale = levelScale[i]; @@ -968,7 +968,7 @@ struct HOGInvoker scaledWinSize.width, scaledWinSize.height)); } } - + const HOGDescriptor* hog; Mat img; double hitThreshold; @@ -1001,22 +1001,22 @@ void HOGDescriptor::detectMultiScale( levelScale.resize(levels); ConcurrentRectVector allCandidates; - + parallel_for(BlockedRange(0, (int)levelScale.size()), HOGInvoker(this, img, hitThreshold, winStride, padding, &levelScale[0], &allCandidates)); - + foundLocations.resize(allCandidates.size()); std::copy(allCandidates.begin(), allCandidates.end(), foundLocations.begin()); groupRectangles(foundLocations, groupThreshold, 0.2); } - + typedef RTTIImpl HOGRTTI; CvType hog_type( CV_TYPE_NAME_HOG_DESCRIPTOR, HOGRTTI::isInstance, HOGRTTI::release, HOGRTTI::read, HOGRTTI::write, HOGRTTI::clone); - + vector HOGDescriptor::getDefaultPeopleDetector() { static const float detector[] = { diff --git a/modules/objdetect/src/resizeimg.cpp b/modules/objdetect/src/resizeimg.cpp index ac3ca348b1..088034c308 100644 --- a/modules/objdetect/src/resizeimg.cpp +++ b/modules/objdetect/src/resizeimg.cpp @@ -4,8 +4,9 @@ #include #include -IplImage * resize_opencv (IplImage * img, float scale){ - IplImage * imgTmp; +IplImage* resize_opencv(IplImage* img, float scale) +{ + IplImage* imgTmp; int W, H, tW, tH; @@ -14,14 +15,10 @@ IplImage * resize_opencv (IplImage * img, float scale){ tW = (int)(((float)W) * scale + 0.5); tH = (int)(((float)H) * scale + 0.5); - + imgTmp = cvCreateImage(cvSize(tW , tH), img->depth, img->nChannels); - cvResize( - img, - imgTmp, - CV_INTER_AREA - ); - + cvResize(img, imgTmp, CV_INTER_AREA); + return imgTmp; } @@ -42,7 +39,7 @@ IplImage * resize_opencv (IplImage * img, float scale){ // int i; // for(i = 0; i < n; i++){ // dst[ofs[i].di] += ofs[i].alpha * src[ofs[i].si]; -// } +// } //} // //int round(float val){