fixed big in gpu::HOGDescriptor, added property into CPU's HOGDescriptor
authorAlexey Spizhevoy <no@email>
Tue, 16 Nov 2010 07:40:32 +0000 (07:40 +0000)
committerAlexey Spizhevoy <no@email>
Tue, 16 Nov 2010 07:40:32 +0000 (07:40 +0000)
modules/gpu/src/cuda/hog.cu
modules/objdetect/include/opencv2/objdetect/objdetect.hpp
modules/objdetect/src/hog.cpp

index 371ce7f..3dbaca0 100644 (file)
@@ -446,7 +446,7 @@ __global__ void compute_gradients_8UC4_kernel(int height, int width, const PtrEl
 \r
     if (threadIdx.x == 0)\r
     {\r
-        val = x > 0 ? row[x - 1] : row[x + 1];\r
+        val = x > 0 ? row[x - 1] : row[1];\r
         sh_row[0] = val.x;\r
         sh_row[(nthreads + 2)] = val.y;\r
         sh_row[2 * (nthreads + 2)] = val.z;\r
@@ -454,7 +454,7 @@ __global__ void compute_gradients_8UC4_kernel(int height, int width, const PtrEl
 \r
     if (threadIdx.x == blockDim.x - 1)\r
     {\r
-        val = (x < width - 1) ? row[x + 1] : row[x - 1];\r
+        val = (x < width - 1) ? row[x + 1] : row[width - 2];\r
         sh_row[blockDim.x + 1] = val.x;\r
         sh_row[blockDim.x + 1 + (nthreads + 2)] = val.y;\r
         sh_row[blockDim.x + 1 + 2 * (nthreads + 2)] = val.z;\r
@@ -553,10 +553,10 @@ __global__ void compute_gradients_8UC1_kernel(int height, int width, const PtrEl
         sh_row[threadIdx.x + 1] = row[x - 2];\r
 \r
     if (threadIdx.x == 0)\r
-        sh_row[0] = x > 0 ? row[x - 1] : row[x + 1];\r
+        sh_row[0] = x > 0 ? row[x - 1] : row[1];\r
 \r
     if (threadIdx.x == blockDim.x - 1)\r
-        sh_row[blockDim.x + 1] = (x < width - 1) ? row[x + 1] : row[x - 1];\r
+        sh_row[blockDim.x + 1] = (x < width - 1) ? row[x + 1] : row[width - 2];\r
 \r
     __syncthreads();\r
     if (x < width)\r
index e4f1f42..bddb6f4 100644 (file)
@@ -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<float> svmDetector;
+    CV_PROP int nlevels;
 };
 
        
index 43911c5..77678e1 100644 (file)
@@ -872,11 +872,10 @@ void HOGDescriptor::detectMultiScale(
     double scale0, int groupThreshold) const
 {
     double scale = 1.;
-    const int maxLevels = 64;
     int levels = 0;
 
     vector<double> levelScale;
-    for( levels = 0; levels < maxLevels; levels++ )
+    for( levels = 0; levels < nlevels; levels++ )
     {
         levelScale.push_back(scale);
         if( cvRound(img.cols/scale) < winSize.width ||