From cc6a87fc9db919346d52bbf9c6d866019a730992 Mon Sep 17 00:00:00 2001 From: Alexey Spizhevoy Date: Tue, 16 Nov 2010 07:40:32 +0000 Subject: [PATCH] fixed big in gpu::HOGDescriptor, added property into CPU's HOGDescriptor --- modules/gpu/src/cuda/hog.cu | 8 ++++---- .../objdetect/include/opencv2/objdetect/objdetect.hpp | 9 ++++++--- modules/objdetect/src/hog.cpp | 3 +-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/gpu/src/cuda/hog.cu b/modules/gpu/src/cuda/hog.cu index 371ce7f55c..3dbaca037c 100644 --- a/modules/gpu/src/cuda/hog.cu +++ b/modules/gpu/src/cuda/hog.cu @@ -446,7 +446,7 @@ __global__ void compute_gradients_8UC4_kernel(int height, int width, const PtrEl if (threadIdx.x == 0) { - val = x > 0 ? row[x - 1] : row[x + 1]; + val = x > 0 ? row[x - 1] : row[1]; sh_row[0] = val.x; sh_row[(nthreads + 2)] = val.y; sh_row[2 * (nthreads + 2)] = val.z; @@ -454,7 +454,7 @@ __global__ void compute_gradients_8UC4_kernel(int height, int width, const PtrEl if (threadIdx.x == blockDim.x - 1) { - val = (x < width - 1) ? row[x + 1] : row[x - 1]; + val = (x < width - 1) ? row[x + 1] : row[width - 2]; sh_row[blockDim.x + 1] = val.x; sh_row[blockDim.x + 1 + (nthreads + 2)] = val.y; sh_row[blockDim.x + 1 + 2 * (nthreads + 2)] = val.z; @@ -553,10 +553,10 @@ __global__ void compute_gradients_8UC1_kernel(int height, int width, const PtrEl sh_row[threadIdx.x + 1] = row[x - 2]; if (threadIdx.x == 0) - sh_row[0] = x > 0 ? row[x - 1] : row[x + 1]; + sh_row[0] = x > 0 ? row[x - 1] : row[1]; if (threadIdx.x == blockDim.x - 1) - sh_row[blockDim.x + 1] = (x < width - 1) ? row[x + 1] : row[x - 1]; + sh_row[blockDim.x + 1] = (x < width - 1) ? row[x + 1] : row[width - 2]; __syncthreads(); if (x < width) diff --git a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp index e4f1f426a1..bddb6f496c 100644 --- a/modules/objdetect/include/opencv2/objdetect/objdetect.hpp +++ b/modules/objdetect/include/opencv2/objdetect/objdetect.hpp @@ -360,20 +360,22 @@ struct CV_EXPORTS_W HOGDescriptor { public: enum { L2Hys=0 }; + enum { DEFAULT_NLEVELS=64 }; CV_WRAP HOGDescriptor() : winSize(64,128), blockSize(16,16), blockStride(8,8), cellSize(8,8), nbins(9), derivAperture(1), winSigma(-1), - histogramNormType(HOGDescriptor::L2Hys), L2HysThreshold(0.2), gammaCorrection(true) + histogramNormType(HOGDescriptor::L2Hys), L2HysThreshold(0.2), gammaCorrection(true), + nlevels(DEFAULT_NLEVELS) {} CV_WRAP HOGDescriptor(Size _winSize, Size _blockSize, Size _blockStride, Size _cellSize, int _nbins, int _derivAperture=1, double _winSigma=-1, int _histogramNormType=HOGDescriptor::L2Hys, - double _L2HysThreshold=0.2, bool _gammaCorrection=false) + double _L2HysThreshold=0.2, bool _gammaCorrection=false, int _nlevels=DEFAULT_NLEVELS) : winSize(_winSize), blockSize(_blockSize), blockStride(_blockStride), cellSize(_cellSize), nbins(_nbins), derivAperture(_derivAperture), winSigma(_winSigma), histogramNormType(_histogramNormType), L2HysThreshold(_L2HysThreshold), - gammaCorrection(_gammaCorrection) + gammaCorrection(_gammaCorrection), nlevels(_nlevels) {} CV_WRAP HOGDescriptor(const String& filename) @@ -429,6 +431,7 @@ public: CV_PROP double L2HysThreshold; CV_PROP bool gammaCorrection; CV_PROP vector svmDetector; + CV_PROP int nlevels; }; diff --git a/modules/objdetect/src/hog.cpp b/modules/objdetect/src/hog.cpp index 43911c50d1..77678e1b6d 100644 --- a/modules/objdetect/src/hog.cpp +++ b/modules/objdetect/src/hog.cpp @@ -872,11 +872,10 @@ void HOGDescriptor::detectMultiScale( double scale0, int groupThreshold) const { double scale = 1.; - const int maxLevels = 64; int levels = 0; vector levelScale; - for( levels = 0; levels < maxLevels; levels++ ) + for( levels = 0; levels < nlevels; levels++ ) { levelScale.push_back(scale); if( cvRound(img.cols/scale) < winSize.width || -- 2.34.1