1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

Merge branch 4.x

This commit is contained in:
Alexander Alekhin
2021-04-09 10:30:38 +00:00
1114 changed files with 64039 additions and 14611 deletions
+64 -15
View File
@@ -185,6 +185,7 @@ location of points on the plane, building special graphs (such as NNG,RNG), and
@defgroup imgproc_motion Motion Analysis and Object Tracking
@defgroup imgproc_feature Feature Detection
@defgroup imgproc_object Object Detection
@defgroup imgproc_segmentation Image Segmentation
@defgroup imgproc_c C API
@defgroup imgproc_hal Hardware Acceleration Layer
@{
@@ -404,9 +405,13 @@ enum ConnectedComponentsTypes {
//! connected components algorithm
enum ConnectedComponentsAlgorithmsTypes {
CCL_WU = 0, //!< SAUF @cite Wu2009 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity
CCL_DEFAULT = -1, //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity
CCL_GRANA = 1 //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity
CCL_DEFAULT = -1, //!< BBDT @cite Grana2010 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity. The parallel implementation described in @cite Bolelli2017 is available for both BBDT and SAUF.
CCL_WU = 0, //!< SAUF @cite Wu2009 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity. The parallel implementation described in @cite Bolelli2017 is available for SAUF.
CCL_GRANA = 1, //!< BBDT @cite Grana2010 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity. The parallel implementation described in @cite Bolelli2017 is available for both BBDT and SAUF.
CCL_BOLELLI = 2, //!< Spaghetti @cite Bolelli2019 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity.
CCL_SAUF = 3, //!< Same as CCL_WU. It is preferable to use the flag with the name of the algorithm (CCL_SAUF) rather than the one with the name of the first author (CCL_WU).
CCL_BBDT = 4, //!< Same as CCL_GRANA. It is preferable to use the flag with the name of the algorithm (CCL_BBDT) rather than the one with the name of the first author (CCL_GRANA).
CCL_SPAGHETTI = 5, //!< Same as CCL_BOLELLI. It is preferable to use the flag with the name of the algorithm (CCL_SPAGHETTI) rather than the one with the name of the first author (CCL_BOLELLI).
};
//! mode of the contour retrieval algorithm
@@ -578,7 +583,7 @@ enum ColorConversionCodes {
COLOR_YCrCb2BGR = 38,
COLOR_YCrCb2RGB = 39,
COLOR_BGR2HSV = 40, //!< convert RGB/BGR to HSV (hue saturation value), @ref color_convert_rgb_hsv "color conversions"
COLOR_BGR2HSV = 40, //!< convert RGB/BGR to HSV (hue saturation value) with H range 0..180 if 8 bit image, @ref color_convert_rgb_hsv "color conversions"
COLOR_RGB2HSV = 41,
COLOR_BGR2Lab = 44, //!< convert RGB/BGR to CIE Lab, @ref color_convert_rgb_lab "color conversions"
@@ -586,27 +591,27 @@ enum ColorConversionCodes {
COLOR_BGR2Luv = 50, //!< convert RGB/BGR to CIE Luv, @ref color_convert_rgb_luv "color conversions"
COLOR_RGB2Luv = 51,
COLOR_BGR2HLS = 52, //!< convert RGB/BGR to HLS (hue lightness saturation), @ref color_convert_rgb_hls "color conversions"
COLOR_BGR2HLS = 52, //!< convert RGB/BGR to HLS (hue lightness saturation) with H range 0..180 if 8 bit image, @ref color_convert_rgb_hls "color conversions"
COLOR_RGB2HLS = 53,
COLOR_HSV2BGR = 54, //!< backward conversions to RGB/BGR
COLOR_HSV2BGR = 54, //!< backward conversions HSV to RGB/BGR with H range 0..180 if 8 bit image
COLOR_HSV2RGB = 55,
COLOR_Lab2BGR = 56,
COLOR_Lab2RGB = 57,
COLOR_Luv2BGR = 58,
COLOR_Luv2RGB = 59,
COLOR_HLS2BGR = 60,
COLOR_HLS2BGR = 60, //!< backward conversions HLS to RGB/BGR with H range 0..180 if 8 bit image
COLOR_HLS2RGB = 61,
COLOR_BGR2HSV_FULL = 66,
COLOR_BGR2HSV_FULL = 66, //!< convert RGB/BGR to HSV (hue saturation value) with H range 0..255 if 8 bit image, @ref color_convert_rgb_hsv "color conversions"
COLOR_RGB2HSV_FULL = 67,
COLOR_BGR2HLS_FULL = 68,
COLOR_BGR2HLS_FULL = 68, //!< convert RGB/BGR to HLS (hue lightness saturation) with H range 0..255 if 8 bit image, @ref color_convert_rgb_hls "color conversions"
COLOR_RGB2HLS_FULL = 69,
COLOR_HSV2BGR_FULL = 70,
COLOR_HSV2BGR_FULL = 70, //!< backward conversions HSV to RGB/BGR with H range 0..255 if 8 bit image
COLOR_HSV2RGB_FULL = 71,
COLOR_HLS2BGR_FULL = 72,
COLOR_HLS2BGR_FULL = 72, //!< backward conversions HLS to RGB/BGR with H range 0..255 if 8 bit image
COLOR_HLS2RGB_FULL = 73,
COLOR_LBGR2Lab = 74,
@@ -1923,6 +1928,38 @@ CV_EXPORTS_W void goodFeaturesToTrack( InputArray image, OutputArray corners,
InputArray mask, int blockSize,
int gradientSize, bool useHarrisDetector = false,
double k = 0.04 );
/** @brief Same as above, but returns also quality measure of the detected corners.
@param image Input 8-bit or floating-point 32-bit, single-channel image.
@param corners Output vector of detected corners.
@param maxCorners Maximum number of corners to return. If there are more corners than are found,
the strongest of them is returned. `maxCorners <= 0` implies that no limit on the maximum is set
and all detected corners are returned.
@param qualityLevel Parameter characterizing the minimal accepted quality of image corners. The
parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue
(see #cornerMinEigenVal ) or the Harris function response (see #cornerHarris ). The corners with the
quality measure less than the product are rejected. For example, if the best corner has the
quality measure = 1500, and the qualityLevel=0.01 , then all the corners with the quality measure
less than 15 are rejected.
@param minDistance Minimum possible Euclidean distance between the returned corners.
@param mask Region of interest. If the image is not empty (it needs to have the type
CV_8UC1 and the same size as image ), it specifies the region in which the corners are detected.
@param cornersQuality Output vector of quality measure of the detected corners.
@param blockSize Size of an average block for computing a derivative covariation matrix over each
pixel neighborhood. See cornerEigenValsAndVecs .
@param gradientSize Aperture parameter for the Sobel operator used for derivatives computation.
See cornerEigenValsAndVecs .
@param useHarrisDetector Parameter indicating whether to use a Harris detector (see #cornerHarris)
or #cornerMinEigenVal.
@param k Free parameter of the Harris detector.
*/
CV_EXPORTS CV_WRAP_AS(goodFeaturesToTrackWithQuality) void goodFeaturesToTrack(
InputArray image, OutputArray corners,
int maxCorners, double qualityLevel, double minDistance,
InputArray mask, OutputArray cornersQuality, int blockSize = 3,
int gradientSize = 3, bool useHarrisDetector = false, double k = 0.04);
/** @example samples/cpp/tutorial_code/ImgTrans/houghlines.cpp
An example using the Hough line detector
![Sample input image](Hough_Lines_Tutorial_Original_Image.jpg) ![Output image](Hough_Lines_Tutorial_Result.jpg)
@@ -3152,6 +3189,9 @@ CV_EXPORTS_AS(EMD) float wrapperEMD( InputArray signature1, InputArray signature
//! @} imgproc_hist
//! @addtogroup imgproc_segmentation
//! @{
/** @example samples/cpp/watershed.cpp
An example using the watershed algorithm
*/
@@ -3179,11 +3219,11 @@ function.
size as image .
@sa findContours
@ingroup imgproc_misc
*/
CV_EXPORTS_W void watershed( InputArray image, InputOutputArray markers );
//! @} imgproc_segmentation
//! @addtogroup imgproc_filter
//! @{
@@ -3229,7 +3269,7 @@ CV_EXPORTS_W void pyrMeanShiftFiltering( InputArray src, OutputArray dst,
//! @}
//! @addtogroup imgproc_misc
//! @addtogroup imgproc_segmentation
//! @{
/** @example samples/cpp/grabcut.cpp
@@ -3259,6 +3299,11 @@ CV_EXPORTS_W void grabCut( InputArray img, InputOutputArray mask, Rect rect,
InputOutputArray bgdModel, InputOutputArray fgdModel,
int iterCount, int mode = GC_EVAL );
//! @} imgproc_segmentation
//! @addtogroup imgproc_misc
//! @{
/** @example samples/cpp/distrans.cpp
An example on using the distance transform
*/
@@ -3430,7 +3475,7 @@ CV_EXPORTS_W int floodFill( InputOutputArray image, InputOutputArray mask,
//! @param weights1 It has a type of CV_32FC1 and the same size with src1.
//! @param weights2 It has a type of CV_32FC1 and the same size with src1.
//! @param dst It is created if it does not have the same size and type with src1.
CV_EXPORTS void blendLinear(InputArray src1, InputArray src2, InputArray weights1, InputArray weights2, OutputArray dst);
CV_EXPORTS_W void blendLinear(InputArray src1, InputArray src2, InputArray weights1, InputArray weights2, OutputArray dst);
//! @} imgproc_misc
@@ -4908,4 +4953,8 @@ Point LineIterator::pos() const
} // cv
#include "./imgproc/segmentation.hpp"
#endif
@@ -0,0 +1,34 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#ifndef OPENCV_IMGPROC_BINDINGS_HPP
#define OPENCV_IMGPROC_BINDINGS_HPP
// This file contains special overloads for OpenCV bindings
// No need to use these functions in C++ code.
namespace cv {
/** @brief Finds lines in a binary image using the standard Hough transform and get accumulator.
*
* @note This function is for bindings use only. Use original function in C++ code
*
* @sa HoughLines
*/
CV_WRAP static inline
void HoughLinesWithAccumulator(
InputArray image, OutputArray lines,
double rho, double theta, int threshold,
double srn = 0, double stn = 0,
double min_theta = 0, double max_theta = CV_PI
)
{
std::vector<Vec3f> lines_acc;
HoughLines(image, lines_acc, rho, theta, threshold, srn, stn, min_theta, max_theta);
Mat(lines_acc).copyTo(lines);
}
} // namespace
#endif // OPENCV_IMGPROC_BINDINGS_HPP
@@ -0,0 +1,141 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#ifndef OPENCV_IMGPROC_SEGMENTATION_HPP
#define OPENCV_IMGPROC_SEGMENTATION_HPP
#include "opencv2/imgproc.hpp"
namespace cv {
namespace segmentation {
//! @addtogroup imgproc_segmentation
//! @{
/** @brief Intelligent Scissors image segmentation
*
* This class is used to find the path (contour) between two points
* which can be used for image segmentation.
*
* Usage example:
* @snippet snippets/imgproc_segmentation.cpp usage_example_intelligent_scissors
*
* Reference: <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.138.3811&rep=rep1&type=pdf">"Intelligent Scissors for Image Composition"</a>
* algorithm designed by Eric N. Mortensen and William A. Barrett, Brigham Young University
* @cite Mortensen95intelligentscissors
*/
class CV_EXPORTS_W_SIMPLE IntelligentScissorsMB
{
public:
CV_WRAP
IntelligentScissorsMB();
/** @brief Specify weights of feature functions
*
* Consider keeping weights normalized (sum of weights equals to 1.0)
* Discrete dynamic programming (DP) goal is minimization of costs between pixels.
*
* @param weight_non_edge Specify cost of non-edge pixels (default: 0.43f)
* @param weight_gradient_direction Specify cost of gradient direction function (default: 0.43f)
* @param weight_gradient_magnitude Specify cost of gradient magnitude function (default: 0.14f)
*/
CV_WRAP
IntelligentScissorsMB& setWeights(float weight_non_edge, float weight_gradient_direction, float weight_gradient_magnitude);
/** @brief Specify gradient magnitude max value threshold
*
* Zero limit value is used to disable gradient magnitude thresholding (default behavior, as described in original article).
* Otherwize pixels with `gradient magnitude >= threshold` have zero cost.
*
* @note Thresholding should be used for images with irregular regions (to avoid stuck on parameters from high-contract areas, like embedded logos).
*
* @param gradient_magnitude_threshold_max Specify gradient magnitude max value threshold (default: 0, disabled)
*/
CV_WRAP
IntelligentScissorsMB& setGradientMagnitudeMaxLimit(float gradient_magnitude_threshold_max = 0.0f);
/** @brief Switch to "Laplacian Zero-Crossing" edge feature extractor and specify its parameters
*
* This feature extractor is used by default according to article.
*
* Implementation has additional filtering for regions with low-amplitude noise.
* This filtering is enabled through parameter of minimal gradient amplitude (use some small value 4, 8, 16).
*
* @note Current implementation of this feature extractor is based on processing of grayscale images (color image is converted to grayscale image first).
*
* @note Canny edge detector is a bit slower, but provides better results (especially on color images): use setEdgeFeatureCannyParameters().
*
* @param gradient_magnitude_min_value Minimal gradient magnitude value for edge pixels (default: 0, check is disabled)
*/
CV_WRAP
IntelligentScissorsMB& setEdgeFeatureZeroCrossingParameters(float gradient_magnitude_min_value = 0.0f);
/** @brief Switch edge feature extractor to use Canny edge detector
*
* @note "Laplacian Zero-Crossing" feature extractor is used by default (following to original article)
*
* @sa Canny
*/
CV_WRAP
IntelligentScissorsMB& setEdgeFeatureCannyParameters(
double threshold1, double threshold2,
int apertureSize = 3, bool L2gradient = false
);
/** @brief Specify input image and extract image features
*
* @param image input image. Type is #CV_8UC1 / #CV_8UC3
*/
CV_WRAP
IntelligentScissorsMB& applyImage(InputArray image);
/** @brief Specify custom features of imput image
*
* Customized advanced variant of applyImage() call.
*
* @param non_edge Specify cost of non-edge pixels. Type is CV_8UC1. Expected values are `{0, 1}`.
* @param gradient_direction Specify gradient direction feature. Type is CV_32FC2. Values are expected to be normalized: `x^2 + y^2 == 1`
* @param gradient_magnitude Specify cost of gradient magnitude function: Type is CV_32FC1. Values should be in range `[0, 1]`.
* @param image **Optional parameter**. Must be specified if subset of features is specified (non-specified features are calculated internally)
*/
CV_WRAP
IntelligentScissorsMB& applyImageFeatures(
InputArray non_edge, InputArray gradient_direction, InputArray gradient_magnitude,
InputArray image = noArray()
);
/** @brief Prepares a map of optimal paths for the given source point on the image
*
* @note applyImage() / applyImageFeatures() must be called before this call
*
* @param sourcePt The source point used to find the paths
*/
CV_WRAP void buildMap(const Point& sourcePt);
/** @brief Extracts optimal contour for the given target point on the image
*
* @note buildMap() must be called before this call
*
* @param targetPt The target point
* @param[out] contour The list of pixels which contains optimal path between the source and the target points of the image. Type is CV_32SC2 (compatible with `std::vector<Point>`)
* @param backward Flag to indicate reverse order of retrived pixels (use "true" value to fetch points from the target to the source point)
*/
CV_WRAP void getContour(const Point& targetPt, OutputArray contour, bool backward = false) const;
#ifndef CV_DOXYGEN
struct Impl;
inline Impl* getImpl() const { return impl.get(); }
protected:
std::shared_ptr<Impl> impl;
#endif
};
//! @}
} // namespace segmentation
} // namespace cv
#endif // OPENCV_IMGPROC_SEGMENTATION_HPP