The Detection structure is a high-level C++ wrapper for object detection with HAAR and LBP cascade classifiers. More...
#include <SimdDetection.hpp>
Data Structures | |
| struct | Object |
| The Object structure describes one grouped detection result. More... | |
Public Types | |
| typedef A< uint8_t > | Allocator |
| typedef Simd::View< A > | View |
| typedef Simd::Point< ptrdiff_t > | Size |
| typedef std::vector< Size > | Sizes |
| typedef Simd::Rectangle< ptrdiff_t > | Rect |
| typedef std::vector< Rect > | Rects |
| typedef int | Tag |
| typedef std::vector< Object > | Objects |
Public Member Functions | |
| Detection () | |
| ~Detection () | |
| bool | LoadStringXml (const std::string &xml, Tag tag=UNDEFINED_OBJECT_TAG) |
| bool | Load (const std::string &path, Tag tag=UNDEFINED_OBJECT_TAG) |
| bool | Init (const Size &imageSize, double scaleFactor=1.1, const Size &sizeMin=Size(0, 0), const Size &sizeMax=Size(INT_MAX, INT_MAX), const View &roi=View(), ptrdiff_t threadNumber=-1) |
| bool | Detect (const View &src, Objects &objects, int groupSizeMin=3, double sizeDifferenceMax=0.2, bool motionMask=false, const Rects &motionRegions=Rects()) |
Static Public Attributes | |
| static const Tag | UNDEFINED_OBJECT_TAG = -1 |
Detailed Description
struct Simd::Detection< A >
The Detection structure is a high-level C++ wrapper for object detection with HAAR and LBP cascade classifiers.
The structure loads one or more OpenCV-format cascades, prepares a scale pyramid for a fixed input image size and then detects objects in images of this size. The input image can be gray or color; color images are converted to gray internally. If several cascades are loaded, every cascade is applied independently and detections are grouped separately for every user tag.
Using example (face detection in the image):
Using example (face detection in the video captured by OpenCV):
- Note
- This is wrapper around low-level Object Detection API.
Member Typedef Documentation
◆ Allocator
◆ View
| typedef Simd::View<A> View |
Image view type used for input images, ROI masks and internal pyramid levels.
◆ Size
| typedef Simd::Point<ptrdiff_t> Size |
Two-dimensional size or point type.
◆ Sizes
◆ Rect
| typedef Simd::Rectangle<ptrdiff_t> Rect |
Rectangle type used for object bounds and search regions.
◆ Rects
◆ Tag
| typedef int Tag |
User tag type used to identify detections from different cascades.
◆ Objects
Constructor & Destructor Documentation
◆ Detection()
| Detection | ( | ) |
Creates a new empty Detection structure. Load at least one cascade and call Init before Detect.
◆ ~Detection()
| ~Detection | ( | ) |
Releases all loaded cascades.
Member Function Documentation
◆ LoadStringXml()
| bool LoadStringXml | ( | const std::string & | xml, |
| Tag | tag = UNDEFINED_OBJECT_TAG |
||
| ) |
Loads a classifier cascade from XML text. Supports OpenCV HAAR and LBP cascade types. You can call this function more than once if you want to use several object detectors at the same time.
- Note
- Tree based cascades and old cascade formats are not supported!
- Parameters
-
[in] xml - a string containing XML with cascade. [in] tag - a user defined tag. This tag will be inserted into output Object structures.
- Returns
- a result of this operation.
◆ Load()
| bool Load | ( | const std::string & | path, |
| Tag | tag = UNDEFINED_OBJECT_TAG |
||
| ) |
Loads a classifier cascade from an XML file. Supports OpenCV HAAR and LBP cascade types. You can call this function more than once if you want to use several object detectors at the same time.
- Note
- Tree based cascades and old cascade formats are not supported!
- Parameters
-
[in] path - a path to XML cascade file. [in] tag - a user defined tag. This tag will be inserted into output Object structures.
- Returns
- a result of this operation.
◆ Init()
| bool Init | ( | const Size & | imageSize, |
| double | scaleFactor = 1.1, |
||
| const Size & | sizeMin = Size(0, 0), |
||
| const Size & | sizeMax = Size(INT_MAX, INT_MAX), |
||
| const View & | roi = View(), |
||
| ptrdiff_t | threadNumber = -1 |
||
| ) |
Prepares Detection structure to work with images of the given size.
The function builds internal pyramid levels for all loaded cascades and object sizes that fit into [sizeMin, sizeMax]. It must be called after loading cascades and before Detect. After successful initialization every input image passed to Detect must have the same size as imageSize.
- Parameters
-
[in] imageSize - a size of input image. [in] scaleFactor - a multiplier between neighboring pyramid levels. Values close to 1 improve scale precision but create more levels and reduce performance. [in] sizeMin - a minimal size of detected objects in input image coordinates. It strongly affects performance. [in] sizeMax - a maximal size of detected objects in input image coordinates. [in] roi - an optional 8-bit mask which defines a Region Of Interest. Non-zero mask pixels allow detection; zero pixels reject it. The mask is applied to detected object centers. [in] threadNumber - a number of worker threads. Use value -1 to choose this number automatically.
- Returns
- a result of this operation.
◆ Detect()
| bool Detect | ( | const View & | src, |
| Objects & | objects, | ||
| int | groupSizeMin = 3, |
||
| double | sizeDifferenceMax = 0.2, |
||
| bool | motionMask = false, |
||
| const Rects & | motionRegions = Rects() |
||
| ) |
Detects objects in the given image.
The function runs all initialized pyramid levels, collects elementary detections and then groups similar rectangles separately for every cascade tag. The output vector is cleared before grouped objects are added.
- Parameters
-
[in] src - an input image. Its size must be equal to imageSize passed to Init. [out] objects - detected and grouped objects. [in] groupSizeMin - a minimal number of elementary detections required to keep a grouped object. If this value is zero, no objects are returned. [in] sizeDifferenceMax - a relative rectangle difference used to group elementary detections. [in] motionMask - a flag to restrict detection by motionRegions in addition to the ROI mask. [in] motionRegions - rectangles in input image coordinates that dynamically restrict detection. The regions are applied to detected object centers.
- Returns
- a result of this operation.
Field Documentation
◆ UNDEFINED_OBJECT_TAG
|
static |
Default tag assigned to objects when no user tag is specified.