Auxilliary Tool:
A class that does the necessary book keeping for filtering an image quickly at many scales.
More...
#include <PatchList.h>
Public Member Functions | |
PatchList (cv::Size minSize=cv::Size(0, 0), cv::Size maxSize=cv::Size(0, 0), double scaleInc=1.2, double stepWidth=1, cv::Size basePatchSize=cv::Size(30, 30)) | |
Constructor. | |
virtual | ~PatchList () |
Destructor. | |
cv::Size | getBasePatchSize () |
Get the base patch size, which is size of the object detector that you plan to apply. It is also the default search minSize, and other scale sizes are computed relative to it. | |
void | setBasePatchSize (cv::Size baseSize) |
Set the base patch size, which is size of the object detector that you plan to apply. It is also the default search minSize, and other scale sizes are computed relative to it. | |
void | setImage (const cv::Mat &newImage) |
Set the image to filter or process for object detection. | |
void | resetListToScale (int scale) |
Prepare the data structure to search for objects at a certain scale. | |
void | accumulateAndRemovePatchesBelowThreshold (double threshold) |
Adds the values in destInds to an accumulator. Any accumulator values that are below threshold are removed from the list. | |
void | keepOnlyLocalMaxima (int radius) |
Remove image patch candidates that have a nearby patch (within radius horizontal or vertical pixels) with a higher value. | |
void | getRemainingPatches (std::vector< SearchResult > &searchResults) |
Get info about the patches that have not yet been removed from the PatchList since calling resetListToScale(). Each SearchResult contains info about the location of the patch in the original image, and its current accumulator value. | |
void | getProbImage (cv::Mat &dest, double faceAreaPrior=.5, double faceInvisibleProb=.1) |
Compute a pixel-by-pixel estimate for this scale that there is an object located at that pixel. | |
cv::Size | getPatchSizeAtScale (int scale=-1) |
Get the effective object size if searching at a given (or the current) scale. | |
cv::Size | getFilterSizeAtScale (int scale=-1) |
Get the filter size that should be applied at this scale. For PatchList, this is always getBasePatchSize(). In PatchList, this always returns getBasePatchSize(). In FastPatchList, this always returns getPatchSizeAtScale(scale). | |
cv::Size | getImageSizeAtScale (int scale=-1) |
Get the size of the valid convolution image, for viewing filtering and accumulator results. | |
int | getIntegralWidthStepAtScale (int scale=-1) |
Get the width step of the integral image, i.e. how many integral_type elements are there in srcInds[i][j] before a pixel that is directly below [j]. | |
int | getCurrentListLength () |
Get the number of remaining patches at this scale. Initially, this has all patches in the scale, but may be reduced by repeated calls to accumulateAndRemovePatchesBelowThreshold(). | |
int | getTotalPatches () |
Get the total number of patches available to this PatchList at all scales. | |
int | getNumScales () |
Get the total number of scales. | |
std::vector< ImagePatch * > | getNearbyPatches (cv::Rect roi, int spatialRadius=0, int scaleRadius=0) |
Get patches near a region of interest. This is useful for augmenting the number of positive examples in a dataset by grabbing nearby patches, or for finding the image patch that is closest to a labelled location. | |
void | fillImageWithPixelsOfSearchPatch (cv::Mat &dest, SearchResult r) |
Get the exact same pixels from the image patch that the filtering process sees. This is useful for pulling out hard background patches for training. | |
void | setDontCopyImageData (int flag=0) |
Improve efficiency by only copying integral data (not image data). This makes fillImageWithPixelsOfSearchPatch fail. | |
void | setDontScaleDownPatches (int flag=0) |
Improve detail of patches when getting pixels of patch -- at the cost of extra memory. Only affects FastPatchList. | |
void | getFilterImage (cv::Mat &image) |
Output of image filtering process as an image which can be visualized. | |
void | getAccumImage (cv::Mat &image) |
Output of filtering accumulation process as an image which can be visualized. | |
Public Attributes | |
integral_type ** | srcInds |
A list of pointers to the top-left of image patches still considered as candidate locations of the object. This pointer is exposed to allow BoxFeature to evaluate the image with maximal efficiency. | |
double ** | destInds |
A list of pointers to corresponding to the filtering outputs of the remaining candidate patches in srcInds. |
Auxilliary Tool:
A class that does the necessary book keeping for filtering an image quickly at many scales.
Specifically, a PatchList gives BoxFeature, FeatureRegressor, and GentleBoostCascadedClassifier a way to apply a single weak learner to all remaining candidate object image patches. GentleBoost requires that each weak learner output be accumulated with the output of other weak learners. PatchList maintains this accumulator.
They key parameters controlling a PatchList are the size of the image (using setImage), the base patch size, and the scale increment factor. Here as an example with an image of size 320x240, a base patch size of 30, and a scale increment of 1.2.
At scale 0, the image is simply copied, and an integral image is computed. It can be filtered in a region up to 29 pixels from the border by a filter of size 30x30 (which is the base patch size). ImageSize represents the size of this valid filtering region, which is 291x211 pixels and is useful for displaying an image representation of the fitlering output. Each of these pixels contains the output of the filtering of one patch, so there are 61401 patches at scale 0.
At scale 1, the size of patches to search increases by a factor of 1.2, giving a patchWidth of 36. Internally, the image is downscaled by a factor of 1.2, giving a 266x200 image, with a 237x171 valid filtering region, and 40527 total patches.
At scale 12, the patch size would be 30*(1.2^12)=267x267. This is larger than the height of the image, and so the largest scale is 11. Since the scales start at 0, there are 12 total scales:
The PatchList has 12 scales containing 170925 total patches.
Other parameters that can be set are maxSize, minSize, and stepWidth. MaxSize changes the maximum searched patch size. If (0,0), then the smaller image dimension is used. MinSize changes the minimum searched patch size. If (0,0), the base patch size is used. Otherwise, the image is scaled in size by a factor of basePatchSize/minSize before searching. StepWidth reduces the number of patches searched by skipping rows and columns. If StepWidth is 1, each patch location is searched. If it is 2, every other one is searched. If it is 2/3, then two consecutive patches are searched and one is skipped.
PatchList is effecicient about not doing more memory allocation than it needs. A rule of thumb is that giving a PatchList images of different sizes will incur a slowdown, but if all images are the same size, then subsequent calls to setImage will be faster.
For example, a typical time for the first call to setImage with a 320x240 image, a base patch size of 30x30, and a scale increment of 1.2 is 15 ms, while subsequent calls with the same image size and parameters takes 1.5 ms.
PatchList::PatchList | ( | cv::Size | minSize = cv::Size(0, 0) , |
cv::Size | maxSize = cv::Size(0, 0) , |
||
double | scaleInc = 1.2 , |
||
double | stepWidth = 1 , |
||
cv::Size | basePatchSize = cv::Size(30, 30) |
||
) |
Constructor.
minSize | Don't search for objects smaller than minSize. If minSize is (0,0) then baseObjectSize is used. |
maxSize | Don't search for objects larger than maxSize. If maxSize is (0,0), then the upper bound on the object size is the smallest dimension of the image size. |
scaleInc | Relative size of the object in the next scale, compared to the current one. scaleInc must be greater than 1. |
stepWidth | Search interval between subsequent patches. A stepWidth of 1 means slide the object evaluation window over one pixel. 2 means only evaluate patches at every other pixel. 1.5 means search two and skip the third, etc. |
basePatchSize | The size of the patches that will be evaluated for containing the object. This should match the size of whatever filter will be applied to the patches. It may be set later, using setBasePatchSize(). At subsequent scales, the image is scaled up or down relative to this size. |
void PatchList::accumulateAndRemovePatchesBelowThreshold | ( | double | threshold ) |
Adds the values in destInds to an accumulator. Any accumulator values that are below threshold are removed from the list.
threshold | Accumulator values below threshold will be removed from the PatchList. -INFINITY will insure all patches are kept. |
void PatchList::fillImageWithPixelsOfSearchPatch | ( | cv::Mat & | dest, |
SearchResult | r | ||
) |
Get the exact same pixels from the image patch that the filtering process sees. This is useful for pulling out hard background patches for training.
im | Destination image for pixels. |
r | A Patch SearchResult from getRemainingPatches() to query. |
void PatchList::getAccumImage | ( | cv::Mat & | image ) |
Output of filtering accumulation process as an image which can be visualized.
This image contains that data that was accumulated by successive calls to accumulateAndRemovePatchesBelowThreshold().
Size PatchList::getBasePatchSize | ( | ) |
Get the base patch size, which is size of the object detector that you plan to apply. It is also the default search minSize, and other scale sizes are computed relative to it.
int PatchList::getCurrentListLength | ( | ) |
Get the number of remaining patches at this scale. Initially, this has all patches in the scale, but may be reduced by repeated calls to accumulateAndRemovePatchesBelowThreshold().
void PatchList::getFilterImage | ( | cv::Mat & | image ) |
Output of image filtering process as an image which can be visualized.
This image contains that data that is written in destInds by BoxFeature and FeatureRegressor and GentleBoostCascadedClassifier.
Size PatchList::getFilterSizeAtScale | ( | int | scale = -1 ) |
Get the filter size that should be applied at this scale. For PatchList, this is always getBasePatchSize(). In PatchList, this always returns getBasePatchSize(). In FastPatchList, this always returns getPatchSizeAtScale(scale).
You must call setImage() before. When querying scales for information, the maximum valid value is getNumScales()-1, and the minimum is 0.
scale | The scale to query. If -1, use the current. Otherwise, any valid scale can be queried. |
Size PatchList::getImageSizeAtScale | ( | int | scale = -1 ) |
Get the size of the valid convolution image, for viewing filtering and accumulator results.
You must call setImage() before because it is impossible to determine the filtered image size without knowing the image size. When querying scales for information, the maximum valid value is getNumScales()-1, and the minimum is 0.
scale | The scale to query. If -1, use the current. Otherwise, any valid scale can be queried. |
int PatchList::getIntegralWidthStepAtScale | ( | int | scale = -1 ) |
Get the width step of the integral image, i.e. how many integral_type elements are there in srcInds[i][j] before a pixel that is directly below [j].
You must call setImage() before because it is impossible to determine the size of the integral image without knowing the image size. When querying scales for information, the maximum valid value is getNumScales()-1, and the minimum is 0.
scale | The scale to query. If -1, use the current. Otherwise, any valid scale can be queried. |
vector< ImagePatch * > PatchList::getNearbyPatches | ( | cv::Rect | roi, |
int | spatialRadius = 0 , |
||
int | scaleRadius = 0 |
||
) |
Get patches near a region of interest. This is useful for augmenting the number of positive examples in a dataset by grabbing nearby patches, or for finding the image patch that is closest to a labelled location.
roi | A region of interest in the image. |
spatialRadius | Take patches that are slightly left/right/up/down from roi.Note that a radius of 1 gives 9 patches, and a radius of 2 gives 25. |
scaleRadius | Take patches that are slightly larger or smaller than the roi. This size is radius is in terms of search scale, not pixels. Note that a radius of 1 gives 3 patches, and a radius of 2 gives 5. |
!!!! TODO : Check this out. -- Decide if we want this to be size of base patch or size of patch in image
int PatchList::getNumScales | ( | ) |
Get the total number of scales.
You must call setImage() before because it is impossible to determine the number of scales without knowing the image size. When querying scales for information, the maximum valid value is getNumScales()-1, and the minimum is 0.
Size PatchList::getPatchSizeAtScale | ( | int | scale = -1 ) |
Get the effective object size if searching at a given (or the current) scale.
You must call setImage() before because it is impossible to determine the number of patch sizes without knowing the image size. When querying scales for information, the maximum valid value is getNumScales()-1, and the minimum is 0.
scale | The scale to query. If -1, use the current. Otherwise, any valid scale can be queried. |
void PatchList::getRemainingPatches | ( | std::vector< SearchResult > & | searchResults ) |
Get info about the patches that have not yet been removed from the PatchList since calling resetListToScale(). Each SearchResult contains info about the location of the patch in the original image, and its current accumulator value.
searchResults | The vector that will be filled with the remaining patches. The contents of the vector passed in are entirely overwritten. |
int PatchList::getTotalPatches | ( | ) |
void PatchList::keepOnlyLocalMaxima | ( | int | radius ) |
Remove image patch candidates that have a nearby patch (within radius horizontal or vertical pixels) with a higher value.
radius | Radius (in pixels) to do non-maximal suppression. Pixels are scale-adjusted, so the suppression region grows with the size of the object. |
void PatchList::resetListToScale | ( | int | scale ) |
Prepare the data structure to search for objects at a certain scale.
You must call setImage() before because it is impossible to determine various scale info without knowing the image size. When querying scales for information, the maximum valid value is getNumScales()-1, and the minimum is 0.
Scales number from 0 to getNumScales()-1. 0 searches for smallest objects, getNumScales()-1 searches for the largest.
void PatchList::setBasePatchSize | ( | cv::Size | baseSize ) |
Set the base patch size, which is size of the object detector that you plan to apply. It is also the default search minSize, and other scale sizes are computed relative to it.
This can be changed somewhat freely, but setImage() must be called afterward.
baseSize | The base patch size. |
void PatchList::setDontCopyImageData | ( | int | flag = 0 ) |
Improve efficiency by only copying integral data (not image data). This makes fillImageWithPixelsOfSearchPatch fail.
flag | Set to non-zero if you want efficiency, but not to look at patches. |
void PatchList::setDontScaleDownPatches | ( | int | flag = 0 ) |
Improve detail of patches when getting pixels of patch -- at the cost of extra memory. Only affects FastPatchList.
flag | Set to non-zero if you want big patches for training with FastPatchList. |
void PatchList::setImage | ( | const cv::Mat & | newImage ) |
Set the image to filter or process for object detection.
newImage | The image to process must be a single channel image of IPL_DEPTH_8U. It can be of any size, but passing images of the same size repeatedly will boost performance. |
double** PatchList::destInds |
A list of pointers to corresponding to the filtering outputs of the remaining candidate patches in srcInds.
This is a place for BoxFeature, FeatureRegressor, GentleBoostCascadedClassifier etc. to store their outputs.