mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
Merge branch 4.x
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
set(the_description "Object Detection")
|
||||
ocv_define_module(objdetect opencv_core opencv_imgproc opencv_3d opencv_dnn WRAP java objc python js)
|
||||
ocv_define_module(objdetect
|
||||
opencv_core
|
||||
opencv_imgproc
|
||||
opencv_3d
|
||||
OPTIONAL
|
||||
opencv_dnn
|
||||
WRAP
|
||||
python
|
||||
java
|
||||
objc
|
||||
js
|
||||
)
|
||||
|
||||
if(HAVE_QUIRC)
|
||||
get_property(QUIRC_INCLUDE GLOBAL PROPERTY QUIRC_INCLUDE_DIR)
|
||||
|
||||
@@ -49,8 +49,8 @@
|
||||
/**
|
||||
@defgroup objdetect Object Detection
|
||||
|
||||
Haar Feature-based Cascade Classifier for Object Detection
|
||||
----------------------------------------------------------
|
||||
@{
|
||||
@defgroup objdetect_cascade_classifier Cascade Classifier for Object Detection
|
||||
|
||||
The object detector described below has been initially proposed by Paul Viola @cite Viola01 and
|
||||
improved by Rainer Lienhart @cite Lienhart02 .
|
||||
@@ -90,8 +90,7 @@ middle) and the sum of the image pixels under the black stripe multiplied by 3 i
|
||||
compensate for the differences in the size of areas. The sums of pixel values over a rectangular
|
||||
regions are calculated rapidly using integral images (see below and the integral description).
|
||||
|
||||
To see the object detector at work, have a look at the facedetect demo:
|
||||
<https://github.com/opencv/opencv/tree/5.x/samples/cpp/dbt_face_detection.cpp>
|
||||
Check @ref tutorial_cascade_classifier "the corresponding tutorial" for more details.
|
||||
|
||||
The following reference is for the detection part only. There is a separate application called
|
||||
opencv_traincascade that can train a cascade of boosted classifiers from a set of samples.
|
||||
@@ -99,10 +98,13 @@ opencv_traincascade that can train a cascade of boosted classifiers from a set o
|
||||
@note In the new C++ interface it is also possible to use LBP (local binary pattern) features in
|
||||
addition to Haar-like features. .. [Viola01] Paul Viola and Michael J. Jones. Rapid Object Detection
|
||||
using a Boosted Cascade of Simple Features. IEEE CVPR, 2001. The paper is available online at
|
||||
<http://research.microsoft.com/en-us/um/people/viola/Pubs/Detect/violaJones_CVPR2001.pdf>
|
||||
<https://github.com/SvHey/thesis/blob/master/Literature/ObjectDetection/violaJones_CVPR2001.pdf>
|
||||
|
||||
@{
|
||||
@defgroup objdetect_c C API
|
||||
@defgroup objdetect_hog HOG (Histogram of Oriented Gradients) descriptor and object detector
|
||||
@defgroup objdetect_qrcode QRCode detection and encoding
|
||||
@defgroup objdetect_dnn_face DNN-based face detection and recognition
|
||||
Check @ref tutorial_dnn_face "the corresponding tutorial" for more details.
|
||||
@defgroup objdetect_common Common functions and classes
|
||||
@}
|
||||
*/
|
||||
|
||||
@@ -111,13 +113,15 @@ typedef struct CvHaarClassifierCascade CvHaarClassifierCascade;
|
||||
namespace cv
|
||||
{
|
||||
|
||||
//! @addtogroup objdetect
|
||||
//! @addtogroup objdetect_common
|
||||
//! @{
|
||||
|
||||
///////////////////////////// Object Detection ////////////////////////////
|
||||
|
||||
//! class for grouping object candidates, detected by Cascade Classifier, HOG etc.
|
||||
//! instance of the class is to be passed to cv::partition (see cxoperations.hpp)
|
||||
/** @brief This class is used for grouping object candidates detected by Cascade Classifier, HOG etc.
|
||||
|
||||
instance of the class is to be passed to cv::partition
|
||||
*/
|
||||
class CV_EXPORTS SimilarRects
|
||||
{
|
||||
public:
|
||||
@@ -162,6 +166,10 @@ CV_EXPORTS void groupRectangles(std::vector<Rect>& rectList, std::vector<int>&
|
||||
CV_EXPORTS void groupRectangles_meanshift(std::vector<Rect>& rectList, std::vector<double>& foundWeights,
|
||||
std::vector<double>& foundScales,
|
||||
double detectThreshold = 0.0, Size winDetSize = Size(64, 128));
|
||||
//! @}
|
||||
|
||||
//! @addtogroup objdetect_cascade_classifier
|
||||
//! @{
|
||||
|
||||
template<> struct DefaultDeleter<CvHaarClassifierCascade>{ CV_EXPORTS void operator ()(CvHaarClassifierCascade* obj) const; };
|
||||
|
||||
@@ -243,7 +251,7 @@ public:
|
||||
CV_WRAP bool load( const String& filename );
|
||||
/** @brief Reads a classifier from a FileStorage node.
|
||||
|
||||
@note The file may contain a new cascade classifier (trained traincascade application) only.
|
||||
@note The file may contain a new cascade classifier (trained by the traincascade application) only.
|
||||
*/
|
||||
CV_WRAP bool read( const FileNode& node );
|
||||
|
||||
@@ -260,12 +268,6 @@ public:
|
||||
cvHaarDetectObjects. It is not used for a new cascade.
|
||||
@param minSize Minimum possible object size. Objects smaller than that are ignored.
|
||||
@param maxSize Maximum possible object size. Objects larger than that are ignored. If `maxSize == minSize` model is evaluated on single scale.
|
||||
|
||||
The function is parallelized with the TBB library.
|
||||
|
||||
@note
|
||||
- (Python) A face detection example using cascade classifiers can be found at
|
||||
opencv_source_code/samples/python/facedetect.py
|
||||
*/
|
||||
CV_WRAP void detectMultiScale( InputArray image,
|
||||
CV_OUT std::vector<Rect>& objects,
|
||||
@@ -338,7 +340,10 @@ public:
|
||||
};
|
||||
|
||||
CV_EXPORTS Ptr<BaseCascadeClassifier::MaskGenerator> createFaceDetectionMaskGenerator();
|
||||
//! @}
|
||||
|
||||
//! @addtogroup objdetect_hog
|
||||
//! @{
|
||||
//////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector //////////////
|
||||
|
||||
//! struct for detection region of interest (ROI)
|
||||
@@ -378,7 +383,7 @@ public:
|
||||
};
|
||||
enum DescriptorStorageFormat { DESCR_FORMAT_COL_BY_COL, DESCR_FORMAT_ROW_BY_ROW };
|
||||
|
||||
/**@brief Creates the HOG descriptor and detector with default params.
|
||||
/**@brief Creates the HOG descriptor and detector with default parameters.
|
||||
|
||||
aqual to HOGDescriptor(Size(64,128), Size(16,16), Size(8,8), Size(8,8), 9 )
|
||||
*/
|
||||
@@ -414,6 +419,8 @@ public:
|
||||
{}
|
||||
|
||||
/** @overload
|
||||
|
||||
Creates the HOG descriptor and detector and loads HOGDescriptor parameters and coefficients for the linear SVM classifier from a file.
|
||||
@param filename The file name containing HOGDescriptor properties and coefficients for the linear SVM classifier.
|
||||
*/
|
||||
CV_WRAP HOGDescriptor(const String& filename)
|
||||
@@ -452,19 +459,19 @@ public:
|
||||
*/
|
||||
CV_WRAP virtual void setSVMDetector(InputArray svmdetector);
|
||||
|
||||
/** @brief Reads HOGDescriptor parameters from a cv::FileNode.
|
||||
/** @brief Reads HOGDescriptor parameters and coefficients for the linear SVM classifier from a file node.
|
||||
@param fn File node
|
||||
*/
|
||||
virtual bool read(FileNode& fn);
|
||||
|
||||
/** @brief Stores HOGDescriptor parameters in a cv::FileStorage.
|
||||
/** @brief Stores HOGDescriptor parameters and coefficients for the linear SVM classifier in a file storage.
|
||||
@param fs File storage
|
||||
@param objname Object name
|
||||
*/
|
||||
virtual void write(FileStorage& fs, const String& objname) const;
|
||||
|
||||
/** @brief loads HOGDescriptor parameters and coefficients for the linear SVM classifier from a file.
|
||||
@param filename Path of the file to read.
|
||||
/** @brief loads HOGDescriptor parameters and coefficients for the linear SVM classifier from a file
|
||||
@param filename Name of the file to read.
|
||||
@param objname The optional name of the node to read (if empty, the first top-level node will be used).
|
||||
*/
|
||||
CV_WRAP virtual bool load(const String& filename, const String& objname = String());
|
||||
@@ -537,13 +544,14 @@ public:
|
||||
@param winStride Window stride. It must be a multiple of block stride.
|
||||
@param padding Padding
|
||||
@param scale Coefficient of the detection window increase.
|
||||
@param finalThreshold Final threshold
|
||||
@param groupThreshold Coefficient to regulate the similarity threshold. When detected, some objects can be covered
|
||||
by many rectangles. 0 means not to perform grouping.
|
||||
@param useMeanshiftGrouping indicates grouping algorithm
|
||||
*/
|
||||
CV_WRAP virtual void detectMultiScale(InputArray img, CV_OUT std::vector<Rect>& foundLocations,
|
||||
CV_OUT std::vector<double>& foundWeights, double hitThreshold = 0,
|
||||
Size winStride = Size(), Size padding = Size(), double scale = 1.05,
|
||||
double finalThreshold = 2.0,bool useMeanshiftGrouping = false) const;
|
||||
double groupThreshold = 2.0, bool useMeanshiftGrouping = false) const;
|
||||
|
||||
/** @brief Detects objects of different sizes in the input image. The detected objects are returned as a list
|
||||
of rectangles.
|
||||
@@ -555,13 +563,14 @@ public:
|
||||
@param winStride Window stride. It must be a multiple of block stride.
|
||||
@param padding Padding
|
||||
@param scale Coefficient of the detection window increase.
|
||||
@param finalThreshold Final threshold
|
||||
@param groupThreshold Coefficient to regulate the similarity threshold. When detected, some objects can be covered
|
||||
by many rectangles. 0 means not to perform grouping.
|
||||
@param useMeanshiftGrouping indicates grouping algorithm
|
||||
*/
|
||||
virtual void detectMultiScale(InputArray img, CV_OUT std::vector<Rect>& foundLocations,
|
||||
double hitThreshold = 0, Size winStride = Size(),
|
||||
Size padding = Size(), double scale = 1.05,
|
||||
double finalThreshold = 2.0, bool useMeanshiftGrouping = false) const;
|
||||
double groupThreshold = 2.0, bool useMeanshiftGrouping = false) const;
|
||||
|
||||
/** @brief Computes gradients and quantized gradient orientations.
|
||||
@param img Matrix contains the image to be computed
|
||||
@@ -666,6 +675,10 @@ public:
|
||||
*/
|
||||
void groupRectangles(std::vector<cv::Rect>& rectList, std::vector<double>& weights, int groupThreshold, double eps) const;
|
||||
};
|
||||
//! @}
|
||||
|
||||
//! @addtogroup objdetect_qrcode
|
||||
//! @{
|
||||
|
||||
class CV_EXPORTS_W QRCodeEncoder {
|
||||
protected:
|
||||
@@ -827,7 +840,7 @@ protected:
|
||||
Ptr<Impl> p;
|
||||
};
|
||||
|
||||
//! @} objdetect
|
||||
//! @}
|
||||
}
|
||||
|
||||
#include "opencv2/objdetect/detection_based_tracker.hpp"
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
namespace cv
|
||||
{
|
||||
|
||||
//! @addtogroup objdetect
|
||||
//! @addtogroup objdetect_cascade_classifier
|
||||
//! @{
|
||||
|
||||
class CV_EXPORTS DetectionBasedTracker
|
||||
@@ -215,7 +215,7 @@ class CV_EXPORTS DetectionBasedTracker
|
||||
void detectInRegion(const cv::Mat& img, const cv::Rect& r, std::vector<cv::Rect>& detectedObjectsInRegions);
|
||||
};
|
||||
|
||||
//! @} objdetect
|
||||
//! @}
|
||||
|
||||
} //end of cv namespace
|
||||
|
||||
|
||||
@@ -7,13 +7,15 @@
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
/** @defgroup dnn_face DNN-based face detection and recognition
|
||||
*/
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
/** @brief DNN-based face detector, model download link: https://github.com/ShiqiYu/libfacedetection.train/tree/master/tasks/task1/onnx.
|
||||
//! @addtogroup objdetect_dnn_face
|
||||
//! @{
|
||||
|
||||
/** @brief DNN-based face detector
|
||||
|
||||
model download link: https://github.com/opencv/opencv_zoo/tree/master/models/face_detection_yunet
|
||||
*/
|
||||
class CV_EXPORTS_W FaceDetectorYN
|
||||
{
|
||||
@@ -80,7 +82,9 @@ public:
|
||||
int target_id = 0);
|
||||
};
|
||||
|
||||
/** @brief DNN-based face recognizer, model download link: https://drive.google.com/file/d/1ClK9WiB492c5OZFKveF3XiHCejoOxINW/view.
|
||||
/** @brief DNN-based face recognizer
|
||||
|
||||
model download link: https://github.com/opencv/opencv_zoo/tree/master/models/face_recognition_sface
|
||||
*/
|
||||
class CV_EXPORTS_W FaceRecognizerSF
|
||||
{
|
||||
@@ -105,11 +109,11 @@ public:
|
||||
CV_WRAP virtual void feature(InputArray aligned_img, OutputArray face_feature) = 0;
|
||||
|
||||
/** @brief Calculating the distance between two face features
|
||||
* @param _face_feature1 the first input feature
|
||||
* @param _face_feature2 the second input feature of the same size and the same type as _face_feature1
|
||||
* @param face_feature1 the first input feature
|
||||
* @param face_feature2 the second input feature of the same size and the same type as face_feature1
|
||||
* @param dis_type defining the similarity with optional values "FR_OSINE" or "FR_NORM_L2"
|
||||
*/
|
||||
CV_WRAP virtual double match(InputArray _face_feature1, InputArray _face_feature2, int dis_type = FaceRecognizerSF::FR_COSINE) const = 0;
|
||||
CV_WRAP virtual double match(InputArray face_feature1, InputArray face_feature2, int dis_type = FaceRecognizerSF::FR_COSINE) const = 0;
|
||||
|
||||
/** @brief Creates an instance of this class with given parameters
|
||||
* @param model the path of the onnx model used for face recognition
|
||||
@@ -120,6 +124,7 @@ public:
|
||||
CV_WRAP static Ptr<FaceRecognizerSF> create(const String& model, const String& config, int backend_id = 0, int target_id = 0);
|
||||
};
|
||||
|
||||
//! @}
|
||||
} // namespace cv
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,13 +6,16 @@
|
||||
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
#include "opencv2/dnn.hpp"
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
class FaceDetectorYNImpl : public FaceDetectorYN
|
||||
{
|
||||
public:
|
||||
@@ -273,6 +276,7 @@ private:
|
||||
|
||||
std::vector<Rect2f> priors;
|
||||
};
|
||||
#endif
|
||||
|
||||
Ptr<FaceDetectorYN> FaceDetectorYN::create(const String& model,
|
||||
const String& config,
|
||||
@@ -283,7 +287,12 @@ Ptr<FaceDetectorYN> FaceDetectorYN::create(const String& model,
|
||||
const int backend_id,
|
||||
const int target_id)
|
||||
{
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
return makePtr<FaceDetectorYNImpl>(model, config, input_size, score_threshold, nms_threshold, top_k, backend_id, target_id);
|
||||
#else
|
||||
CV_UNUSED(model); CV_UNUSED(config); CV_UNUSED(input_size); CV_UNUSED(score_threshold); CV_UNUSED(nms_threshold); CV_UNUSED(top_k); CV_UNUSED(backend_id); CV_UNUSED(target_id);
|
||||
CV_Error(cv::Error::StsNotImplemented, "cv::FaceDetectorYN requires enabled 'dnn' module.");
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace cv
|
||||
|
||||
@@ -4,13 +4,17 @@
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
#include "opencv2/dnn.hpp"
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
class FaceRecognizerSFImpl : public FaceRecognizerSF
|
||||
{
|
||||
public:
|
||||
@@ -173,10 +177,16 @@ private:
|
||||
private:
|
||||
dnn::Net net;
|
||||
};
|
||||
#endif
|
||||
|
||||
Ptr<FaceRecognizerSF> FaceRecognizerSF::create(const String& model, const String& config, int backend_id, int target_id)
|
||||
{
|
||||
#ifdef HAVE_OPENCV_DNN
|
||||
return makePtr<FaceRecognizerSFImpl>(model, config, backend_id, target_id);
|
||||
#else
|
||||
CV_UNUSED(model); CV_UNUSED(config); CV_UNUSED(backend_id); CV_UNUSED(target_id);
|
||||
CV_Error(cv::Error::StsNotImplemented, "cv::FaceRecognizerSF requires enabled 'dnn' module");
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace cv
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
|
||||
#include "precomp.hpp"
|
||||
#include "cascadedetect.hpp"
|
||||
#include "opencv2/core/core_c.h"
|
||||
#include "opencv2/core/hal/intrin.hpp"
|
||||
#include "opencl_kernels_objdetect.hpp"
|
||||
|
||||
@@ -1887,7 +1886,7 @@ static bool ocl_detectMultiScale(InputArray _img, std::vector<Rect> &found_locat
|
||||
void HOGDescriptor::detectMultiScale(
|
||||
InputArray _img, std::vector<Rect>& foundLocations, std::vector<double>& foundWeights,
|
||||
double hitThreshold, Size winStride, Size padding,
|
||||
double scale0, double finalThreshold, bool useMeanshiftGrouping) const
|
||||
double scale0, double groupThreshold, bool useMeanshiftGrouping) const
|
||||
{
|
||||
CV_INSTRUMENT_REGION();
|
||||
|
||||
@@ -1913,7 +1912,7 @@ void HOGDescriptor::detectMultiScale(
|
||||
|
||||
CV_OCL_RUN(_img.dims() <= 2 && _img.type() == CV_8UC1 && scale0 > 1 && winStride.width % blockStride.width == 0 &&
|
||||
winStride.height % blockStride.height == 0 && padding == Size(0,0) && _img.isUMat(),
|
||||
ocl_detectMultiScale(_img, foundLocations, levelScale, hitThreshold, winStride, finalThreshold, oclSvmDetector,
|
||||
ocl_detectMultiScale(_img, foundLocations, levelScale, hitThreshold, winStride, groupThreshold, oclSvmDetector,
|
||||
blockSize, cellSize, nbins, blockStride, winSize, gammaCorrection, L2HysThreshold, (float)getWinSigma(), free_coef, signedGradient));
|
||||
|
||||
std::vector<Rect> allCandidates;
|
||||
@@ -1934,21 +1933,21 @@ void HOGDescriptor::detectMultiScale(
|
||||
std::copy(tempWeights.begin(), tempWeights.end(), back_inserter(foundWeights));
|
||||
|
||||
if ( useMeanshiftGrouping )
|
||||
groupRectangles_meanshift(foundLocations, foundWeights, foundScales, finalThreshold, winSize);
|
||||
groupRectangles_meanshift(foundLocations, foundWeights, foundScales, groupThreshold, winSize);
|
||||
else
|
||||
groupRectangles(foundLocations, foundWeights, (int)finalThreshold, 0.2);
|
||||
groupRectangles(foundLocations, foundWeights, (int)groupThreshold, 0.2);
|
||||
clipObjects(imgSize, foundLocations, 0, &foundWeights);
|
||||
}
|
||||
|
||||
void HOGDescriptor::detectMultiScale(InputArray img, std::vector<Rect>& foundLocations,
|
||||
double hitThreshold, Size winStride, Size padding,
|
||||
double scale0, double finalThreshold, bool useMeanshiftGrouping) const
|
||||
double scale0, double groupThreshold, bool useMeanshiftGrouping) const
|
||||
{
|
||||
CV_INSTRUMENT_REGION();
|
||||
|
||||
std::vector<double> foundWeights;
|
||||
detectMultiScale(img, foundLocations, foundWeights, hitThreshold, winStride,
|
||||
padding, scale0, finalThreshold, useMeanshiftGrouping);
|
||||
padding, scale0, groupThreshold, useMeanshiftGrouping);
|
||||
}
|
||||
|
||||
std::vector<float> HOGDescriptor::getDefaultPeopleDetector()
|
||||
|
||||
@@ -78,7 +78,7 @@ TEST(Objdetect_face_detection, regression)
|
||||
// }
|
||||
|
||||
// Initialize detector
|
||||
std::string model = findDataFile("dnn/onnx/models/yunet-202109.onnx", false);
|
||||
std::string model = findDataFile("dnn/onnx/models/yunet-202202.onnx", false);
|
||||
Ptr<FaceDetectorYN> faceDetector = FaceDetectorYN::create(model, "", Size(300, 300));
|
||||
faceDetector->setScoreThreshold(0.7f);
|
||||
|
||||
@@ -178,7 +178,7 @@ TEST(Objdetect_face_recognition, regression)
|
||||
}
|
||||
|
||||
// Initialize detector
|
||||
std::string detect_model = findDataFile("dnn/onnx/models/yunet-202109.onnx", false);
|
||||
std::string detect_model = findDataFile("dnn/onnx/models/yunet-202202.onnx", false);
|
||||
Ptr<FaceDetectorYN> faceDetector = FaceDetectorYN::create(detect_model, "", Size(150, 150), score_thresh, nms_thresh);
|
||||
|
||||
std::string recog_model = findDataFile("dnn/onnx/models/face_recognizer_fast.onnx", false);
|
||||
|
||||
Reference in New Issue
Block a user