[opencv] 234/251: akaze: replace ceil()

Nobuhiro Iwamatsu iwamatsu at moszumanska.debian.org
Sun Aug 27 23:27:46 UTC 2017


This is an automated email from the git hooks/post-receive script.

iwamatsu pushed a commit to annotated tag 3.3.0
in repository opencv.

commit 8aca8d90d6fc9f97bf35555c5b707afcb9cfe586
Author: Alexander Alekhin <alexander.alekhin at intel.com>
Date:   Thu Aug 3 12:04:02 2017 +0300

    akaze: replace ceil()
    
    - integer division => divUp()
    - cast to 'int' => cvCeil()
---
 modules/features2d/src/akaze.cpp                   |  4 +-
 modules/features2d/src/kaze/AKAZEFeatures.cpp      | 80 +++++++++++++---------
 modules/features2d/src/kaze/fed.cpp                |  2 +-
 .../features2d/src/kaze/nldiffusion_functions.cpp  |  2 +-
 4 files changed, 50 insertions(+), 38 deletions(-)

diff --git a/modules/features2d/src/akaze.cpp b/modules/features2d/src/akaze.cpp
index 570d747..baca3c6 100644
--- a/modules/features2d/src/akaze.cpp
+++ b/modules/features2d/src/akaze.cpp
@@ -113,12 +113,12 @@ namespace cv
                 if (descriptor_size == 0)
                 {
                     int t = (6 + 36 + 120) * descriptor_channels;
-                    return (int)ceil(t / 8.);
+                    return divUp(t, 8);
                 }
                 else
                 {
                     // We use the random bit selection length binary descriptor
-                    return (int)ceil(descriptor_size / 8.);
+                    return divUp(descriptor_size, 8);
                 }
 
             default:
diff --git a/modules/features2d/src/kaze/AKAZEFeatures.cpp b/modules/features2d/src/kaze/AKAZEFeatures.cpp
index 1f4e67c..dff9e44 100644
--- a/modules/features2d/src/kaze/AKAZEFeatures.cpp
+++ b/modules/features2d/src/kaze/AKAZEFeatures.cpp
@@ -106,7 +106,7 @@ void AKAZEFeatures::Allocate_Memory_Evolution(void) {
  */
 static inline int getGaussianKernelSize(float sigma) {
   // Compute an appropriate kernel size according to the specified sigma
-  int ksize = (int)ceil(2.0f*(1.0f + (sigma - 0.8f) / (0.3f)));
+  int ksize = (int)cvCeil(2.0f*(1.0f + (sigma - 0.8f) / (0.3f)));
   ksize |= 1; // kernel should be odd
   return ksize;
 }
@@ -1131,20 +1131,17 @@ void AKAZEFeatures::Compute_Descriptors(std::vector<KeyPoint>& kpts, OutputArray
   }
 
   // Allocate memory for the matrix with the descriptors
-  if (options_.descriptor < AKAZE::DESCRIPTOR_MLDB_UPRIGHT) {
-    descriptors.create((int)kpts.size(), 64, CV_32FC1);
-  }
-  else {
-    // We use the full length binary descriptor -> 486 bits
-    if (options_.descriptor_size == 0) {
-      int t = (6 + 36 + 120)*options_.descriptor_channels;
-      descriptors.create((int)kpts.size(), (int)ceil(t / 8.), CV_8UC1);
-    }
-    else {
-      // We use the random bit selection length binary descriptor
-      descriptors.create((int)kpts.size(), (int)ceil(options_.descriptor_size / 8.), CV_8UC1);
-    }
+  int descriptor_size = 64;
+  int descriptor_type = CV_32FC1;
+  if (options_.descriptor >= AKAZE::DESCRIPTOR_MLDB_UPRIGHT)
+  {
+    int descriptor_bits = (options_.descriptor_size == 0)
+          ? (6 + 36 + 120)*options_.descriptor_channels // the full length binary descriptor -> 486 bits
+          : options_.descriptor_size; // the random bit selection length binary descriptor
+    descriptor_size = divUp(descriptor_bits, 8);
+    descriptor_type = CV_8UC1;
   }
+  descriptors.create((int)kpts.size(), descriptor_size, descriptor_type);
 
   Mat desc = descriptors.getMat();
 
@@ -1701,10 +1698,11 @@ void Upright_MLDB_Full_Descriptor_Invoker::Get_Upright_MLDB_Full_Descriptor(cons
 
   // For 2x2 grid, 3x3 grid and 4x4 grid
   const int pattern_size = options_->descriptor_pattern_size;
-  int sample_step[3] = {
+  CV_Assert((pattern_size & 1) == 0);
+  const int sample_step[3] = {
     pattern_size,
-    static_cast<int>(ceil(pattern_size*2./3.)),
-    pattern_size / 2
+    divUp(pattern_size * 2, 3),
+    divUp(pattern_size, 2)
   };
 
   // For the three grids
@@ -1873,8 +1871,16 @@ void MLDB_Full_Descriptor_Invoker::Get_MLDB_Full_Descriptor(const KeyPoint& kpt,
 
   const int max_channels = 3;
   CV_Assert(options_->descriptor_channels <= max_channels);
+  const int pattern_size = options_->descriptor_pattern_size;
+
   float values[16*max_channels];
-  const double size_mult[3] = {1, 2.0/3.0, 1.0/2.0};
+  CV_Assert((pattern_size & 1) == 0);
+  //const double size_mult[3] = {1, 2.0/3.0, 1.0/2.0};
+  const int sample_step[3] = { // static_cast<int>(ceil(pattern_size * size_mult[lvl]))
+    pattern_size,
+    divUp(pattern_size * 2, 3),
+    divUp(pattern_size, 2)
+  };
 
   float ratio = (float)(1 << kpt.octave);
   float scale = (float)fRound(0.5f*kpt.size / ratio);
@@ -1883,14 +1889,12 @@ void MLDB_Full_Descriptor_Invoker::Get_MLDB_Full_Descriptor(const KeyPoint& kpt,
   float angle = (kpt.angle * static_cast<float>(CV_PI)) / 180.f;
   float co = cos(angle);
   float si = sin(angle);
-  int pattern_size = options_->descriptor_pattern_size;
 
   int dpos = 0;
   for(int lvl = 0; lvl < 3; lvl++) {
 
       int val_count = (lvl + 2) * (lvl + 2);
-      int sample_step = static_cast<int>(ceil(pattern_size * size_mult[lvl]));
-      MLDB_Fill_Values(values, sample_step, kpt.class_id, xf, yf, co, si, scale);
+      MLDB_Fill_Values(values, sample_step[lvl], kpt.class_id, xf, yf, co, si, scale);
       MLDB_Binary_Comparisons(values, desc, val_count, dpos);
   }
 }
@@ -1930,14 +1934,18 @@ void MLDB_Descriptor_Subset_Invoker::Get_MLDB_Descriptor_Subset(const KeyPoint&
   Mat values((4 + 9 + 16)*options.descriptor_channels, 1, CV_32FC1);
 
   // Sample everything, but only do the comparisons
-  vector<int> steps(3);
-  steps.at(0) = options.descriptor_pattern_size;
-  steps.at(1) = (int)ceil(2.f*options.descriptor_pattern_size / 3.f);
-  steps.at(2) = options.descriptor_pattern_size / 2;
+  const int pattern_size = options.descriptor_pattern_size;
+  CV_Assert((pattern_size & 1) == 0);
+  const int sample_steps[3] = {
+    pattern_size,
+    divUp(pattern_size * 2, 3),
+    divUp(pattern_size, 2)
+  };
 
   for (int i = 0; i < descriptorSamples_.rows; i++) {
     const int *coords = descriptorSamples_.ptr<int>(i);
-    int sample_step = steps.at(coords[0]);
+    CV_Assert(coords[0] >= 0 && coords[0] < 3);
+    const int sample_step = sample_steps[coords[0]];
     di = 0.0f;
     dx = 0.0f;
     dy = 0.0f;
@@ -2025,14 +2033,18 @@ void Upright_MLDB_Descriptor_Subset_Invoker::Get_Upright_MLDB_Descriptor_Subset(
   // Allocate memory for the matrix of values
   Mat values ((4 + 9 + 16)*options.descriptor_channels, 1, CV_32FC1);
 
-  vector<int> steps(3);
-  steps.at(0) = options.descriptor_pattern_size;
-  steps.at(1) = static_cast<int>(ceil(2.f*options.descriptor_pattern_size / 3.f));
-  steps.at(2) = options.descriptor_pattern_size / 2;
+  const int pattern_size = options.descriptor_pattern_size;
+  CV_Assert((pattern_size & 1) == 0);
+  const int sample_steps[3] = {
+    pattern_size,
+    divUp(pattern_size * 2, 3),
+    divUp(pattern_size, 2)
+  };
 
   for (int i = 0; i < descriptorSamples_.rows; i++) {
     const int *coords = descriptorSamples_.ptr<int>(i);
-    int sample_step = steps.at(coords[0]);
+    CV_Assert(coords[0] >= 0 && coords[0] < 3);
+    int sample_step = sample_steps[coords[0]];
     di = 0.0f, dx = 0.0f, dy = 0.0f;
 
     for (int k = coords[1]; k < coords[1] + sample_step; k++) {
@@ -2120,7 +2132,7 @@ void generateDescriptorSubsample(Mat& sampleList, Mat& comparisons, int nbits,
   for (int i = 0, c = 0; i < 3; i++) {
     int gdiv = i + 2; //grid divisions, per row
     int gsz = gdiv*gdiv;
-    int psz = (int)ceil(2.f*pattern_size / (float)gdiv);
+    int psz = divUp(2*pattern_size, gdiv);
 
     for (int j = 0; j < gsz; j++) {
       for (int k = j + 1; k < gsz; k++, c++) {
@@ -2134,12 +2146,12 @@ void generateDescriptorSubsample(Mat& sampleList, Mat& comparisons, int nbits,
   }
 
   RNG rng(1024);
-  Mat_<int> comps = Mat_<int>(nchannels * (int)ceil(nbits / (float)nchannels), 2);
+  const int npicks = divUp(nbits, nchannels);
+  Mat_<int> comps = Mat_<int>(nchannels * npicks, 2);
   comps = 1000;
 
   // Select some samples. A sample includes all channels
   int count = 0;
-  int npicks = (int)ceil(nbits / (float)nchannels);
   Mat_<int> samples(29, 3);
   Mat_<int> fullcopy = fullM.clone();
   samples = -1;
diff --git a/modules/features2d/src/kaze/fed.cpp b/modules/features2d/src/kaze/fed.cpp
index cb47628..2026b83 100644
--- a/modules/features2d/src/kaze/fed.cpp
+++ b/modules/features2d/src/kaze/fed.cpp
@@ -72,7 +72,7 @@ int fed_tau_by_cycle_time(const float& t, const float& tau_max,
   float scale = 0.0;  // Ratio of t we search to maximal t
 
   // Compute necessary number of time steps
-  n = (int)(ceilf(sqrtf(3.0f*t/tau_max+0.25f)-0.5f-1.0e-8f)+ 0.5f);
+  n = cvCeil(sqrtf(3.0f*t/tau_max+0.25f)-0.5f-1.0e-8f);
   scale = 3.0f*t/(tau_max*(float)(n*(n+1)));
 
   // Call internal FED time step creation routine
diff --git a/modules/features2d/src/kaze/nldiffusion_functions.cpp b/modules/features2d/src/kaze/nldiffusion_functions.cpp
index c6e6068..16b9615 100644
--- a/modules/features2d/src/kaze/nldiffusion_functions.cpp
+++ b/modules/features2d/src/kaze/nldiffusion_functions.cpp
@@ -49,7 +49,7 @@ void gaussian_2D_convolution(const cv::Mat& src, cv::Mat& dst, int ksize_x, int
 
     // Compute an appropriate kernel size according to the specified sigma
     if (sigma > ksize_x || sigma > ksize_y || ksize_x == 0 || ksize_y == 0) {
-        ksize_x_ = (int)ceil(2.0f*(1.0f + (sigma - 0.8f) / (0.3f)));
+        ksize_x_ = cvCeil(2.0f*(1.0f + (sigma - 0.8f) / (0.3f)));
         ksize_y_ = ksize_x_;
     }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/opencv.git



More information about the debian-science-commits mailing list