diff --git a/modules/calib3d/src/circlesgrid.cpp b/modules/calib3d/src/circlesgrid.cpp index 635476dc4c..3982bf1a5d 100644 --- a/modules/calib3d/src/circlesgrid.cpp +++ b/modules/calib3d/src/circlesgrid.cpp @@ -1496,7 +1496,7 @@ size_t CirclesGridFinder::getFirstCorner(vector &largeCornerIndices, vect int cornerIdx = 0; bool waitOutsider = true; - while (true) + for(;;) { if (waitOutsider) { diff --git a/modules/features2d/include/opencv2/features2d/features2d.hpp b/modules/features2d/include/opencv2/features2d/features2d.hpp index 3608723259..b24aabed11 100644 --- a/modules/features2d/include/opencv2/features2d/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d/features2d.hpp @@ -404,24 +404,17 @@ public: class CV_EXPORTS ORB { public: - enum PatchSize - { - PATCH_LEARNED_31 = 31 - }; /** the size of the signature in bytes */ - static const int kBytes = 32; + enum { kBytes = 32 }; - struct CommonParams + struct CV_EXPORTS CommonParams { - static const unsigned int DEFAULT_N_LEVELS = 3; - static const float DEFAULT_SCALE_FACTOR; - static const unsigned int DEFAULT_FIRST_LEVEL = 0; - static const PatchSize DEFAULT_PATCH_SIZE; + enum { DEFAULT_N_LEVELS = 3, DEFAULT_FIRST_LEVEL = 0, DEFAULT_PATCH_SIZE = 31 }; /** default constructor */ - CommonParams(float scale_factor = DEFAULT_SCALE_FACTOR, unsigned int n_levels = DEFAULT_N_LEVELS, - unsigned int first_level = DEFAULT_FIRST_LEVEL, PatchSize patch_size = DEFAULT_PATCH_SIZE) : + CommonParams(float scale_factor = 1.2f, unsigned int n_levels = DEFAULT_N_LEVELS, + unsigned int first_level = DEFAULT_FIRST_LEVEL, int patch_size = DEFAULT_PATCH_SIZE) : scale_factor_(scale_factor), n_levels_(n_levels), first_level_(first_level >= n_levels ? 0 : first_level), patch_size_(patch_size) { @@ -438,7 +431,7 @@ public: */ unsigned int first_level_; /** The size of the patch that will be used for orientation and comparisons */ - PatchSize patch_size_; + int patch_size_; }; /** Default Constructor */ diff --git a/modules/features2d/src/detectors.cpp b/modules/features2d/src/detectors.cpp index d68a88589d..a1fa960e72 100644 --- a/modules/features2d/src/detectors.cpp +++ b/modules/features2d/src/detectors.cpp @@ -444,8 +444,7 @@ void ORB::CommonParams::read(const FileNode& fn) scale_factor_ = fn["scaleFactor"]; n_levels_ = int(fn["nLevels"]); first_level_ = int(fn["firsLevel"]); - int patch_size = fn["patchSize"]; - patch_size_ = PatchSize(patch_size); + patch_size_ = fn["patchSize"]; } void ORB::CommonParams::write(FileStorage& fs) const diff --git a/modules/features2d/src/orb.cpp b/modules/features2d/src/orb.cpp index 3a473c591e..a25ae7d860 100644 --- a/modules/features2d/src/orb.cpp +++ b/modules/features2d/src/orb.cpp @@ -75,8 +75,8 @@ template for (size_t u = 0; u <= 6; u++, ++dX_data, ++dY_data) { // 1, 2 for Sobel, 3 and 10 for Scharr - float Ix = 1 * (*dX_data + *(dX_data + 14)) + 2 * (*(dX_data + 7)); - float Iy = 1 * (*dY_data + *(dY_data + 2)) + 2 * (*(dY_data + 1)); + float Ix = (float)(1 * (*dX_data + *(dX_data + 14)) + 2 * (*(dX_data + 7))); + float Iy = (float)(1 * (*dY_data + *(dY_data + 2)) + 2 * (*(dY_data + 1))); a += Ix * Ix; b += Iy * Iy; @@ -154,8 +154,8 @@ HarrisResponse::HarrisResponse(const cv::Mat& image, double k) : void HarrisResponse::operator()(std::vector& kpts) const { // Those parameters are used to match the OpenCV computation of Harris corners - float scale = (1 << 2) * 7.0 * 255.0; - scale = 1.0 / scale; + float scale = (1 << 2) * 7.0f * 255.0f; + scale = 1.0f / scale; float scale_sq_sq = scale * scale * scale * scale; // define it to 1 if you want to compare to what OpenCV computes @@ -166,10 +166,10 @@ void HarrisResponse::operator()(std::vector& kpts) const #endif for (std::vector::iterator kpt = kpts.begin(), kpt_end = kpts.end(); kpt != kpt_end; ++kpt) { - cv::Mat patch = image_(cv::Rect(kpt->pt.x - 4, kpt->pt.y - 4, 9, 9)); + cv::Mat patch = image_(cv::Rect(cvRound(kpt->pt.x) - 4, cvRound(kpt->pt.y) - 4, 9, 9)); // Compute the response - kpt->response = harris (patch, k_, dX_offsets_, dY_offsets_) * scale_sq_sq; + kpt->response = harris (patch, (float)k_, dX_offsets_, dY_offsets_) * scale_sq_sq; #if HARRIS_TEST cv::Mat_ Ix(9, 9), Iy(9, 9); @@ -225,7 +225,7 @@ template // Go line by line in the circular patch std::vector::const_iterator horizontal_iterator = horizontal_offsets.begin(), vertical_iterator = vertical_offsets.begin(); - const SumType* val_ptr = &(integral_image.at (kpt.pt.y, kpt.pt.x)); + const SumType* val_ptr = &(integral_image.at (cvRound(kpt.pt.y), cvRound(kpt.pt.x))); for (int uv = 1; uv <= half_k; ++uv) { // Do the horizontal lines @@ -239,8 +239,8 @@ template vertical_iterator += 8; } - float x = m_10; - float y = m_01; + float x = (float)m_10; + float y = (float)m_01; kpt.angle = cv::fastAtan2(y, x); } @@ -249,7 +249,7 @@ template { SumType m_01 = 0, m_10 = 0/*, m_00 = 0*/; - const PatchType* val_center_ptr_plus = &(image.at (kpt.pt.y, kpt.pt.x)), *val_center_ptr_minus; + const PatchType* val_center_ptr_plus = &(image.at (cvRound(kpt.pt.y), cvRound(kpt.pt.x))), *val_center_ptr_minus; // Treat the center line differently, v=0 @@ -279,8 +279,8 @@ template m_01 += v * v_sum; } - float x = m_10;// / float(m_00);// / m_00; - float y = m_01;// / float(m_00);// / m_00; + float x = (float)m_10;// / float(m_00);// / m_00; + float y = (float)m_01;// / float(m_00);// / m_00; kpt.angle = cv::fastAtan2(y, x); } @@ -291,9 +291,9 @@ inline int smoothedSum(const int *center, const int* int_diff) return *(center + int_diff[2]) - *(center + int_diff[3]) - *(center + int_diff[1]) + *(center + int_diff[0]); } -inline char smoothed_comparison(const int * center, const int* diff, int l, int m) +inline uchar smoothed_comparison(const int * center, const int* diff, int l, int m) { - static const char score[] = {1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7}; + static const uchar score[] = {1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7}; return (smoothedSum(center, diff + l) < smoothedSum(center, diff + l + 4)) ? score[m] : 0; } } @@ -388,21 +388,21 @@ public: private: static inline int angle2Wedge(float angle) { - return (angle / 360) * kNumAngles; + return cvRound((angle / 360) * kNumAngles); } - void generateRelativePattern(int angle_idx, int sz, cv::Mat & relative_pattern) + void generateRelativePattern(int angle_idx, int /*sz*/, cv::Mat & relative_pattern) { // Create the relative pattern relative_pattern.create(512, 4, CV_32SC1); int * relative_pattern_data = reinterpret_cast (relative_pattern.data); // Get the original rotated pattern const int * pattern_data; - switch (sz) + //switch (sz) { - default: + //default: pattern_data = reinterpret_cast (rotated_patterns_[angle_idx].data); - break; + //break; } int half_kernel = ORB::kKernelWidth / 2; @@ -421,7 +421,7 @@ private: static cv::Mat getRotationMat(int angle_idx) { - float a = float(angle_idx) / kNumAngles * CV_PI * 2; + float a = float(float(angle_idx) / kNumAngles * CV_PI * 2); return (cv::Mat_(2, 2) << cos(a), -sin(a), sin(a), cos(a)); } @@ -443,13 +443,10 @@ private: std::vector ORB::OrbPatterns::rotated_patterns_ = OrbPatterns::generateRotatedPatterns(); //this is the definition for BIT_PATTERN -#include "orb_pattern.i" +#include "orb_pattern.hpp" //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -const float ORB::CommonParams::DEFAULT_SCALE_FACTOR = 1.2; -const ORB::PatchSize ORB::CommonParams::DEFAULT_PATCH_SIZE = ORB::PATCH_LEARNED_31; - /** Constructor * @param detector_params parameters to use */ @@ -457,12 +454,12 @@ ORB::ORB(size_t n_features, const CommonParams & detector_params) : params_(detector_params), n_features_(n_features) { // fill the extractors and descriptors for the corresponding scales - int n_desired_features_per_scale = n_features / ((1.0 / std::pow(params_.scale_factor_, 2.f * params_.n_levels_) - 1) - / (1.0 / std::pow(params_.scale_factor_, 2) - 1)); + int n_desired_features_per_scale = cvRound(n_features / ((1.0 / std::pow(params_.scale_factor_, 2.f * params_.n_levels_) - 1) + / (1.0 / std::pow(params_.scale_factor_, 2) - 1))); n_features_per_level_.resize(detector_params.n_levels_); for (unsigned int level = 0; level < detector_params.n_levels_; level++) { - n_desired_features_per_scale /= std::pow(params_.scale_factor_, 2); + n_desired_features_per_scale = cvRound(n_desired_features_per_scale / std::pow(params_.scale_factor_, 2)); n_features_per_level_[level] = n_desired_features_per_scale; } @@ -470,7 +467,7 @@ ORB::ORB(size_t n_features, const CommonParams & detector_params) : half_patch_size_ = params_.patch_size_ / 2; u_max_.resize(half_patch_size_ + 1); for (int v = 0; v <= half_patch_size_ * sqrt(2.f) / 2 + 1; ++v) - u_max_[v] = std::floor(sqrt(float(half_patch_size_ * half_patch_size_ - v * v)) + 0.5); + u_max_[v] = cvRound(sqrt(float(half_patch_size_ * half_patch_size_ - v * v))); // Make sure we are symmetric for (int v = half_patch_size_, v_0 = 0; v >= half_patch_size_ * sqrt(2.f) / 2; --v) diff --git a/modules/features2d/src/orb_pattern.i b/modules/features2d/src/orb_pattern.hpp similarity index 100% rename from modules/features2d/src/orb_pattern.i rename to modules/features2d/src/orb_pattern.hpp