From ec8b7c933a71f168b584c549547ecdcbf46b06c3 Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Sat, 3 Apr 2021 15:11:38 +0300 Subject: [PATCH 1/8] Update Documentation --- modules/core/include/opencv2/core/types.hpp | 26 ++++----- .../features2d/include/opencv2/features2d.hpp | 45 +++++---------- modules/imgproc/include/opencv2/imgproc.hpp | 57 +++++++++---------- 3 files changed, 55 insertions(+), 73 deletions(-) diff --git a/modules/core/include/opencv2/core/types.hpp b/modules/core/include/opencv2/core/types.hpp index 4d04bef90a..0b1d948156 100644 --- a/modules/core/include/opencv2/core/types.hpp +++ b/modules/core/include/opencv2/core/types.hpp @@ -702,24 +702,24 @@ public: //! the default constructor CV_WRAP KeyPoint(); /** - @param _pt x & y coordinates of the keypoint - @param _size keypoint diameter - @param _angle keypoint orientation - @param _response keypoint detector response on the keypoint (that is, strength of the keypoint) - @param _octave pyramid octave in which the keypoint has been detected - @param _class_id object id + @param pt x & y coordinates of the keypoint + @param size keypoint diameter + @param angle keypoint orientation + @param response keypoint detector response on the keypoint (that is, strength of the keypoint) + @param octave pyramid octave in which the keypoint has been detected + @param class_id object id */ - KeyPoint(Point2f _pt, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1); + KeyPoint(Point2f pt, float size, float angle=-1, float response=0, int octave=0, int class_id=-1); /** @param x x-coordinate of the keypoint @param y y-coordinate of the keypoint - @param _size keypoint diameter - @param _angle keypoint orientation - @param _response keypoint detector response on the keypoint (that is, strength of the keypoint) - @param _octave pyramid octave in which the keypoint has been detected - @param _class_id object id + @param size keypoint diameter + @param angle keypoint orientation + @param response keypoint detector response on the keypoint (that is, strength of the keypoint) + @param octave pyramid octave in which the keypoint has been detected + @param class_id object id */ - CV_WRAP KeyPoint(float x, float y, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1); + CV_WRAP KeyPoint(float x, float y, float size, float angle=-1, float response=0, int octave=0, int class_id=-1); size_t hash() const; diff --git a/modules/features2d/include/opencv2/features2d.hpp b/modules/features2d/include/opencv2/features2d.hpp index 18ec360a1d..86b5e935c8 100644 --- a/modules/features2d/include/opencv2/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d.hpp @@ -61,25 +61,11 @@ easily switch between different algorithms solving the same problem. This sectio matching descriptors that are represented as vectors in a multidimensional space. All objects that implement vector descriptor matchers inherit the DescriptorMatcher interface. -@note - - An example explaining keypoint matching can be found at - opencv_source_code/samples/cpp/descriptor_extractor_matcher.cpp - - An example on descriptor matching evaluation can be found at - opencv_source_code/samples/cpp/detector_descriptor_matcher_evaluation.cpp - - An example on one to many image matching can be found at - opencv_source_code/samples/cpp/matching_to_many_images.cpp - @defgroup features2d_draw Drawing Function of Keypoints and Matches @defgroup features2d_category Object Categorization This section describes approaches based on local 2D features and used to categorize objects. -@note - - A complete Bag-Of-Words sample can be found at - opencv_source_code/samples/cpp/bagofwords_classification.cpp - - (Python) An example using the features2D framework to perform object categorization can be - found at opencv_source_code/samples/python/find_obj.py - @defgroup feature2d_hal Hardware Acceleration Layer @{ @defgroup features2d_hal_interface Interface @@ -90,7 +76,7 @@ This section describes approaches based on local 2D features and used to categor namespace cv { -//! @addtogroup features2d +//! @addtogroup features2d_main //! @{ // //! writes vector of keypoints to the file storage @@ -241,9 +227,6 @@ the vector descriptor extractors inherit the DescriptorExtractor interface. */ typedef Feature2D DescriptorExtractor; -//! @addtogroup features2d_main -//! @{ - /** @brief Class for implementing the wrapper which makes detectors and extractors to be affine invariant, described as ASIFT in @cite YM11 . @@ -477,20 +460,20 @@ class CV_EXPORTS_W MSER : public Feature2D public: /** @brief Full constructor for %MSER detector - @param _delta it compares \f$(size_{i}-size_{i-delta})/size_{i-delta}\f$ - @param _min_area prune the area which smaller than minArea - @param _max_area prune the area which bigger than maxArea - @param _max_variation prune the area have similar size to its children - @param _min_diversity for color image, trace back to cut off mser with diversity less than min_diversity - @param _max_evolution for color image, the evolution steps - @param _area_threshold for color image, the area threshold to cause re-initialize - @param _min_margin for color image, ignore too small margin - @param _edge_blur_size for color image, the aperture size for edge blur + @param delta it compares \f$(size_{i}-size_{i-delta})/size_{i-delta}\f$ + @param min_area prune the area which smaller than minArea + @param max_area prune the area which bigger than maxArea + @param max_variation prune the area have similar size to its children + @param min_diversity for color image, trace back to cut off mser with diversity less than min_diversity + @param max_evolution for color image, the evolution steps + @param area_threshold for color image, the area threshold to cause re-initialize + @param min_margin for color image, ignore too small margin + @param edge_blur_size for color image, the aperture size for edge blur */ - CV_WRAP static Ptr create( int _delta=5, int _min_area=60, int _max_area=14400, - double _max_variation=0.25, double _min_diversity=.2, - int _max_evolution=200, double _area_threshold=1.01, - double _min_margin=0.003, int _edge_blur_size=5 ); + CV_WRAP static Ptr create( int delta=5, int min_area=60, int max_area=14400, + double max_variation=0.25, double min_diversity=.2, + int max_evolution=200, double area_threshold=1.01, + double min_margin=0.003, int edge_blur_size=5 ); /** @brief Detect %MSER regions diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index 2ded15d1a9..aba7821e3e 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -1181,7 +1181,7 @@ protected: struct CV_EXPORTS Vertex { Vertex(); - Vertex(Point2f pt, bool _isvirtual, int _firstEdge=0); + Vertex(Point2f pt, bool isvirtual, int firstEdge=0); bool isvirtual() const; bool isfree() const; @@ -1237,9 +1237,9 @@ public: ![image](pics/building_lsd.png) - @param _image A grayscale (CV_8UC1) input image. If only a roi needs to be selected, use: + @param image A grayscale (CV_8UC1) input image. If only a roi needs to be selected, use: `lsd_ptr-\>detect(image(roi), lines, ...); lines += Scalar(roi.x, roi.y, roi.x, roi.y);` - @param _lines A vector of Vec4i or Vec4f elements specifying the beginning and ending point of a line. Where + @param lines A vector of Vec4i or Vec4f elements specifying the beginning and ending point of a line. Where Vec4i/Vec4f is (x1, y1, x2, y2), point 1 is the start, point 2 - end. Returned lines are strictly oriented depending on the gradient. @param width Vector of widths of the regions, where the lines are found. E.g. Width of line. @@ -1251,26 +1251,26 @@ public: - 1 corresponds to 0.1 mean false alarms This vector will be calculated only when the objects type is #LSD_REFINE_ADV. */ - CV_WRAP virtual void detect(InputArray _image, OutputArray _lines, + CV_WRAP virtual void detect(InputArray image, OutputArray lines, OutputArray width = noArray(), OutputArray prec = noArray(), OutputArray nfa = noArray()) = 0; /** @brief Draws the line segments on a given image. - @param _image The image, where the lines will be drawn. Should be bigger or equal to the image, + @param image The image, where the lines will be drawn. Should be bigger or equal to the image, where the lines were found. @param lines A vector of the lines that needed to be drawn. */ - CV_WRAP virtual void drawSegments(InputOutputArray _image, InputArray lines) = 0; + CV_WRAP virtual void drawSegments(InputOutputArray image, InputArray lines) = 0; /** @brief Draws two groups of lines in blue and red, counting the non overlapping (mismatching) pixels. @param size The size of the image, where lines1 and lines2 were found. @param lines1 The first group of lines that needs to be drawn. It is visualized in blue color. @param lines2 The second group of lines. They visualized in red color. - @param _image Optional image, where the lines will be drawn. The image should be color(3-channel) + @param image Optional image, where the lines will be drawn. The image should be color(3-channel) in order for lines1 and lines2 to be drawn in the above mentioned colors. */ - CV_WRAP virtual int compareSegments(const Size& size, InputArray lines1, InputArray lines2, InputOutputArray _image = noArray()) = 0; + CV_WRAP virtual int compareSegments(const Size& size, InputArray lines1, InputArray lines2, InputOutputArray image = noArray()) = 0; virtual ~LineSegmentDetector() { } }; @@ -1280,22 +1280,21 @@ public: The LineSegmentDetector algorithm is defined using the standard values. Only advanced users may want to edit those, as to tailor it for their own application. -@param _refine The way found lines will be refined, see #LineSegmentDetectorModes -@param _scale The scale of the image that will be used to find the lines. Range (0..1]. -@param _sigma_scale Sigma for Gaussian filter. It is computed as sigma = _sigma_scale/_scale. -@param _quant Bound to the quantization error on the gradient norm. -@param _ang_th Gradient angle tolerance in degrees. -@param _log_eps Detection threshold: -log10(NFA) \> log_eps. Used only when advance refinement -is chosen. -@param _density_th Minimal density of aligned region points in the enclosing rectangle. -@param _n_bins Number of bins in pseudo-ordering of gradient modulus. +@param refine The way found lines will be refined, see #LineSegmentDetectorModes +@param scale The scale of the image that will be used to find the lines. Range (0..1]. +@param sigma_scale Sigma for Gaussian filter. It is computed as sigma = sigma_scale/scale. +@param quant Bound to the quantization error on the gradient norm. +@param ang_th Gradient angle tolerance in degrees. +@param log_eps Detection threshold: -log10(NFA) \> log_eps. Used only when advance refinement is chosen. +@param density_th Minimal density of aligned region points in the enclosing rectangle. +@param n_bins Number of bins in pseudo-ordering of gradient modulus. @note Implementation has been removed due original code license conflict */ CV_EXPORTS_W Ptr createLineSegmentDetector( - int _refine = LSD_REFINE_STD, double _scale = 0.8, - double _sigma_scale = 0.6, double _quant = 2.0, double _ang_th = 22.5, - double _log_eps = 0, double _density_th = 0.7, int _n_bins = 1024); + int refine = LSD_REFINE_STD, double scale = 0.8, + double sigma_scale = 0.6, double quant = 2.0, double ang_th = 22.5, + double log_eps = 0, double density_th = 0.7, int n_bins = 1024); //! @} imgproc_feature @@ -1494,7 +1493,7 @@ The unnormalized square box filter can be useful in computing local image statis variance and standard deviation around the neighborhood of a pixel. @param src input image -@param dst output image of the same size and type as _src +@param dst output image of the same size and type as src @param ddepth the output image depth (-1 to use src.depth()) @param ksize kernel size @param anchor kernel anchor point. The default value of Point(-1, -1) denotes that the anchor is at the kernel @@ -2036,8 +2035,8 @@ CV_EXPORTS_W void HoughLinesP( InputArray image, OutputArray lines, The function finds lines in a set of points using a modification of the Hough transform. @include snippets/imgproc_HoughLinesPointSet.cpp -@param _point Input vector of points. Each vector must be encoded as a Point vector \f$(x,y)\f$. Type must be CV_32FC2 or CV_32SC2. -@param _lines Output vector of found lines. Each vector is encoded as a vector \f$(votes, rho, theta)\f$. +@param point Input vector of points. Each vector must be encoded as a Point vector \f$(x,y)\f$. Type must be CV_32FC2 or CV_32SC2. +@param lines Output vector of found lines. Each vector is encoded as a vector \f$(votes, rho, theta)\f$. The larger the value of 'votes', the higher the reliability of the Hough line. @param lines_max Max count of hough lines. @param threshold Accumulator threshold parameter. Only those lines are returned that get enough @@ -2049,7 +2048,7 @@ votes ( \f$>\texttt{threshold}\f$ ) @param max_theta Maximum angle value of the accumulator in radians. @param theta_step Angle resolution of the accumulator in radians. */ -CV_EXPORTS_W void HoughLinesPointSet( InputArray _point, OutputArray _lines, int lines_max, int threshold, +CV_EXPORTS_W void HoughLinesPointSet( InputArray point, OutputArray lines, int lines_max, int threshold, double min_rho, double max_rho, double rho_step, double min_theta, double max_theta, double theta_step ); @@ -4163,9 +4162,9 @@ Examples of how intersectConvexConvex works /** @brief Finds intersection of two convex polygons -@param _p1 First polygon -@param _p2 Second polygon -@param _p12 Output polygon describing the intersecting area +@param p1 First polygon +@param p2 Second polygon +@param p12 Output polygon describing the intersecting area @param handleNested When true, an intersection is found if one of the polygons is fully enclosed in the other. When false, no intersection is found. If the polygons share a side or the vertex of one polygon lies on an edge of the other, they are not considered nested and an intersection will be found regardless of the value of handleNested. @@ -4174,8 +4173,8 @@ of the other, they are not considered nested and an intersection will be found r @note intersectConvexConvex doesn't confirm that both polygons are convex and will return invalid results if they aren't. */ -CV_EXPORTS_W float intersectConvexConvex( InputArray _p1, InputArray _p2, - OutputArray _p12, bool handleNested = true ); +CV_EXPORTS_W float intersectConvexConvex( InputArray p1, InputArray p2, + OutputArray p12, bool handleNested = true ); /** @example samples/cpp/fitellipse.cpp An example using the fitEllipse technique From 222af8e7e48d35d0d4dd02f4b2b0291e4e091d1c Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 9 Apr 2021 15:46:11 +0000 Subject: [PATCH 2/8] core: avoid process cleanup deadlock if TlsStorage is not used --- modules/core/src/precomp.hpp | 2 ++ modules/core/src/system.cpp | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/core/src/precomp.hpp b/modules/core/src/precomp.hpp index 0ffde8855a..eebbda0694 100644 --- a/modules/core/src/precomp.hpp +++ b/modules/core/src/precomp.hpp @@ -388,6 +388,8 @@ cv::Mutex& getInitializationMutex(); #define CV_SINGLETON_LAZY_INIT(TYPE, INITIALIZER) CV_SINGLETON_LAZY_INIT_(TYPE, INITIALIZER, instance) #define CV_SINGLETON_LAZY_INIT_REF(TYPE, INITIALIZER) CV_SINGLETON_LAZY_INIT_(TYPE, INITIALIZER, *instance) +CV_EXPORTS void releaseTlsStorageThread(); + int cv_snprintf(char* buf, int len, const char* fmt, ...); int cv_vsnprintf(char* buf, int len, const char* fmt, va_list args); } diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index 6e882e1dde..51c7363b30 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -1583,6 +1583,9 @@ struct ThreadData size_t idx; // Thread index in TLS storage. This is not OS thread ID! }; + +static bool g_isTlsStorageInitialized = false; + // Main TLS storage class class TlsStorage { @@ -1592,6 +1595,7 @@ public: { tlsSlots.reserve(32); threads.reserve(32); + g_isTlsStorageInitialized = true; } ~TlsStorage() { @@ -1810,6 +1814,13 @@ static void WINAPI opencv_fls_destructor(void* pData) } // namespace details using namespace details; +void releaseTlsStorageThread() +{ + if (!g_isTlsStorageInitialized) + return; // nothing to release, so prefer to avoid creation of new global structures + getTlsStorage().releaseThread(); +} + TLSDataContainer::TLSDataContainer() { key_ = (int)getTlsStorage().reserveSlot(this); // Reserve key from TLS storage @@ -1893,7 +1904,7 @@ BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID lpReserved) { // Not allowed to free resources if lpReserved is non-null // http://msdn.microsoft.com/en-us/library/windows/desktop/ms682583.aspx - cv::getTlsStorage().releaseThread(); + releaseTlsStorageThread(); } } return TRUE; From a9a6801c6dcbe2baa989453e2c95c80388888879 Mon Sep 17 00:00:00 2001 From: Danny <33044223+danielenricocahall@users.noreply.github.com> Date: Fri, 9 Apr 2021 12:56:14 -0400 Subject: [PATCH 3/8] Merge pull request #19884 from danielenricocahall:fix-prediction-features-bug Fix bug with predictions in RTrees/Boost * address bug where predict functions with invalid feature count in rtrees/boost models * compact matrix rep in tests * check 1..n-1 and n+1 in feature size validation test --- modules/ml/src/boost.cpp | 1 + modules/ml/src/rtrees.cpp | 1 + modules/ml/test/test_rtrees.cpp | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/modules/ml/src/boost.cpp b/modules/ml/src/boost.cpp index 4b94410eeb..58f572b90d 100644 --- a/modules/ml/src/boost.cpp +++ b/modules/ml/src/boost.cpp @@ -490,6 +490,7 @@ public: float predict( InputArray samples, OutputArray results, int flags ) const CV_OVERRIDE { + CV_Assert( samples.cols() == getVarCount() && samples.type() == CV_32F ); return impl.predict(samples, results, flags); } diff --git a/modules/ml/src/rtrees.cpp b/modules/ml/src/rtrees.cpp index 1deee6f6c8..46af37ce11 100644 --- a/modules/ml/src/rtrees.cpp +++ b/modules/ml/src/rtrees.cpp @@ -479,6 +479,7 @@ public: float predict( InputArray samples, OutputArray results, int flags ) const CV_OVERRIDE { CV_TRACE_FUNCTION(); + CV_Assert( samples.cols() == getVarCount() && samples.type() == CV_32F ); return impl.predict(samples, results, flags); } diff --git a/modules/ml/test/test_rtrees.cpp b/modules/ml/test/test_rtrees.cpp index 1ec9b8d042..5a4fb34e74 100644 --- a/modules/ml/test/test_rtrees.cpp +++ b/modules/ml/test/test_rtrees.cpp @@ -95,6 +95,25 @@ TEST(ML_RTrees, 11142_sample_weights_classification) EXPECT_GE(error_with_weights, error_without_weights); } +TEST(ML_RTrees, bug_12974_throw_exception_when_predict_different_feature_count) +{ + int numFeatures = 5; + // create a 5 feature dataset and train the model + cv::Ptr model = RTrees::create(); + Mat samples(10, numFeatures, CV_32F); + randu(samples, 0, 10); + Mat labels = (Mat_(10,1) << 0,0,0,0,0,1,1,1,1,1); + cv::Ptr trainData = TrainData::create(samples, cv::ml::ROW_SAMPLE, labels); + model->train(trainData); + // try to predict on data which have fewer features - this should throw an exception + for(int i = 1; i < numFeatures - 1; ++i) { + Mat test(1, i, CV_32FC1); + ASSERT_THROW(model->predict(test), Exception); + } + // try to predict on data which have more features - this should also throw an exception + Mat test(1, numFeatures + 1, CV_32FC1); + ASSERT_THROW(model->predict(test), Exception); +} }} // namespace From b9b19185bcf603e27853260dc1d9c763203e4b2c Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 12 Apr 2021 19:05:52 +0000 Subject: [PATCH 4/8] ml: fix legacy import in DTreesImpl --- modules/ml/src/boost.cpp | 2 +- modules/ml/src/tree.cpp | 43 +++++++++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/modules/ml/src/boost.cpp b/modules/ml/src/boost.cpp index 58f572b90d..be9c9a7b46 100644 --- a/modules/ml/src/boost.cpp +++ b/modules/ml/src/boost.cpp @@ -490,7 +490,7 @@ public: float predict( InputArray samples, OutputArray results, int flags ) const CV_OVERRIDE { - CV_Assert( samples.cols() == getVarCount() && samples.type() == CV_32F ); + CV_CheckEQ(samples.cols(), getVarCount(), ""); return impl.predict(samples, results, flags); } diff --git a/modules/ml/src/tree.cpp b/modules/ml/src/tree.cpp index 87181b156c..1f82ff5081 100644 --- a/modules/ml/src/tree.cpp +++ b/modules/ml/src/tree.cpp @@ -43,6 +43,8 @@ #include "precomp.hpp" #include +#include + namespace cv { namespace ml { @@ -1694,9 +1696,9 @@ void DTreesImpl::write( FileStorage& fs ) const void DTreesImpl::readParams( const FileNode& fn ) { _isClassifier = (int)fn["is_classifier"] != 0; - /*int var_all = (int)fn["var_all"]; - int var_count = (int)fn["var_count"]; - int cat_var_count = (int)fn["cat_var_count"]; + int varAll = (int)fn["var_all"]; + int varCount = (int)fn["var_count"]; + /*int cat_var_count = (int)fn["cat_var_count"]; int ord_var_count = (int)fn["ord_var_count"];*/ FileNode tparams_node = fn["training_params"]; @@ -1723,11 +1725,38 @@ void DTreesImpl::readParams( const FileNode& fn ) readVectorOrMat(fn["var_idx"], varIdx); fn["var_type"] >> varType; - int format = 0; - fn["format"] >> format; - bool isLegacy = format < 3; + bool isLegacy = false; + if (fn["format"].empty()) // Export bug until OpenCV 3.2: https://github.com/opencv/opencv/pull/6314 + { + if (!fn["cat_ofs"].empty()) + isLegacy = false; // 2.4 doesn't store "cat_ofs" + else if (!fn["missing_subst"].empty()) + isLegacy = false; // 2.4 doesn't store "missing_subst" + else if (!fn["class_labels"].empty()) + isLegacy = false; // 2.4 doesn't store "class_labels" + else if ((int)varType.size() != varAll) + isLegacy = true; // 3.0+: https://github.com/opencv/opencv/blame/3.0.0/modules/ml/src/tree.cpp#L1576 + else if (/*(int)varType.size() == varAll &&*/ varCount == varAll) + isLegacy = true; + else + { + // 3.0+: + // - https://github.com/opencv/opencv/blame/3.0.0/modules/ml/src/tree.cpp#L1552-L1553 + // - https://github.com/opencv/opencv/blame/3.0.0/modules/ml/src/precomp.hpp#L296 + isLegacy = !(varCount + 1 == varAll); + } + CV_LOG_INFO(NULL, "ML/DTrees: possible missing 'format' field due to bug of OpenCV export implementation. " + "Details: https://github.com/opencv/opencv/issues/5412. Consider re-exporting of saved ML model. " + "isLegacy = " << isLegacy); + } + else + { + int format = 0; + fn["format"] >> format; + CV_CheckGT(format, 0, ""); + isLegacy = format < 3; + } - int varAll = (int)fn["var_all"]; if (isLegacy && (int)varType.size() <= varAll) { std::vector extendedTypes(varAll + 1, 0); From 0bdbc745c444e488021c356ff6197bc6d538e517 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 13 Apr 2021 11:09:14 +0000 Subject: [PATCH 5/8] ml: update checks --- modules/ml/src/rtrees.cpp | 2 +- modules/ml/src/tree.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/ml/src/rtrees.cpp b/modules/ml/src/rtrees.cpp index 46af37ce11..56be5c0e22 100644 --- a/modules/ml/src/rtrees.cpp +++ b/modules/ml/src/rtrees.cpp @@ -479,7 +479,7 @@ public: float predict( InputArray samples, OutputArray results, int flags ) const CV_OVERRIDE { CV_TRACE_FUNCTION(); - CV_Assert( samples.cols() == getVarCount() && samples.type() == CV_32F ); + CV_CheckEQ(samples.cols(), getVarCount(), ""); return impl.predict(samples, results, flags); } diff --git a/modules/ml/src/tree.cpp b/modules/ml/src/tree.cpp index 1f82ff5081..5dae889013 100644 --- a/modules/ml/src/tree.cpp +++ b/modules/ml/src/tree.cpp @@ -1701,6 +1701,9 @@ void DTreesImpl::readParams( const FileNode& fn ) /*int cat_var_count = (int)fn["cat_var_count"]; int ord_var_count = (int)fn["ord_var_count"];*/ + if (varAll <= 0) + CV_Error(Error::StsParseError, "The field \"var_all\" of DTree classifier is missing or non-positive"); + FileNode tparams_node = fn["training_params"]; TreeParams params0 = TreeParams(); From 2a48730166bdd3e0f39e61895e1bfc3aad67d0ac Mon Sep 17 00:00:00 2001 From: berak Date: Tue, 13 Apr 2021 12:51:34 +0200 Subject: [PATCH 6/8] docs:fix python retvals --- doc/tools/html_functions.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/doc/tools/html_functions.py b/doc/tools/html_functions.py index b76639cea5..204f6d1c1b 100644 --- a/doc/tools/html_functions.py +++ b/doc/tools/html_functions.py @@ -107,17 +107,10 @@ def add_signature_to_table(soup, table, signature, language, type): """ Add a signature to an html table""" row = soup.new_tag('tr') row.append(soup.new_tag('td', style='width: 20px;')) - - if 'ret' in signature: - row.append(append(soup.new_tag('td'), signature['ret'])) - row.append(append(soup.new_tag('td'), '=')) - else: - row.append(soup.new_tag('td')) # return values - row.append(soup.new_tag('td')) # '=' - row.append(append(soup.new_tag('td'), signature['name'] + '(')) row.append(append(soup.new_tag('td', **{'class': 'paramname'}), signature['arg'])) - row.append(append(soup.new_tag('td'), ')')) + row.append(append(soup.new_tag('td'), ') -> ')) + row.append(append(soup.new_tag('td'), signature['ret'])) table.append(row) From ec32061f5fc63880727b2d252294412b2e024c54 Mon Sep 17 00:00:00 2001 From: CSBVision Date: Wed, 14 Apr 2021 12:05:53 +0200 Subject: [PATCH 7/8] Update __init__.py to support symbolic links Currently, the LOADER_DIR is set as os.path.dirname(os.path.abspath(__file__)). This does not point to the true library path if the cv2 folder is symlinked into the Python package directory such that importing cv2 under Python fails. The proposed change only resolves symbolic links correctly by calling os.path.realpath(__file__) first and does not change anything if __file__ contains no symbolic link. --- modules/python/package/cv2/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/python/package/cv2/__init__.py b/modules/python/package/cv2/__init__.py index 940ac65732..de70872839 100644 --- a/modules/python/package/cv2/__init__.py +++ b/modules/python/package/cv2/__init__.py @@ -34,7 +34,7 @@ def bootstrap(): import platform if DEBUG: print('OpenCV loader: os.name="{}" platform.system()="{}"'.format(os.name, str(platform.system()))) - LOADER_DIR=os.path.dirname(os.path.abspath(__file__)) + LOADER_DIR = os.path.dirname(os.path.abspath(os.path.realpath(__file__))) PYTHON_EXTENSIONS_PATHS = [] BINARIES_PATHS = [] From aeb8dfc52df99d866f4a7c50a34d926fe7140613 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Thu, 15 Apr 2021 12:13:15 +0300 Subject: [PATCH 8/8] Fix header sorting for modules without headers --- cmake/OpenCVModule.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/OpenCVModule.cmake b/cmake/OpenCVModule.cmake index bcbca833f2..5501b99113 100644 --- a/cmake/OpenCVModule.cmake +++ b/cmake/OpenCVModule.cmake @@ -877,7 +877,9 @@ macro(_ocv_create_module) ocv_compiler_optimization_process_sources(OPENCV_MODULE_${the_module}_SOURCES OPENCV_MODULE_${the_module}_DEPS_EXT ${the_module}) set(__module_headers ${OPENCV_MODULE_${the_module}_HEADERS}) - list(SORT __module_headers) # fix headers order, useful for bindings + if(__module_headers) + list(SORT __module_headers) # fix headers order, useful for bindings + endif() set(OPENCV_MODULE_${the_module}_HEADERS ${__module_headers} CACHE INTERNAL "List of header files for ${the_module}") set(OPENCV_MODULE_${the_module}_SOURCES ${OPENCV_MODULE_${the_module}_SOURCES} CACHE INTERNAL "List of source files for ${the_module}")