commit
9a0cc98078
54 changed files with 5514 additions and 0 deletions
@ -0,0 +1,2 @@ |
||||
set(the_description "Object Detection") |
||||
ocv_define_module(latentsvm opencv_core opencv_imgproc opencv_objdetect opencv_ts OPTIONAL opencv_highgui) |
@ -0,0 +1,113 @@ |
||||
Latent SVM |
||||
=============================================================== |
||||
|
||||
Discriminatively Trained Part Based Models for Object Detection |
||||
--------------------------------------------------------------- |
||||
|
||||
The object detector described below has been initially proposed by |
||||
P.F. Felzenszwalb in [Felzenszwalb2010a]_. It is based on a |
||||
Dalal-Triggs detector that uses a single filter on histogram of |
||||
oriented gradients (HOG) features to represent an object category. |
||||
This detector uses a sliding window approach, where a filter is |
||||
applied at all positions and scales of an image. The first |
||||
innovation is enriching the Dalal-Triggs model using a |
||||
star-structured part-based model defined by a "root" filter |
||||
(analogous to the Dalal-Triggs filter) plus a set of parts filters |
||||
and associated deformation models. The score of one of star models |
||||
at a particular position and scale within an image is the score of |
||||
the root filter at the given location plus the sum over parts of the |
||||
maximum, over placements of that part, of the part filter score on |
||||
its location minus a deformation cost easuring the deviation of the |
||||
part from its ideal location relative to the root. Both root and |
||||
part filter scores are defined by the dot product between a filter |
||||
(a set of weights) and a subwindow of a feature pyramid computed |
||||
from the input image. Another improvement is a representation of the |
||||
class of models by a mixture of star models. The score of a mixture |
||||
model at a particular position and scale is the maximum over |
||||
components, of the score of that component model at the given |
||||
location. |
||||
|
||||
The detector was dramatically speeded-up with cascade algorithm |
||||
proposed by P.F. Felzenszwalb in [Felzenszwalb2010b]_. The algorithm |
||||
prunes partial hypotheses using thresholds on their scores.The basic |
||||
idea of the algorithm is to use a hierarchy of models defined by an |
||||
ordering of the original model's parts. For a model with (n+1) |
||||
parts, including the root, a sequence of (n+1) models is obtained. |
||||
The i-th model in this sequence is defined by the first i parts from |
||||
the original model. Using this hierarchy, low scoring hypotheses can be |
||||
pruned after looking at the best configuration of a subset of the parts. |
||||
Hypotheses that score high under a weak model are evaluated further using |
||||
a richer model. |
||||
|
||||
In OpenCV there is an C++ implementation of Latent SVM. |
||||
|
||||
.. highlight:: cpp |
||||
|
||||
LSVMDetector |
||||
----------------- |
||||
.. ocv:class:: LSVMDetector |
||||
|
||||
This is a C++ abstract class, it provides external user API to work with Latent SVM. |
||||
|
||||
LSVMDetector::ObjectDetection |
||||
---------------------------------- |
||||
.. ocv:struct:: LSVMDetector::ObjectDetection |
||||
|
||||
Structure contains the detection information. |
||||
|
||||
.. ocv:member:: Rect rect |
||||
|
||||
bounding box for a detected object |
||||
|
||||
.. ocv:member:: float score |
||||
|
||||
confidence level |
||||
|
||||
.. ocv:member:: int classID |
||||
|
||||
class (model or detector) ID that detect an object |
||||
|
||||
LSVMDetector::~LSVMDetector |
||||
------------------------------------- |
||||
Destructor. |
||||
|
||||
.. ocv:function:: LSVMDetector::~LSVMDetector() |
||||
|
||||
LSVMDetector::create |
||||
----------------------- |
||||
Load the trained models from given ``.xml`` files and return ``cv::Ptr<LSVMDetector>``. |
||||
|
||||
.. ocv:function:: static cv::Ptr<LSVMDetector> LSVMDetector::create( const vector<string>& filenames, const vector<string>& classNames=vector<string>() ) |
||||
|
||||
:param filenames: A set of filenames storing the trained detectors (models). Each file contains one model. See examples of such files here /opencv_extra/testdata/cv/LSVMDetector/models_VOC2007/. |
||||
|
||||
:param classNames: A set of trained models names. If it's empty then the name of each model will be constructed from the name of file containing the model. E.g. the model stored in "/home/user/cat.xml" will get the name "cat". |
||||
|
||||
LSVMDetector::detect |
||||
------------------------- |
||||
Find rectangular regions in the given image that are likely to contain objects of loaded classes (models) |
||||
and corresponding confidence levels. |
||||
|
||||
.. ocv:function:: void LSVMDetector::detect( const Mat& image, vector<ObjectDetection>& objectDetections, float overlapThreshold=0.5f, int numThreads=-1 ) |
||||
|
||||
:param image: An image. |
||||
:param objectDetections: The detections: rectangulars, scores and class IDs. |
||||
:param overlapThreshold: Threshold for the non-maximum suppression algorithm. |
||||
:param numThreads: Number of threads used in parallel version of the algorithm. |
||||
|
||||
LSVMDetector::getClassNames |
||||
-------------------------------- |
||||
Return the class (model) names that were passed in constructor or method ``load`` or extracted from models filenames in those methods. |
||||
|
||||
.. ocv:function:: const vector<string>& LSVMDetector::getClassNames() const |
||||
|
||||
LSVMDetector::getClassCount |
||||
-------------------------------- |
||||
Return a count of loaded models (classes). |
||||
|
||||
.. ocv:function:: size_t LSVMDetector::getClassCount() const |
||||
|
||||
|
||||
.. [Felzenszwalb2010a] Felzenszwalb, P. F. and Girshick, R. B. and McAllester, D. and Ramanan, D. *Object Detection with Discriminatively Trained Part Based Models*. PAMI, vol. 32, no. 9, pp. 1627-1645, September 2010 |
||||
.. [Felzenszwalb2010b] Felzenszwalb, P. F. and Girshick, R. B. and McAllester, D. *Cascade Object Detection with Deformable Part Models*. CVPR 2010, pp. 2241-2248 |
||||
|
@ -0,0 +1,93 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, University of Nizhny Novgorod, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
// SVM implementation authors:
|
||||
// Evgeniy Kozinov - evgeniy.kozinov@gmail.com
|
||||
// Valentina Kustikova - valentina.kustikova@gmail.com
|
||||
// Nikolai Zolotykh - Nikolai.Zolotykh@gmail.com
|
||||
// Iosif Meyerov - meerov@vmk.unn.ru
|
||||
// Alexey Polovinkin - polovinkin.alexey@gmail.com
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_LATENTSVM_HPP__ |
||||
#define __OPENCV_LATENTSVM_HPP__ |
||||
|
||||
#include "opencv2/core.hpp" |
||||
|
||||
#include <map> |
||||
#include <vector> |
||||
#include <string> |
||||
|
||||
namespace cv |
||||
{ |
||||
|
||||
namespace lsvm |
||||
{ |
||||
|
||||
class CV_EXPORTS_W LSVMDetector |
||||
{ |
||||
public: |
||||
|
||||
struct CV_EXPORTS_W ObjectDetection |
||||
{ |
||||
ObjectDetection(); |
||||
ObjectDetection( const Rect& rect, float score, int classID=-1 ); |
||||
Rect rect; |
||||
float score; |
||||
int classID; |
||||
}; |
||||
|
||||
virtual bool isEmpty() const = 0; |
||||
virtual void detect(cv::Mat const &image, CV_OUT std::vector<ObjectDetection> &objects, |
||||
float overlapThreshold=0.5f ) = 0; |
||||
|
||||
virtual std::vector<std::string> const& getClassNames() const = 0; |
||||
virtual size_t getClassCount() const = 0; |
||||
|
||||
static cv::Ptr<LSVMDetector> create(std::vector<std::string> const &filenames, |
||||
std::vector<std::string> const &classNames = std::vector<std::string>()); |
||||
|
||||
virtual ~LSVMDetector(){} |
||||
}; |
||||
|
||||
} // namespace lsvm
|
||||
} // namespace cv
|
||||
|
||||
#endif |
@ -0,0 +1,50 @@ |
||||
#include "perf_precomp.hpp" |
||||
#include <opencv2/imgproc.hpp> |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace perf; |
||||
using std::tr1::make_tuple; |
||||
using std::tr1::get; |
||||
|
||||
typedef std::tr1::tuple<std::string, int> ImageName_MinSize_t; |
||||
typedef perf::TestBaseWithParam<ImageName_MinSize_t> ImageName_MinSize; |
||||
|
||||
PERF_TEST_P(ImageName_MinSize, CascadeClassifierLBPFrontalFace, |
||||
testing::Combine(testing::Values( std::string("cv/shared/lena.png"), |
||||
std::string("cv/shared/1_itseez-0000289.png"), |
||||
std::string("cv/shared/1_itseez-0000492.png"), |
||||
std::string("cv/shared/1_itseez-0000573.png")), |
||||
testing::Values(24, 30, 40, 50, 60, 70, 80, 90) |
||||
) |
||||
) |
||||
{ |
||||
const string filename = get<0>(GetParam()); |
||||
int min_size = get<1>(GetParam()); |
||||
Size minSize(min_size, min_size); |
||||
|
||||
CascadeClassifier cc(getDataPath("cv/cascadeandhog/cascades/lbpcascade_frontalface.xml")); |
||||
if (cc.empty()) |
||||
FAIL() << "Can't load cascade file"; |
||||
|
||||
Mat img = imread(getDataPath(filename), 0); |
||||
if (img.empty()) |
||||
FAIL() << "Can't load source image"; |
||||
|
||||
vector<Rect> faces; |
||||
|
||||
equalizeHist(img, img); |
||||
declare.in(img); |
||||
|
||||
while(next()) |
||||
{ |
||||
faces.clear(); |
||||
|
||||
startTimer(); |
||||
cc.detectMultiScale(img, faces, 1.1, 3, 0, minSize); |
||||
stopTimer(); |
||||
} |
||||
|
||||
std::sort(faces.begin(), faces.end(), comparators::RectLess()); |
||||
SANITY_CHECK(faces, 3.001 * faces.size()); |
||||
} |
@ -0,0 +1,3 @@ |
||||
#include "perf_precomp.hpp" |
||||
|
||||
CV_PERF_TEST_MAIN(objdetect) |
@ -0,0 +1 @@ |
||||
#include "perf_precomp.hpp" |
@ -0,0 +1,20 @@ |
||||
#ifdef __GNUC__ |
||||
# pragma GCC diagnostic ignored "-Wmissing-declarations" |
||||
# if defined __clang__ || defined __APPLE__ |
||||
# pragma GCC diagnostic ignored "-Wmissing-prototypes" |
||||
# pragma GCC diagnostic ignored "-Wextra" |
||||
# endif |
||||
#endif |
||||
|
||||
#ifndef __OPENCV_PERF_PRECOMP_HPP__ |
||||
#define __OPENCV_PERF_PRECOMP_HPP__ |
||||
|
||||
#include "opencv2/ts.hpp" |
||||
#include "opencv2/objdetect.hpp" |
||||
#include "opencv2/highgui.hpp" |
||||
|
||||
#ifdef GTEST_CREATE_SHARED_LIBRARY |
||||
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined |
||||
#endif |
||||
|
||||
#endif |
@ -0,0 +1,61 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, University of Nizhny Novgorod, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef LSVM_ERROR |
||||
#define LSVM_ERROR |
||||
|
||||
#define LATENT_SVM_OK 0 |
||||
#define LATENT_SVM_MEM_NULL 2 |
||||
#define DISTANCE_TRANSFORM_OK 1 |
||||
#define DISTANCE_TRANSFORM_GET_INTERSECTION_ERROR -1 |
||||
#define DISTANCE_TRANSFORM_ERROR -2 |
||||
#define DISTANCE_TRANSFORM_EQUAL_POINTS -3 |
||||
#define LATENT_SVM_GET_FEATURE_PYRAMID_FAILED -4 |
||||
#define LATENT_SVM_SEARCH_OBJECT_FAILED -5 |
||||
#define LATENT_SVM_FAILED_SUPERPOSITION -6 |
||||
#define FILTER_OUT_OF_BOUNDARIES -7 |
||||
#define LATENT_SVM_TBB_SCHEDULE_CREATION_FAILED -8 |
||||
#define LATENT_SVM_TBB_NUMTHREADS_NOT_CORRECT -9 |
||||
#define FFT_OK 2 |
||||
#define FFT_ERROR -10 |
||||
#define LSVM_PARSER_FILE_NOT_FOUND -11 |
||||
|
||||
#endif |
@ -0,0 +1,58 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, University of Nizhny Novgorod, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef FUNCTION_SC |
||||
#define FUNCTION_SC |
||||
|
||||
#include "_lsvmc_types.h" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace lsvm |
||||
{ |
||||
|
||||
float calcM (int k,int di,int dj, const CvLSVMFeaturePyramidCaskade * H, const CvLSVMFilterObjectCaskade *filter); |
||||
float calcM_PCA (int k,int di,int dj, const CvLSVMFeaturePyramidCaskade * H, const CvLSVMFilterObjectCaskade *filter); |
||||
float calcM_PCA_cash(int k,int di,int dj, const CvLSVMFeaturePyramidCaskade * H, const CvLSVMFilterObjectCaskade *filter, float * cashM, int * maskM, int step); |
||||
float calcFine (const CvLSVMFilterObjectCaskade *filter, int di, int dj); |
||||
} |
||||
} |
||||
#endif |
@ -0,0 +1,379 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, University of Nizhny Novgorod, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
/*****************************************************************************/ |
||||
/* Latent SVM prediction API */ |
||||
/*****************************************************************************/ |
||||
|
||||
#ifndef _LATENTSVM_H_ |
||||
#define _LATENTSVM_H_ |
||||
|
||||
#include <stdio.h> |
||||
#include "_lsvmc_types.h" |
||||
#include "_lsvmc_error.h" |
||||
#include "_lsvmc_routine.h" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace lsvm |
||||
{ |
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Building feature pyramid
|
||||
// (pyramid constructed both contrast and non-contrast image)
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
void FeaturePyramid32(CvLSVMFeaturePyramidCaskade* H, int maxX, int maxY); |
||||
|
||||
/*
|
||||
// Creation PSA feature pyramid
|
||||
//
|
||||
// API
|
||||
// featurePyramid* createPSA_FeaturePyramid(featurePyramid* H);
|
||||
|
||||
// INPUT
|
||||
// H - feature pyramid
|
||||
// OUTPUT
|
||||
// RESULT
|
||||
// PSA feature pyramid
|
||||
*/ |
||||
CvLSVMFeaturePyramidCaskade* createPCA_FeaturePyramid(CvLSVMFeaturePyramidCaskade* H,
|
||||
CvLatentSvmDetectorCaskade* detector,
|
||||
int maxX, int maxY); |
||||
|
||||
/*
|
||||
// Getting feature pyramid
|
||||
//
|
||||
// API
|
||||
// int getFeaturePyramid(IplImage * image, const CvLSVMFilterObjectCaskade **all_F,
|
||||
const int n_f, |
||||
const int lambda, const int k,
|
||||
const int startX, const int startY,
|
||||
const int W, const int H, featurePyramid **maps); |
||||
// INPUT
|
||||
// image - image
|
||||
// lambda - resize scale
|
||||
// k - size of cells
|
||||
// startX - X coordinate of the image rectangle to search
|
||||
// startY - Y coordinate of the image rectangle to search
|
||||
// W - width of the image rectangle to search
|
||||
// H - height of the image rectangle to search
|
||||
// OUTPUT
|
||||
// maps - feature maps for all levels
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int getFeaturePyramid(IplImage * image, CvLSVMFeaturePyramidCaskade **maps); |
||||
|
||||
/*
|
||||
// Getting feature map for the selected subimage
|
||||
//
|
||||
// API
|
||||
// int getFeatureMaps(const IplImage * image, const int k, featureMap **map);
|
||||
// INPUT
|
||||
// image - selected subimage
|
||||
// k - size of cells
|
||||
// OUTPUT
|
||||
// map - feature map
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int getFeatureMaps(const IplImage * image, const int k, CvLSVMFeatureMapCaskade **map); |
||||
|
||||
|
||||
/*
|
||||
// Feature map Normalization and Truncation
|
||||
//
|
||||
// API
|
||||
// int normalizationAndTruncationFeatureMaps(featureMap *map, const float alfa);
|
||||
// INPUT
|
||||
// map - feature map
|
||||
// alfa - truncation threshold
|
||||
// OUTPUT
|
||||
// map - truncated and normalized feature map
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int normalizeAndTruncate(CvLSVMFeatureMapCaskade *map, const float alfa); |
||||
|
||||
/*
|
||||
// Feature map reduction
|
||||
// In each cell we reduce dimension of the feature vector
|
||||
// according to original paper special procedure
|
||||
//
|
||||
// API
|
||||
// int PCAFeatureMaps(featureMap *map)
|
||||
// INPUT
|
||||
// map - feature map
|
||||
// OUTPUT
|
||||
// map - feature map
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int PCAFeatureMaps(CvLSVMFeatureMapCaskade *map); |
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// search object
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
// Transformation filter displacement from the block space
|
||||
// to the space of pixels at the initial image
|
||||
//
|
||||
// API
|
||||
// int convertPoints(int countLevel, int lambda,
|
||||
int initialImageLevel, |
||||
CvPoint *points, int *levels,
|
||||
CvPoint **partsDisplacement, int kPoints, int n,
|
||||
int maxXBorder, |
||||
int maxYBorder); |
||||
// INPUT
|
||||
// countLevel - the number of levels in the feature pyramid
|
||||
// lambda - method parameter
|
||||
// initialImageLevel - level of feature pyramid that contains feature map
|
||||
for initial image |
||||
// points - the set of root filter positions (in the block space)
|
||||
// levels - the set of levels
|
||||
// partsDisplacement - displacement of part filters (in the block space)
|
||||
// kPoints - number of root filter positions
|
||||
// n - number of part filters
|
||||
// maxXBorder - the largest root filter size (X-direction)
|
||||
// maxYBorder - the largest root filter size (Y-direction)
|
||||
// OUTPUT
|
||||
// points - the set of root filter positions (in the space of pixels)
|
||||
// partsDisplacement - displacement of part filters (in the space of pixels)
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int convertPoints(int countLevel, int lambda,
|
||||
int initialImageLevel, |
||||
CvPoint *points, int *levels,
|
||||
CvPoint **partsDisplacement, int kPoints, int n,
|
||||
int maxXBorder, |
||||
int maxYBorder); |
||||
|
||||
/*
|
||||
// Elimination boxes that are outside the image boudaries
|
||||
//
|
||||
// API
|
||||
// int clippingBoxes(int width, int height,
|
||||
CvPoint *points, int kPoints); |
||||
// INPUT
|
||||
// width - image wediht
|
||||
// height - image heigth
|
||||
// points - a set of points (coordinates of top left or
|
||||
bottom right corners) |
||||
// kPoints - points number
|
||||
// OUTPUT
|
||||
// points - updated points (if coordinates less than zero then
|
||||
set zero coordinate, if coordinates more than image
|
||||
size then set coordinates equal image size) |
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int clippingBoxes(int width, int height,
|
||||
CvPoint *points, int kPoints); |
||||
|
||||
/*
|
||||
// Creation feature pyramid with nullable border
|
||||
//
|
||||
// API
|
||||
// featurePyramid* createFeaturePyramidWithBorder(const IplImage *image,
|
||||
int maxXBorder, int maxYBorder); |
||||
|
||||
// INPUT
|
||||
// image - initial image
|
||||
// maxXBorder - the largest root filter size (X-direction)
|
||||
// maxYBorder - the largest root filter size (Y-direction)
|
||||
// OUTPUT
|
||||
// RESULT
|
||||
// Feature pyramid with nullable border
|
||||
*/ |
||||
CvLSVMFeaturePyramidCaskade* createFeaturePyramidWithBorder(IplImage *image, |
||||
int maxXBorder, int maxYBorder); |
||||
|
||||
/*
|
||||
// Computation root filters displacement and values of score function
|
||||
//
|
||||
// API
|
||||
// int searchObjectThresholdSomeComponents(const featurePyramid *H,
|
||||
const CvLSVMFilterObjectCaskade **filters,
|
||||
int kComponents, const int *kPartFilters, |
||||
const float *b, float scoreThreshold, |
||||
CvPoint **points, CvPoint **oppPoints, |
||||
float **score, int *kPoints); |
||||
// INPUT
|
||||
// H - feature pyramid
|
||||
// filters - filters (root filter then it's part filters, etc.)
|
||||
// kComponents - root filters number
|
||||
// kPartFilters - array of part filters number for each component
|
||||
// b - array of linear terms
|
||||
// scoreThreshold - score threshold
|
||||
// OUTPUT
|
||||
// points - root filters displacement (top left corners)
|
||||
// oppPoints - root filters displacement (bottom right corners)
|
||||
// score - array of score values
|
||||
// kPoints - number of boxes
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int searchObjectThresholdSomeComponents(const CvLSVMFeaturePyramidCaskade *H, |
||||
const CvLSVMFeaturePyramidCaskade *H_PCA, |
||||
const CvLSVMFilterObjectCaskade **filters,
|
||||
int kComponents, const int *kPartFilters, |
||||
const float *b, float scoreThreshold, |
||||
CvPoint **points, CvPoint **oppPoints, |
||||
float **score, int *kPoints); |
||||
|
||||
/*
|
||||
// Compute opposite point for filter box
|
||||
//
|
||||
// API
|
||||
// int getOppositePoint(CvPoint point,
|
||||
int sizeX, int sizeY, |
||||
float step, int degree, |
||||
CvPoint *oppositePoint); |
||||
|
||||
// INPUT
|
||||
// point - coordinates of filter top left corner
|
||||
(in the space of pixels) |
||||
// (sizeX, sizeY) - filter dimension in the block space
|
||||
// step - scaling factor
|
||||
// degree - degree of the scaling factor
|
||||
// OUTPUT
|
||||
// oppositePoint - coordinates of filter bottom corner
|
||||
(in the space of pixels) |
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int getOppositePoint(CvPoint point, |
||||
int sizeX, int sizeY, |
||||
float step, int degree, |
||||
CvPoint *oppositePoint); |
||||
|
||||
/*
|
||||
// Drawing root filter boxes
|
||||
//
|
||||
// API
|
||||
// int showRootFilterBoxes(const IplImage *image,
|
||||
const CvLSVMFilterObjectCaskade *filter,
|
||||
CvPoint *points, int *levels, int kPoints, |
||||
CvScalar color, int thickness,
|
||||
int line_type, int shift); |
||||
// INPUT
|
||||
// image - initial image
|
||||
// filter - root filter object
|
||||
// points - a set of points
|
||||
// levels - levels of feature pyramid
|
||||
// kPoints - number of points
|
||||
// color - line color for each box
|
||||
// thickness - line thickness
|
||||
// line_type - line type
|
||||
// shift - shift
|
||||
// OUTPUT
|
||||
// window contained initial image and filter boxes
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int showRootFilterBoxes(IplImage *image, |
||||
const CvLSVMFilterObjectCaskade *filter,
|
||||
CvPoint *points, int *levels, int kPoints, |
||||
CvScalar color, int thickness,
|
||||
int line_type, int shift); |
||||
|
||||
/*
|
||||
// Drawing part filter boxes
|
||||
//
|
||||
// API
|
||||
// int showPartFilterBoxes(const IplImage *image,
|
||||
const CvLSVMFilterObjectCaskade *filter,
|
||||
CvPoint *points, int *levels, int kPoints, |
||||
CvScalar color, int thickness,
|
||||
int line_type, int shift); |
||||
// INPUT
|
||||
// image - initial image
|
||||
// filters - a set of part filters
|
||||
// n - number of part filters
|
||||
// partsDisplacement - a set of points
|
||||
// levels - levels of feature pyramid
|
||||
// kPoints - number of foot filter positions
|
||||
// color - line color for each box
|
||||
// thickness - line thickness
|
||||
// line_type - line type
|
||||
// shift - shift
|
||||
// OUTPUT
|
||||
// window contained initial image and filter boxes
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int showPartFilterBoxes(IplImage *image, |
||||
const CvLSVMFilterObjectCaskade **filters, |
||||
int n, CvPoint **partsDisplacement,
|
||||
int *levels, int kPoints, |
||||
CvScalar color, int thickness,
|
||||
int line_type, int shift); |
||||
|
||||
/*
|
||||
// Drawing boxes
|
||||
//
|
||||
// API
|
||||
// int showBoxes(const IplImage *img,
|
||||
const CvPoint *points, const CvPoint *oppositePoints, int kPoints,
|
||||
CvScalar color, int thickness, int line_type, int shift); |
||||
// INPUT
|
||||
// img - initial image
|
||||
// points - top left corner coordinates
|
||||
// oppositePoints - right bottom corner coordinates
|
||||
// kPoints - points number
|
||||
// color - line color for each box
|
||||
// thickness - line thickness
|
||||
// line_type - line type
|
||||
// shift - shift
|
||||
// OUTPUT
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int showBoxes(IplImage *img,
|
||||
const CvPoint *points, const CvPoint *oppositePoints, int kPoints,
|
||||
CvScalar color, int thickness, int line_type, int shift); |
||||
} |
||||
} |
||||
#endif |
@ -0,0 +1,130 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, University of Nizhny Novgorod, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
/*****************************************************************************/ |
||||
/* Matching procedure API */ |
||||
/*****************************************************************************/ |
||||
//
|
||||
#ifndef _LSVM_MATCHING_H_ |
||||
#define _LSVM_MATCHING_H_ |
||||
|
||||
#include "_lsvmc_latentsvm.h" |
||||
#include "_lsvmc_error.h" |
||||
#include "_lsvmc_routine.h" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace lsvm |
||||
{ |
||||
|
||||
|
||||
/*
|
||||
// Computation border size for feature map
|
||||
//
|
||||
// API
|
||||
// int computeBorderSize(int maxXBorder, int maxYBorder, int *bx, int *by);
|
||||
// INPUT
|
||||
// maxXBorder - the largest root filter size (X-direction)
|
||||
// maxYBorder - the largest root filter size (Y-direction)
|
||||
// OUTPUT
|
||||
// bx - border size (X-direction)
|
||||
// by - border size (Y-direction)
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int computeBorderSize(int maxXBorder, int maxYBorder, int *bx, int *by); |
||||
|
||||
/*
|
||||
// Addition nullable border to the feature map
|
||||
//
|
||||
// API
|
||||
// int addNullableBorder(featureMap *map, int bx, int by);
|
||||
// INPUT
|
||||
// map - feature map
|
||||
// bx - border size (X-direction)
|
||||
// by - border size (Y-direction)
|
||||
// OUTPUT
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int addNullableBorder(CvLSVMFeatureMapCaskade *map, int bx, int by); |
||||
|
||||
/*
|
||||
// Perform non-maximum suppression algorithm (described in original paper)
|
||||
// to remove "similar" bounding boxes
|
||||
//
|
||||
// API
|
||||
// int nonMaximumSuppression(int numBoxes, const CvPoint *points,
|
||||
const CvPoint *oppositePoints, const float *score, |
||||
float overlapThreshold,
|
||||
int *numBoxesout, CvPoint **pointsOut,
|
||||
CvPoint **oppositePointsOut, float **scoreOut); |
||||
// INPUT
|
||||
// numBoxes - number of bounding boxes
|
||||
// points - array of left top corner coordinates
|
||||
// oppositePoints - array of right bottom corner coordinates
|
||||
// score - array of detection scores
|
||||
// overlapThreshold - threshold: bounding box is removed if overlap part
|
||||
is greater than passed value |
||||
// OUTPUT
|
||||
// numBoxesOut - the number of bounding boxes algorithm returns
|
||||
// pointsOut - array of left top corner coordinates
|
||||
// oppositePointsOut - array of right bottom corner coordinates
|
||||
// scoreOut - array of detection scores
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int nonMaximumSuppression(int numBoxes, const CvPoint *points,
|
||||
const CvPoint *oppositePoints, const float *score, |
||||
float overlapThreshold,
|
||||
int *numBoxesOut, CvPoint **pointsOut,
|
||||
CvPoint **oppositePointsOut, float **scoreOut); |
||||
int getMaxFilterDims(const CvLSVMFilterObjectCaskade **filters, int kComponents, |
||||
const int *kPartFilters,
|
||||
unsigned int *maxXBorder, unsigned int *maxYBorder); |
||||
//}
|
||||
|
||||
int getMaxFilterDims(const CvLSVMFilterObjectCaskade **filters, int kComponents, |
||||
const int *kPartFilters,
|
||||
unsigned int *maxXBorder, unsigned int *maxYBorder); |
||||
} |
||||
} |
||||
#endif |
@ -0,0 +1,128 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, University of Nizhny Novgorod, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef LSVM_PARSER |
||||
#define LSVM_PARSER |
||||
|
||||
#include "_lsvmc_types.h" |
||||
|
||||
#define MODEL 1 |
||||
#define P 2 |
||||
#define COMP 3 |
||||
#define SCORE 4 |
||||
#define RFILTER 100 |
||||
#define PFILTERs 101 |
||||
#define PFILTER 200 |
||||
#define SIZEX 150 |
||||
#define SIZEY 151 |
||||
#define WEIGHTS 152 |
||||
#define TAGV 300 |
||||
#define Vx 350 |
||||
#define Vy 351 |
||||
#define TAGD 400 |
||||
#define Dx 451 |
||||
#define Dy 452 |
||||
#define Dxx 453 |
||||
#define Dyy 454 |
||||
#define BTAG 500 |
||||
|
||||
#define PCA 5 |
||||
#define WEIGHTSPCA 162 |
||||
#define CASCADE_Th 163 |
||||
#define HYPOTHES_PCA 164 |
||||
#define DEFORM_PCA 165 |
||||
#define HYPOTHES 166 |
||||
#define DEFORM 167 |
||||
|
||||
#define PCACOEFF 6 |
||||
|
||||
#define STEP_END 1000 |
||||
|
||||
#define EMODEL (STEP_END + MODEL) |
||||
#define EP (STEP_END + P) |
||||
#define ECOMP (STEP_END + COMP) |
||||
#define ESCORE (STEP_END + SCORE) |
||||
#define ERFILTER (STEP_END + RFILTER) |
||||
#define EPFILTERs (STEP_END + PFILTERs) |
||||
#define EPFILTER (STEP_END + PFILTER) |
||||
#define ESIZEX (STEP_END + SIZEX) |
||||
#define ESIZEY (STEP_END + SIZEY) |
||||
#define EWEIGHTS (STEP_END + WEIGHTS) |
||||
#define ETAGV (STEP_END + TAGV) |
||||
#define EVx (STEP_END + Vx) |
||||
#define EVy (STEP_END + Vy) |
||||
#define ETAGD (STEP_END + TAGD) |
||||
#define EDx (STEP_END + Dx) |
||||
#define EDy (STEP_END + Dy) |
||||
#define EDxx (STEP_END + Dxx) |
||||
#define EDyy (STEP_END + Dyy) |
||||
#define EBTAG (STEP_END + BTAG) |
||||
|
||||
#define EPCA (STEP_END + PCA) |
||||
#define EWEIGHTSPCA (STEP_END + WEIGHTSPCA) |
||||
#define ECASCADE_Th (STEP_END + CASCADE_Th) |
||||
#define EHYPOTHES_PCA (STEP_END + HYPOTHES_PCA) |
||||
#define EDEFORM_PCA (STEP_END + DEFORM_PCA) |
||||
#define EHYPOTHES (STEP_END + HYPOTHES) |
||||
#define EDEFORM (STEP_END + DEFORM) |
||||
|
||||
#define EPCACOEFF (STEP_END + PCACOEFF) |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace lsvm |
||||
{ |
||||
|
||||
int loadModel( |
||||
// input parametr
|
||||
const char *modelPath,// model path
|
||||
|
||||
// output parametrs
|
||||
CvLSVMFilterObjectCaskade ***filters, |
||||
int *kFilters,
|
||||
int *kComponents,
|
||||
int **kPartFilters,
|
||||
float **b, |
||||
float *scoreThreshold, |
||||
float ** PCAcoeff); |
||||
} |
||||
} |
||||
#endif |
@ -0,0 +1,56 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, University of Nizhny Novgorod, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _LSVM_RESIZEIMG_H_ |
||||
#define _LSVM_RESIZEIMG_H_ |
||||
|
||||
#include "_lsvmc_types.h" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace lsvm |
||||
{ |
||||
|
||||
IplImage * resize_opencv (IplImage * img, float scale); |
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,76 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, University of Nizhny Novgorod, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef _LSVM_ROUTINE_H_ |
||||
#define _LSVM_ROUTINE_H_ |
||||
|
||||
#include "_lsvmc_types.h" |
||||
#include "_lsvmc_error.h" |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace lsvm |
||||
{ |
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Memory management routines
|
||||
// All paramaters names correspond to previous data structures description
|
||||
// All "alloc" functions return allocated memory for 1 object
|
||||
// with all fields including arrays
|
||||
// Error status is return value
|
||||
//////////////////////////////////////////////////////////////
|
||||
int allocFilterObject(CvLSVMFilterObjectCaskade **obj, const int sizeX, const int sizeY,
|
||||
const int p); |
||||
int freeFilterObject (CvLSVMFilterObjectCaskade **obj); |
||||
|
||||
int allocFeatureMapObject(CvLSVMFeatureMapCaskade **obj, const int sizeX, const int sizeY, |
||||
const int p); |
||||
int freeFeatureMapObject (CvLSVMFeatureMapCaskade **obj); |
||||
|
||||
int allocFeaturePyramidObject(CvLSVMFeaturePyramidCaskade **obj,
|
||||
const int countLevel); |
||||
|
||||
int freeFeaturePyramidObject (CvLSVMFeaturePyramidCaskade **obj); |
||||
|
||||
} |
||||
} |
||||
#endif |
@ -0,0 +1,186 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, University of Nizhny Novgorod, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef SVM_TYPE |
||||
#define SVM_TYPE |
||||
|
||||
#include "float.h" |
||||
|
||||
#define PI CV_PI |
||||
|
||||
#define EPS 0.000001 |
||||
|
||||
#define F_MAX FLT_MAX |
||||
#define F_MIN -FLT_MAX |
||||
|
||||
// The number of elements in bin
|
||||
// The number of sectors in gradient histogram building
|
||||
#define NUM_SECTOR 9 |
||||
|
||||
// The number of levels in image resize procedure
|
||||
// We need Lambda levels to resize image twice
|
||||
#define LAMBDA 10 |
||||
|
||||
// Block size. Used in feature pyramid building procedure
|
||||
#define SIDE_LENGTH 8 |
||||
|
||||
#define VAL_OF_TRUNCATE 0.2f |
||||
namespace cv |
||||
{ |
||||
namespace lsvm |
||||
{ |
||||
//////////////////////////////////////////////////////////////
|
||||
// main data structures //
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// data type: STRUCT CvObjectDetection
|
||||
// structure contains the bounding box and confidence level for detected object
|
||||
// rect - bounding box for a detected object
|
||||
// score - confidence level
|
||||
|
||||
typedef struct CvObjectDetection |
||||
{ |
||||
cv::Rect rect; |
||||
float score; |
||||
} CvObjectDetection; |
||||
|
||||
|
||||
// DataType: STRUCT featureMap
|
||||
// FEATURE MAP DESCRIPTION
|
||||
// Rectangular map (sizeX x sizeY),
|
||||
// every cell stores feature vector (dimension = numFeatures)
|
||||
// map - matrix of feature vectors
|
||||
// to set and get feature vectors (i,j)
|
||||
// used formula map[(j * sizeX + i) * p + k], where
|
||||
// k - component of feature vector in cell (i, j)
|
||||
typedef struct{ |
||||
int sizeX; |
||||
int sizeY; |
||||
int numFeatures; |
||||
float *map; |
||||
} CvLSVMFeatureMapCaskade; |
||||
|
||||
// DataType: STRUCT featurePyramid
|
||||
//
|
||||
// numLevels - number of levels in the feature pyramid
|
||||
// pyramid - array of pointers to feature map at different levels
|
||||
typedef struct{ |
||||
int numLevels; |
||||
CvLSVMFeatureMapCaskade **pyramid; |
||||
} CvLSVMFeaturePyramidCaskade; |
||||
|
||||
// DataType: STRUCT filterDisposition
|
||||
// The structure stores preliminary results in optimization process
|
||||
// with objective function D
|
||||
//
|
||||
// x - array with X coordinates of optimization problems solutions
|
||||
// y - array with Y coordinates of optimization problems solutions
|
||||
// score - array with optimal objective values
|
||||
typedef struct{ |
||||
float *score; |
||||
int *x; |
||||
int *y; |
||||
} CvLSVMFilterDisposition; |
||||
|
||||
// DataType: STRUCT position
|
||||
// Structure describes the position of the filter in the feature pyramid
|
||||
// l - level in the feature pyramid
|
||||
// (x, y) - coordinate in level l
|
||||
|
||||
typedef struct CvLSVMFilterPosition |
||||
{ |
||||
int x; |
||||
int y; |
||||
int l; |
||||
} CvLSVMFilterPosition; |
||||
|
||||
// DataType: STRUCT filterObject
|
||||
// Description of the filter, which corresponds to the part of the object
|
||||
// V - ideal (penalty = 0) position of the partial filter
|
||||
// from the root filter position (V_i in the paper)
|
||||
// penaltyFunction - vector describes penalty function (d_i in the paper)
|
||||
// pf[0] * x + pf[1] * y + pf[2] * x^2 + pf[3] * y^2
|
||||
// FILTER DESCRIPTION
|
||||
// Rectangular map (sizeX x sizeY),
|
||||
// every cell stores feature vector (dimension = p)
|
||||
// H - matrix of feature vectors
|
||||
// to set and get feature vectors (i,j)
|
||||
// used formula H[(j * sizeX + i) * p + k], where
|
||||
// k - component of feature vector in cell (i, j)
|
||||
// END OF FILTER DESCRIPTION
|
||||
|
||||
typedef struct CvLSVMFilterObjectCaskade{ |
||||
CvLSVMFilterPosition V; |
||||
float fineFunction[4]; |
||||
int sizeX; |
||||
int sizeY; |
||||
int numFeatures; |
||||
float *H; |
||||
float *H_PCA; |
||||
float Hypothesis, Deformation; |
||||
float Hypothesis_PCA, Deformation_PCA; |
||||
int deltaX; |
||||
int deltaY; |
||||
} CvLSVMFilterObjectCaskade; |
||||
|
||||
// data type: STRUCT CvLatentSvmDetector
|
||||
// structure contains internal representation of trained Latent SVM detector
|
||||
// num_filters - total number of filters (root plus part) in model
|
||||
// num_components - number of components in model
|
||||
// num_part_filters - array containing number of part filters for each component
|
||||
// filters - root and part filters for all model components
|
||||
// b - biases for all model components
|
||||
// score_threshold - confidence level threshold
|
||||
|
||||
typedef struct CvLatentSvmDetectorCaskade |
||||
{ |
||||
int num_filters; |
||||
int num_components; |
||||
int* num_part_filters; |
||||
CvLSVMFilterObjectCaskade** filters; |
||||
float* b; |
||||
float score_threshold; |
||||
float *pca; |
||||
int pca_size; |
||||
} CvLatentSvmDetectorCaskade; |
||||
} |
||||
} |
||||
#endif |
@ -0,0 +1,624 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, University of Nizhny Novgorod, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
#include "_lsvmc_latentsvm.h" |
||||
#include "_lsvmc_resizeimg.h" |
||||
|
||||
#ifdef HAVE_TBB |
||||
#include <tbb/tbb.h> |
||||
#include "tbb/parallel_for.h" |
||||
#include "tbb/blocked_range.h" |
||||
#endif |
||||
|
||||
#ifndef max |
||||
#define max(a,b) (((a) > (b)) ? (a) : (b)) |
||||
#endif |
||||
|
||||
#ifndef min |
||||
#define min(a,b) (((a) < (b)) ? (a) : (b)) |
||||
#endif |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace lsvm |
||||
{ |
||||
|
||||
int getPathOfFeaturePyramid(IplImage * image, |
||||
float step, int numStep, int startIndex, |
||||
int sideLength, CvLSVMFeaturePyramidCaskade **maps); |
||||
|
||||
/*
|
||||
// Getting feature map for the selected subimage
|
||||
//
|
||||
// API
|
||||
// int getFeatureMaps(const IplImage * image, const int k, featureMap **map);
|
||||
// INPUT
|
||||
// image - selected subimage
|
||||
// k - size of cells
|
||||
// OUTPUT
|
||||
// map - feature map
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int getFeatureMaps(const IplImage* image, const int k, CvLSVMFeatureMapCaskade **map) |
||||
{ |
||||
int sizeX, sizeY; |
||||
int p, px, stringSize; |
||||
int height, width, numChannels; |
||||
int i, j, kk, c, ii, jj, d; |
||||
float * datadx, * datady; |
||||
|
||||
int ch;
|
||||
float magnitude, x, y, tx, ty; |
||||
|
||||
IplImage * dx, * dy; |
||||
int *nearest; |
||||
float *w, a_x, b_x; |
||||
|
||||
float kernel[3] = {-1.f, 0.f, 1.f}; |
||||
CvMat kernel_dx = cvMat(1, 3, CV_32F, kernel); |
||||
CvMat kernel_dy = cvMat(3, 1, CV_32F, kernel); |
||||
|
||||
float * r; |
||||
int * alfa; |
||||
|
||||
float boundary_x[NUM_SECTOR + 1]; |
||||
float boundary_y[NUM_SECTOR + 1]; |
||||
float max, dotProd; |
||||
int maxi; |
||||
|
||||
height = image->height; |
||||
width = image->width ; |
||||
|
||||
numChannels = image->nChannels; |
||||
|
||||
dx = cvCreateImage(cvSize(image->width, image->height),
|
||||
IPL_DEPTH_32F, 3); |
||||
dy = cvCreateImage(cvSize(image->width, image->height),
|
||||
IPL_DEPTH_32F, 3); |
||||
|
||||
sizeX = width / k; |
||||
sizeY = height / k; |
||||
px = 3 * NUM_SECTOR;
|
||||
p = px; |
||||
stringSize = sizeX * p; |
||||
allocFeatureMapObject(map, sizeX, sizeY, p); |
||||
|
||||
cvFilter2D(image, dx, &kernel_dx, cvPoint(-1, 0)); |
||||
cvFilter2D(image, dy, &kernel_dy, cvPoint(0, -1)); |
||||
|
||||
float arg_vector; |
||||
for(i = 0; i <= NUM_SECTOR; i++) |
||||
{ |
||||
arg_vector = ( (float) i ) * ( (float)(PI) / (float)(NUM_SECTOR) ); |
||||
boundary_x[i] = cosf(arg_vector); |
||||
boundary_y[i] = sinf(arg_vector); |
||||
}/*for(i = 0; i <= NUM_SECTOR; i++) */ |
||||
|
||||
r = (float *)malloc( sizeof(float) * (width * height)); |
||||
alfa = (int *)malloc( sizeof(int ) * (width * height * 2)); |
||||
|
||||
for(j = 1; j < height - 1; j++) |
||||
{ |
||||
datadx = (float*)(dx->imageData + dx->widthStep * j); |
||||
datady = (float*)(dy->imageData + dy->widthStep * j); |
||||
for(i = 1; i < width - 1; i++) |
||||
{ |
||||
c = 0; |
||||
x = (datadx[i * numChannels + c]); |
||||
y = (datady[i * numChannels + c]); |
||||
|
||||
r[j * width + i] =sqrtf(x * x + y * y); |
||||
for(ch = 1; ch < numChannels; ch++) |
||||
{ |
||||
tx = (datadx[i * numChannels + ch]); |
||||
ty = (datady[i * numChannels + ch]); |
||||
magnitude = sqrtf(tx * tx + ty * ty); |
||||
if(magnitude > r[j * width + i]) |
||||
{ |
||||
r[j * width + i] = magnitude; |
||||
c = ch; |
||||
x = tx; |
||||
y = ty; |
||||
} |
||||
}/*for(ch = 1; ch < numChannels; ch++)*/ |
||||
|
||||
max = boundary_x[0] * x + boundary_y[0] * y; |
||||
maxi = 0; |
||||
for (kk = 0; kk < NUM_SECTOR; kk++)
|
||||
{ |
||||
dotProd = boundary_x[kk] * x + boundary_y[kk] * y; |
||||
if (dotProd > max)
|
||||
{ |
||||
max = dotProd; |
||||
maxi = kk; |
||||
} |
||||
else
|
||||
{ |
||||
if (-dotProd > max)
|
||||
{ |
||||
max = -dotProd; |
||||
maxi = kk + NUM_SECTOR; |
||||
} |
||||
} |
||||
} |
||||
alfa[j * width * 2 + i * 2 ] = maxi % NUM_SECTOR; |
||||
alfa[j * width * 2 + i * 2 + 1] = maxi;
|
||||
}/*for(i = 0; i < width; i++)*/ |
||||
}/*for(j = 0; j < height; j++)*/ |
||||
|
||||
nearest = (int *)malloc(sizeof(int ) * k); |
||||
w = (float*)malloc(sizeof(float) * (k * 2)); |
||||
|
||||
for(i = 0; i < k / 2; i++) |
||||
{ |
||||
nearest[i] = -1; |
||||
}/*for(i = 0; i < k / 2; i++)*/ |
||||
for(i = k / 2; i < k; i++) |
||||
{ |
||||
nearest[i] = 1; |
||||
}/*for(i = k / 2; i < k; i++)*/ |
||||
|
||||
for(j = 0; j < k / 2; j++) |
||||
{ |
||||
b_x = k / 2 + j + 0.5f; |
||||
a_x = k / 2 - j - 0.5f; |
||||
w[j * 2 ] = 1.0f/a_x * ((a_x * b_x) / ( a_x + b_x));
|
||||
w[j * 2 + 1] = 1.0f/b_x * ((a_x * b_x) / ( a_x + b_x));
|
||||
}/*for(j = 0; j < k / 2; j++)*/ |
||||
for(j = k / 2; j < k; j++) |
||||
{ |
||||
a_x = j - k / 2 + 0.5f; |
||||
b_x =-j + k / 2 - 0.5f + k; |
||||
w[j * 2 ] = 1.0f/a_x * ((a_x * b_x) / ( a_x + b_x));
|
||||
w[j * 2 + 1] = 1.0f/b_x * ((a_x * b_x) / ( a_x + b_x));
|
||||
}/*for(j = k / 2; j < k; j++)*/ |
||||
|
||||
for(i = 0; i < sizeY; i++) |
||||
{ |
||||
for(j = 0; j < sizeX; j++) |
||||
{ |
||||
for(ii = 0; ii < k; ii++) |
||||
{ |
||||
for(jj = 0; jj < k; jj++) |
||||
{ |
||||
if ((i * k + ii > 0) &&
|
||||
(i * k + ii < height - 1) &&
|
||||
(j * k + jj > 0) &&
|
||||
(j * k + jj < width - 1)) |
||||
{ |
||||
d = (k * i + ii) * width + (j * k + jj); |
||||
(*map)->map[ i * stringSize + j * (*map)->numFeatures + alfa[d * 2 ]] +=
|
||||
r[d] * w[ii * 2] * w[jj * 2]; |
||||
(*map)->map[ i * stringSize + j * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] +=
|
||||
r[d] * w[ii * 2] * w[jj * 2]; |
||||
if ((i + nearest[ii] >= 0) &&
|
||||
(i + nearest[ii] <= sizeY - 1)) |
||||
{ |
||||
(*map)->map[(i + nearest[ii]) * stringSize + j * (*map)->numFeatures + alfa[d * 2 ] ] +=
|
||||
r[d] * w[ii * 2 + 1] * w[jj * 2 ]; |
||||
(*map)->map[(i + nearest[ii]) * stringSize + j * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] +=
|
||||
r[d] * w[ii * 2 + 1] * w[jj * 2 ]; |
||||
} |
||||
if ((j + nearest[jj] >= 0) &&
|
||||
(j + nearest[jj] <= sizeX - 1)) |
||||
{ |
||||
(*map)->map[i * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 ] ] +=
|
||||
r[d] * w[ii * 2] * w[jj * 2 + 1]; |
||||
(*map)->map[i * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] +=
|
||||
r[d] * w[ii * 2] * w[jj * 2 + 1]; |
||||
} |
||||
if ((i + nearest[ii] >= 0) &&
|
||||
(i + nearest[ii] <= sizeY - 1) &&
|
||||
(j + nearest[jj] >= 0) &&
|
||||
(j + nearest[jj] <= sizeX - 1)) |
||||
{ |
||||
(*map)->map[(i + nearest[ii]) * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 ] ] +=
|
||||
r[d] * w[ii * 2 + 1] * w[jj * 2 + 1]; |
||||
(*map)->map[(i + nearest[ii]) * stringSize + (j + nearest[jj]) * (*map)->numFeatures + alfa[d * 2 + 1] + NUM_SECTOR] +=
|
||||
r[d] * w[ii * 2 + 1] * w[jj * 2 + 1]; |
||||
} |
||||
} |
||||
}/*for(jj = 0; jj < k; jj++)*/ |
||||
}/*for(ii = 0; ii < k; ii++)*/ |
||||
}/*for(j = 1; j < sizeX - 1; j++)*/ |
||||
}/*for(i = 1; i < sizeY - 1; i++)*/ |
||||
|
||||
cvReleaseImage(&dx); |
||||
cvReleaseImage(&dy); |
||||
|
||||
|
||||
free(w); |
||||
free(nearest); |
||||
|
||||
free(r); |
||||
free(alfa); |
||||
|
||||
return LATENT_SVM_OK; |
||||
} |
||||
|
||||
/*
|
||||
// Feature map Normalization and Truncation
|
||||
//
|
||||
// API
|
||||
// int normalizeAndTruncate(featureMap *map, const float alfa);
|
||||
// INPUT
|
||||
// map - feature map
|
||||
// alfa - truncation threshold
|
||||
// OUTPUT
|
||||
// map - truncated and normalized feature map
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int normalizeAndTruncate(CvLSVMFeatureMapCaskade *map, const float alfa) |
||||
{ |
||||
int i,j, ii; |
||||
int sizeX, sizeY, p, pos, pp, xp, pos1, pos2; |
||||
float * partOfNorm; // norm of C(i, j)
|
||||
float * newData; |
||||
float valOfNorm; |
||||
|
||||
sizeX = map->sizeX; |
||||
sizeY = map->sizeY; |
||||
partOfNorm = (float *)malloc (sizeof(float) * (sizeX * sizeY)); |
||||
|
||||
p = NUM_SECTOR; |
||||
xp = NUM_SECTOR * 3; |
||||
pp = NUM_SECTOR * 12; |
||||
|
||||
for(i = 0; i < sizeX * sizeY; i++) |
||||
{ |
||||
valOfNorm = 0.0f; |
||||
pos = i * map->numFeatures; |
||||
for(j = 0; j < p; j++) |
||||
{ |
||||
valOfNorm += map->map[pos + j] * map->map[pos + j]; |
||||
}/*for(j = 0; j < p; j++)*/ |
||||
partOfNorm[i] = valOfNorm; |
||||
}/*for(i = 0; i < sizeX * sizeY; i++)*/ |
||||
|
||||
sizeX -= 2; |
||||
sizeY -= 2; |
||||
|
||||
newData = (float *)malloc (sizeof(float) * (sizeX * sizeY * pp)); |
||||
//normalization
|
||||
for(i = 1; i <= sizeY; i++) |
||||
{ |
||||
for(j = 1; j <= sizeX; j++) |
||||
{ |
||||
valOfNorm = sqrtf( |
||||
partOfNorm[(i )*(sizeX + 2) + (j )] + |
||||
partOfNorm[(i )*(sizeX + 2) + (j + 1)] + |
||||
partOfNorm[(i + 1)*(sizeX + 2) + (j )] + |
||||
partOfNorm[(i + 1)*(sizeX + 2) + (j + 1)]) + FLT_EPSILON; |
||||
pos1 = (i ) * (sizeX + 2) * xp + (j ) * xp; |
||||
pos2 = (i-1) * (sizeX ) * pp + (j-1) * pp; |
||||
for(ii = 0; ii < p; ii++) |
||||
{ |
||||
newData[pos2 + ii ] = map->map[pos1 + ii ] / valOfNorm; |
||||
}/*for(ii = 0; ii < p; ii++)*/ |
||||
for(ii = 0; ii < 2 * p; ii++) |
||||
{ |
||||
newData[pos2 + ii + p * 4] = map->map[pos1 + ii + p] / valOfNorm; |
||||
}/*for(ii = 0; ii < 2 * p; ii++)*/ |
||||
valOfNorm = sqrtf( |
||||
partOfNorm[(i )*(sizeX + 2) + (j )] + |
||||
partOfNorm[(i )*(sizeX + 2) + (j + 1)] + |
||||
partOfNorm[(i - 1)*(sizeX + 2) + (j )] + |
||||
partOfNorm[(i - 1)*(sizeX + 2) + (j + 1)]) + FLT_EPSILON; |
||||
for(ii = 0; ii < p; ii++) |
||||
{ |
||||
newData[pos2 + ii + p ] = map->map[pos1 + ii ] / valOfNorm; |
||||
}/*for(ii = 0; ii < p; ii++)*/ |
||||
for(ii = 0; ii < 2 * p; ii++) |
||||
{ |
||||
newData[pos2 + ii + p * 6] = map->map[pos1 + ii + p] / valOfNorm; |
||||
}/*for(ii = 0; ii < 2 * p; ii++)*/ |
||||
valOfNorm = sqrtf( |
||||
partOfNorm[(i )*(sizeX + 2) + (j )] + |
||||
partOfNorm[(i )*(sizeX + 2) + (j - 1)] + |
||||
partOfNorm[(i + 1)*(sizeX + 2) + (j )] + |
||||
partOfNorm[(i + 1)*(sizeX + 2) + (j - 1)]) + FLT_EPSILON; |
||||
for(ii = 0; ii < p; ii++) |
||||
{ |
||||
newData[pos2 + ii + p * 2] = map->map[pos1 + ii ] / valOfNorm; |
||||
}/*for(ii = 0; ii < p; ii++)*/ |
||||
for(ii = 0; ii < 2 * p; ii++) |
||||
{ |
||||
newData[pos2 + ii + p * 8] = map->map[pos1 + ii + p] / valOfNorm; |
||||
}/*for(ii = 0; ii < 2 * p; ii++)*/ |
||||
valOfNorm = sqrtf( |
||||
partOfNorm[(i )*(sizeX + 2) + (j )] + |
||||
partOfNorm[(i )*(sizeX + 2) + (j - 1)] + |
||||
partOfNorm[(i - 1)*(sizeX + 2) + (j )] + |
||||
partOfNorm[(i - 1)*(sizeX + 2) + (j - 1)]) + FLT_EPSILON; |
||||
for(ii = 0; ii < p; ii++) |
||||
{ |
||||
newData[pos2 + ii + p * 3 ] = map->map[pos1 + ii ] / valOfNorm; |
||||
}/*for(ii = 0; ii < p; ii++)*/ |
||||
for(ii = 0; ii < 2 * p; ii++) |
||||
{ |
||||
newData[pos2 + ii + p * 10] = map->map[pos1 + ii + p] / valOfNorm; |
||||
}/*for(ii = 0; ii < 2 * p; ii++)*/ |
||||
}/*for(j = 1; j <= sizeX; j++)*/ |
||||
}/*for(i = 1; i <= sizeY; i++)*/ |
||||
//truncation
|
||||
for(i = 0; i < sizeX * sizeY * pp; i++) |
||||
{ |
||||
if(newData [i] > alfa) newData [i] = alfa; |
||||
}/*for(i = 0; i < sizeX * sizeY * pp; i++)*/ |
||||
//swop data
|
||||
|
||||
map->numFeatures = pp; |
||||
map->sizeX = sizeX; |
||||
map->sizeY = sizeY; |
||||
|
||||
free (map->map); |
||||
free (partOfNorm); |
||||
|
||||
map->map = newData; |
||||
|
||||
return LATENT_SVM_OK; |
||||
} |
||||
/*
|
||||
// Feature map reduction
|
||||
// In each cell we reduce dimension of the feature vector
|
||||
// according to original paper special procedure
|
||||
//
|
||||
// API
|
||||
// int PCAFeatureMaps(featureMap *map)
|
||||
// INPUT
|
||||
// map - feature map
|
||||
// OUTPUT
|
||||
// map - feature map
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int PCAFeatureMaps(CvLSVMFeatureMapCaskade *map) |
||||
{
|
||||
int i,j, ii, jj, k; |
||||
int sizeX, sizeY, p, pp, xp, yp, pos1, pos2; |
||||
float * newData; |
||||
float val; |
||||
float nx, ny; |
||||
|
||||
sizeX = map->sizeX; |
||||
sizeY = map->sizeY; |
||||
p = map->numFeatures; |
||||
pp = NUM_SECTOR * 3 + 4; |
||||
yp = 4; |
||||
xp = NUM_SECTOR; |
||||
|
||||
nx = 1.0f / sqrtf((float)(xp * 2)); |
||||
ny = 1.0f / sqrtf((float)(yp )); |
||||
|
||||
newData = (float *)malloc (sizeof(float) * (sizeX * sizeY * pp)); |
||||
|
||||
for(i = 0; i < sizeY; i++) |
||||
{ |
||||
for(j = 0; j < sizeX; j++) |
||||
{ |
||||
pos1 = ((i)*sizeX + j)*p; |
||||
pos2 = ((i)*sizeX + j)*pp; |
||||
k = 0; |
||||
for(jj = 0; jj < xp * 2; jj++) |
||||
{ |
||||
val = 0; |
||||
for(ii = 0; ii < yp; ii++) |
||||
{ |
||||
val += map->map[pos1 + yp * xp + ii * xp * 2 + jj]; |
||||
}/*for(ii = 0; ii < yp; ii++)*/ |
||||
newData[pos2 + k] = val * ny; |
||||
k++; |
||||
}/*for(jj = 0; jj < xp * 2; jj++)*/ |
||||
for(jj = 0; jj < xp; jj++) |
||||
{ |
||||
val = 0; |
||||
for(ii = 0; ii < yp; ii++) |
||||
{ |
||||
val += map->map[pos1 + ii * xp + jj]; |
||||
}/*for(ii = 0; ii < yp; ii++)*/ |
||||
newData[pos2 + k] = val * ny; |
||||
k++; |
||||
}/*for(jj = 0; jj < xp; jj++)*/ |
||||
for(ii = 0; ii < yp; ii++) |
||||
{ |
||||
val = 0; |
||||
for(jj = 0; jj < 2 * xp; jj++) |
||||
{ |
||||
val += map->map[pos1 + yp * xp + ii * xp * 2 + jj]; |
||||
}/*for(jj = 0; jj < xp; jj++)*/ |
||||
newData[pos2 + k] = val * nx; |
||||
k++; |
||||
} /*for(ii = 0; ii < yp; ii++)*/
|
||||
}/*for(j = 0; j < sizeX; j++)*/ |
||||
}/*for(i = 0; i < sizeY; i++)*/ |
||||
//swop data
|
||||
|
||||
map->numFeatures = pp; |
||||
|
||||
free (map->map); |
||||
|
||||
map->map = newData; |
||||
|
||||
return LATENT_SVM_OK; |
||||
} |
||||
|
||||
int getPathOfFeaturePyramid(IplImage * image,
|
||||
float step, int numStep, int startIndex, |
||||
int sideLength, CvLSVMFeaturePyramidCaskade **maps) |
||||
{ |
||||
CvLSVMFeatureMapCaskade *map; |
||||
IplImage *scaleTmp; |
||||
float scale; |
||||
int i; |
||||
|
||||
for(i = 0; i < numStep; i++) |
||||
{ |
||||
scale = 1.0f / powf(step, (float)i); |
||||
scaleTmp = resize_opencv (image, scale); |
||||
getFeatureMaps(scaleTmp, sideLength, &map); |
||||
normalizeAndTruncate(map, VAL_OF_TRUNCATE); |
||||
PCAFeatureMaps(map); |
||||
(*maps)->pyramid[startIndex + i] = map; |
||||
cvReleaseImage(&scaleTmp); |
||||
}/*for(i = 0; i < numStep; i++)*/ |
||||
return LATENT_SVM_OK; |
||||
} |
||||
|
||||
#ifdef HAVE_TBB |
||||
|
||||
class PathOfFeaturePyramid : public ParallelLoopBody{ |
||||
public: |
||||
IplImage * image; |
||||
float step; |
||||
int startIndex; |
||||
int sideLength; |
||||
CvLSVMFeaturePyramidCaskade **maps; |
||||
|
||||
void operator() (const Range& range) const |
||||
{ |
||||
CvLSVMFeatureMapCaskade *map; |
||||
IplImage *scaleTmp; |
||||
float scale; |
||||
int err; |
||||
|
||||
for( int i=range.start; i!=range.end; ++i ) |
||||
{ |
||||
scale = 1.0f / powf(step, (float)i); |
||||
scaleTmp = resize_opencv (image, scale); |
||||
err = getFeatureMaps(scaleTmp, sideLength, &map); |
||||
err = normalizeAndTruncate(map, VAL_OF_TRUNCATE); |
||||
err = PCAFeatureMaps(map); |
||||
(*maps)->pyramid[startIndex + i] = map; |
||||
cvReleaseImage(&scaleTmp); |
||||
} |
||||
} |
||||
}; |
||||
|
||||
|
||||
int getPathOfFeaturePyramid_TBB(IplImage * image,
|
||||
float step, int numStep, int startIndex, |
||||
int sideLength, CvLSVMFeaturePyramidCaskade **maps) |
||||
{ |
||||
PathOfFeaturePyramid str; |
||||
str.step = step; |
||||
str.startIndex = startIndex; |
||||
str.sideLength = sideLength; |
||||
str.maps = maps; |
||||
str.image = image; |
||||
|
||||
cv::parallel_for_(Range( 0, numStep ), str ); |
||||
|
||||
return LATENT_SVM_OK; |
||||
} |
||||
#endif |
||||
|
||||
/*
|
||||
// Getting feature pyramid
|
||||
//
|
||||
// API
|
||||
// int getFeaturePyramid(IplImage * image, const CvLSVMFilterObjectCaskade **all_F,
|
||||
const int n_f, |
||||
const int lambda, const int k,
|
||||
const int startX, const int startY,
|
||||
const int W, const int H, featurePyramid **maps); |
||||
// INPUT
|
||||
// image - image
|
||||
// OUTPUT
|
||||
// maps - feature maps for all levels
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int getFeaturePyramid(IplImage * image, CvLSVMFeaturePyramidCaskade **maps) |
||||
{ |
||||
IplImage *imgResize; |
||||
float step; |
||||
int numStep; |
||||
int maxNumCells; |
||||
int W, H; |
||||
|
||||
if(image->depth == IPL_DEPTH_32F) |
||||
{ |
||||
imgResize = image; |
||||
} |
||||
else |
||||
{ |
||||
imgResize = cvCreateImage(cvSize(image->width , image->height) , |
||||
IPL_DEPTH_32F , 3); |
||||
cvConvert(image, imgResize);
|
||||
} |
||||
|
||||
W = imgResize->width; |
||||
H = imgResize->height; |
||||
|
||||
step = powf(2.0f, 1.0f / ((float)LAMBDA)); |
||||
maxNumCells = W / SIDE_LENGTH; |
||||
if( maxNumCells > H / SIDE_LENGTH ) |
||||
{ |
||||
maxNumCells = H / SIDE_LENGTH; |
||||
} |
||||
numStep = (int)(logf((float) maxNumCells / (5.0f)) / logf( step )) + 1; |
||||
|
||||
allocFeaturePyramidObject(maps, numStep + LAMBDA); |
||||
|
||||
#ifdef HAVE_TBB |
||||
getPathOfFeaturePyramid_TBB(imgResize, step , LAMBDA, 0,
|
||||
SIDE_LENGTH / 2, maps); |
||||
getPathOfFeaturePyramid_TBB(imgResize, step, numStep, LAMBDA,
|
||||
SIDE_LENGTH , maps); |
||||
#else |
||||
getPathOfFeaturePyramid(imgResize, step , LAMBDA, 0,
|
||||
SIDE_LENGTH / 2, maps); |
||||
getPathOfFeaturePyramid(imgResize, step, numStep, LAMBDA,
|
||||
SIDE_LENGTH , maps); |
||||
#endif |
||||
|
||||
if(image->depth != IPL_DEPTH_32F) |
||||
{ |
||||
cvReleaseImage(&imgResize); |
||||
} |
||||
|
||||
return LATENT_SVM_OK; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,127 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, University of Nizhny Novgorod, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
#include "_lsvmc_function.h" |
||||
namespace cv |
||||
{ |
||||
namespace lsvm |
||||
{ |
||||
|
||||
float calcM (int k,int di,int dj, const CvLSVMFeaturePyramidCaskade * H, const CvLSVMFilterObjectCaskade *filter){ |
||||
int i, j; |
||||
float m = 0.0f; |
||||
for(j = dj; j < dj + filter->sizeY; j++){ |
||||
for(i = di * H->pyramid[k]->numFeatures; i < (di + filter->sizeX) * H->pyramid[k]->numFeatures; i++){ |
||||
m += H->pyramid[k]->map[(j * H->pyramid[k]->sizeX ) * H->pyramid[k]->numFeatures + i] *
|
||||
filter ->H [((j - dj) * filter->sizeX - di) * H->pyramid[k]->numFeatures + i];
|
||||
} |
||||
} |
||||
return m; |
||||
} |
||||
float calcM_PCA(int k,int di,int dj, const CvLSVMFeaturePyramidCaskade * H, const CvLSVMFilterObjectCaskade *filter){ |
||||
int i, j; |
||||
float m = 0.0f; |
||||
for(j = dj; j < dj + filter->sizeY; j++){ |
||||
for(i = di * H->pyramid[k]->numFeatures; i < (di + filter->sizeX) * H->pyramid[k]->numFeatures; i++){ |
||||
m += H->pyramid[k]->map[(j * H->pyramid[k]->sizeX ) * H->pyramid[k]->numFeatures + i] *
|
||||
filter ->H_PCA [((j - dj) * filter->sizeX - di) * H->pyramid[k]->numFeatures + i]; |
||||
} |
||||
} |
||||
|
||||
return m; |
||||
} |
||||
float calcM_PCA_cash(int k,int di,int dj, const CvLSVMFeaturePyramidCaskade * H, const CvLSVMFilterObjectCaskade *filter, float * cashM, int * maskM, int step){ |
||||
int i, j, n; |
||||
float m = 0.0f; |
||||
float tmp1, tmp2, tmp3, tmp4; |
||||
float res; |
||||
int pos; |
||||
float *a, *b; |
||||
|
||||
pos = dj * step + di; |
||||
|
||||
if(!((maskM[pos / (sizeof(int) * 8)]) & (1 << pos % (sizeof(int) * 8)))) |
||||
{ |
||||
for(j = dj; j < dj + filter->sizeY; j++) |
||||
{ |
||||
a = H->pyramid[k]->map + (j * H->pyramid[k]->sizeX) * H->pyramid[k]->numFeatures |
||||
+ di * H->pyramid[k]->numFeatures; |
||||
b = filter ->H_PCA + (j - dj) * filter->sizeX * H->pyramid[k]->numFeatures; |
||||
n = ((di + filter->sizeX) * H->pyramid[k]->numFeatures) -
|
||||
(di * H->pyramid[k]->numFeatures); |
||||
|
||||
res = 0.0f; |
||||
tmp1 = 0.0f; tmp2 = 0.0f; tmp3 = 0.0f; tmp4 = 0.0f; |
||||
|
||||
for (i = 0; i < (n >> 2); ++i) |
||||
{ |
||||
tmp1 += a[4 * i + 0] * b[4 * i + 0]; |
||||
tmp2 += a[4 * i + 1] * b[4 * i + 1]; |
||||
tmp3 += a[4 * i + 2] * b[4 * i + 2]; |
||||
tmp4 += a[4 * i + 3] * b[4 * i + 3]; |
||||
} |
||||
|
||||
for (i = (n >> 2) << 2; i < n; ++i) //?
|
||||
{ |
||||
res += a[i] * b[i]; |
||||
} |
||||
|
||||
res += tmp1 + tmp2 + tmp3 + tmp4; |
||||
|
||||
m += res; |
||||
} |
||||
|
||||
cashM[pos ] = m; |
||||
maskM[pos / (sizeof(int) * 8)] |= 1 << pos % (sizeof(int) * 8); |
||||
} |
||||
else |
||||
{ |
||||
m = cashM[pos]; |
||||
} |
||||
return m; |
||||
} |
||||
float calcFine (const CvLSVMFilterObjectCaskade *filter, int di, int dj){ |
||||
return filter->fineFunction[0] * di + filter->fineFunction[1] * dj +
|
||||
filter->fineFunction[2] * di * di + filter->fineFunction[3] * dj * dj; |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,331 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, University of Nizhny Novgorod, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
#include "_lsvmc_parser.h" |
||||
#include "_lsvmc_matching.h" |
||||
namespace cv |
||||
{ |
||||
namespace lsvm |
||||
{ |
||||
|
||||
std::string extractModelName( const std::string& filename ); |
||||
|
||||
const int pca_size = 31; |
||||
|
||||
CvLatentSvmDetectorCaskade* cvLoadLatentSvmDetectorCaskade(const char* filename); |
||||
void cvReleaseLatentSvmDetectorCaskade(CvLatentSvmDetectorCaskade** detector); |
||||
CvSeq* cvLatentSvmDetectObjectsCaskade(IplImage* image, |
||||
CvLatentSvmDetectorCaskade* detector, |
||||
CvMemStorage* storage, |
||||
float overlap_threshold); |
||||
|
||||
/*
|
||||
// load trained detector from a file
|
||||
//
|
||||
// API
|
||||
// CvLatentSvmDetectorCaskade* cvLoadLatentSvmDetector(const char* filename);
|
||||
// INPUT
|
||||
// filename - path to the file containing the parameters of
|
||||
// - trained Latent SVM detector
|
||||
// OUTPUT
|
||||
// trained Latent SVM detector in internal representation
|
||||
*/ |
||||
CvLatentSvmDetectorCaskade* cvLoadLatentSvmDetectorCaskade(const char* filename) |
||||
{ |
||||
CvLatentSvmDetectorCaskade* detector = 0; |
||||
CvLSVMFilterObjectCaskade** filters = 0; |
||||
int kFilters = 0; |
||||
int kComponents = 0; |
||||
int* kPartFilters = 0; |
||||
float* b = 0; |
||||
float scoreThreshold = 0.f; |
||||
int err_code = 0; |
||||
float* PCAcoeff = 0; |
||||
|
||||
err_code = loadModel(filename, &filters, &kFilters, &kComponents, &kPartFilters, &b, &scoreThreshold, &PCAcoeff); |
||||
if (err_code != LATENT_SVM_OK) return 0; |
||||
|
||||
detector = (CvLatentSvmDetectorCaskade*)malloc(sizeof(CvLatentSvmDetectorCaskade)); |
||||
detector->filters = filters; |
||||
detector->b = b; |
||||
detector->num_components = kComponents; |
||||
detector->num_filters = kFilters; |
||||
detector->num_part_filters = kPartFilters; |
||||
detector->score_threshold = scoreThreshold; |
||||
detector->pca = PCAcoeff; |
||||
detector->pca_size = pca_size; |
||||
|
||||
return detector; |
||||
} |
||||
|
||||
/*
|
||||
// release memory allocated for CvLatentSvmDetectorCaskade structure
|
||||
//
|
||||
// API
|
||||
// void cvReleaseLatentSvmDetector(CvLatentSvmDetectorCaskade** detector);
|
||||
// INPUT
|
||||
// detector - CvLatentSvmDetectorCaskade structure to be released
|
||||
// OUTPUT
|
||||
*/ |
||||
void cvReleaseLatentSvmDetectorCaskade(CvLatentSvmDetectorCaskade** detector) |
||||
{ |
||||
free((*detector)->b); |
||||
free((*detector)->num_part_filters); |
||||
for (int i = 0; i < (*detector)->num_filters; i++) |
||||
{ |
||||
free((*detector)->filters[i]->H); |
||||
free((*detector)->filters[i]); |
||||
} |
||||
free((*detector)->filters); |
||||
free((*detector)->pca); |
||||
free((*detector)); |
||||
*detector = 0; |
||||
} |
||||
|
||||
/*
|
||||
// find rectangular regions in the given image that are likely
|
||||
// to contain objects and corresponding confidence levels
|
||||
//
|
||||
// API
|
||||
// CvSeq* cvLatentSvmDetectObjects(const IplImage* image,
|
||||
// CvLatentSvmDetectorCaskade* detector,
|
||||
// CvMemStorage* storage,
|
||||
// float overlap_threshold = 0.5f);
|
||||
// INPUT
|
||||
// image - image to detect objects in
|
||||
// detector - Latent SVM detector in internal representation
|
||||
// storage - memory storage to store the resultant sequence
|
||||
// of the object candidate rectangles
|
||||
// overlap_threshold - threshold for the non-maximum suppression algorithm [here will be the reference to original paper]
|
||||
// OUTPUT
|
||||
// sequence of detected objects (bounding boxes and confidence levels stored in CvObjectDetection structures)
|
||||
*/ |
||||
CvSeq* cvLatentSvmDetectObjectsCaskade(IplImage* image, |
||||
CvLatentSvmDetectorCaskade* detector, |
||||
CvMemStorage* storage, |
||||
float overlap_threshold) |
||||
{ |
||||
CvLSVMFeaturePyramidCaskade *H = 0; |
||||
CvLSVMFeaturePyramidCaskade *H_PCA = 0; |
||||
CvPoint *points = 0, *oppPoints = 0; |
||||
int kPoints = 0; |
||||
float *score = 0; |
||||
unsigned int maxXBorder = 0, maxYBorder = 0; |
||||
int numBoxesOut = 0; |
||||
CvPoint *pointsOut = 0; |
||||
CvPoint *oppPointsOut = 0; |
||||
float *scoreOut = 0; |
||||
CvSeq* result_seq = 0; |
||||
int error = 0; |
||||
|
||||
if(image->nChannels == 3) |
||||
cvCvtColor(image, image, CV_BGR2RGB); |
||||
|
||||
// Getting maximum filter dimensions
|
||||
getMaxFilterDims((const CvLSVMFilterObjectCaskade**)(detector->filters), detector->num_components, |
||||
detector->num_part_filters, &maxXBorder, &maxYBorder); |
||||
// Create feature pyramid with nullable border
|
||||
H = createFeaturePyramidWithBorder(image, maxXBorder, maxYBorder); |
||||
|
||||
// Create PSA feature pyramid
|
||||
H_PCA = createPCA_FeaturePyramid(H, detector, maxXBorder, maxYBorder); |
||||
|
||||
FeaturePyramid32(H, maxXBorder, maxYBorder); |
||||
|
||||
// Search object
|
||||
error = searchObjectThresholdSomeComponents(H, H_PCA,(const CvLSVMFilterObjectCaskade**)(detector->filters), |
||||
detector->num_components, detector->num_part_filters, detector->b, detector->score_threshold, |
||||
&points, &oppPoints, &score, &kPoints); |
||||
if (error != LATENT_SVM_OK) |
||||
{ |
||||
return NULL; |
||||
} |
||||
// Clipping boxes
|
||||
clippingBoxes(image->width, image->height, points, kPoints); |
||||
clippingBoxes(image->width, image->height, oppPoints, kPoints); |
||||
// NMS procedure
|
||||
nonMaximumSuppression(kPoints, points, oppPoints, score, overlap_threshold, |
||||
&numBoxesOut, &pointsOut, &oppPointsOut, &scoreOut); |
||||
|
||||
result_seq = cvCreateSeq( 0, sizeof(CvSeq), sizeof(CvObjectDetection), storage ); |
||||
|
||||
for (int i = 0; i < numBoxesOut; i++) |
||||
{ |
||||
CvObjectDetection detection; |
||||
detection.score = scoreOut[i]; |
||||
detection.rect.x = pointsOut[i].x; |
||||
detection.rect.y = pointsOut[i].y; |
||||
detection.rect.width = oppPointsOut[i].x - pointsOut[i].x; |
||||
detection.rect.height = oppPointsOut[i].y - pointsOut[i].y; |
||||
cvSeqPush(result_seq, &detection); |
||||
} |
||||
|
||||
if(image->nChannels == 3) |
||||
cvCvtColor(image, image, CV_RGB2BGR); |
||||
|
||||
freeFeaturePyramidObject(&H); |
||||
freeFeaturePyramidObject(&H_PCA); |
||||
free(points); |
||||
free(oppPoints); |
||||
free(score); |
||||
|
||||
return result_seq; |
||||
} |
||||
|
||||
class LSVMDetectorImpl : public LSVMDetector |
||||
{ |
||||
public: |
||||
|
||||
LSVMDetectorImpl( const std::vector<std::string>& filenames, const std::vector<std::string>& classNames=std::vector<std::string>() ); |
||||
~LSVMDetectorImpl(); |
||||
|
||||
bool isEmpty() const; |
||||
|
||||
void detect(cv::Mat const &image, CV_OUT std::vector<ObjectDetection>& objects, float overlapThreshold=0.5f); |
||||
|
||||
const std::vector<std::string>& getClassNames() const; |
||||
size_t getClassCount() const; |
||||
|
||||
private: |
||||
std::vector<CvLatentSvmDetectorCaskade*> detectors; |
||||
std::vector<std::string> classNames; |
||||
}; |
||||
|
||||
cv::Ptr<LSVMDetector> LSVMDetector::create(std::vector<std::string> const &filenames, |
||||
std::vector<std::string> const &classNames) |
||||
{ |
||||
return cv::makePtr<LSVMDetectorImpl>(filenames, classNames); |
||||
} |
||||
|
||||
LSVMDetectorImpl::ObjectDetection::ObjectDetection() : score(0.f), classID(-1) {} |
||||
|
||||
LSVMDetectorImpl::ObjectDetection::ObjectDetection( const Rect& _rect, float _score, int _classID ) : |
||||
rect(_rect), score(_score), classID(_classID) {} |
||||
|
||||
|
||||
LSVMDetectorImpl::LSVMDetectorImpl( const std::vector<std::string>& filenames, const std::vector<std::string>& _classNames ) |
||||
{ |
||||
for( size_t i = 0; i < filenames.size(); i++ ) |
||||
{ |
||||
const std::string filename = filenames[i]; |
||||
if( filename.length() < 5 || filename.substr(filename.length()-4, 4) != ".xml" ) |
||||
continue; |
||||
|
||||
CvLatentSvmDetectorCaskade* detector = cvLoadLatentSvmDetectorCaskade( filename.c_str() ); |
||||
if( detector ) |
||||
{ |
||||
detectors.push_back( detector ); |
||||
if( _classNames.empty() ) |
||||
{ |
||||
classNames.push_back( extractModelName(filenames[i]) ); |
||||
} |
||||
else |
||||
classNames.push_back( _classNames[i] ); |
||||
} |
||||
} |
||||
} |
||||
|
||||
LSVMDetectorImpl::~LSVMDetectorImpl() |
||||
{ |
||||
for(size_t i = 0; i < detectors.size(); i++) |
||||
cv::lsvm::cvReleaseLatentSvmDetectorCaskade(&detectors[i]); |
||||
} |
||||
|
||||
bool LSVMDetectorImpl::isEmpty() const |
||||
{ |
||||
return detectors.empty(); |
||||
} |
||||
|
||||
const std::vector<std::string>& LSVMDetectorImpl::getClassNames() const |
||||
{ |
||||
return classNames; |
||||
} |
||||
|
||||
size_t LSVMDetectorImpl::getClassCount() const |
||||
{ |
||||
return classNames.size(); |
||||
} |
||||
|
||||
std::string extractModelName( const std::string& filename ) |
||||
{ |
||||
size_t startPos = filename.rfind('/'); |
||||
if( startPos == std::string::npos ) |
||||
startPos = filename.rfind('\\'); |
||||
|
||||
if( startPos == std::string::npos ) |
||||
startPos = 0; |
||||
else |
||||
startPos++; |
||||
|
||||
const int extentionSize = 4; //.xml
|
||||
|
||||
int substrLength = (int)(filename.size() - startPos - extentionSize); |
||||
|
||||
return filename.substr(startPos, substrLength); |
||||
} |
||||
|
||||
void LSVMDetectorImpl::detect( cv::Mat const &image, |
||||
std::vector<ObjectDetection> &objectDetections, |
||||
float overlapThreshold) |
||||
{ |
||||
objectDetections.clear(); |
||||
|
||||
for( size_t classID = 0; classID < detectors.size(); classID++ ) |
||||
{ |
||||
IplImage image_ipl = image; |
||||
CvMemStorage* storage = cvCreateMemStorage(0); |
||||
CvSeq* detections = cv::lsvm::cvLatentSvmDetectObjectsCaskade( &image_ipl, (CvLatentSvmDetectorCaskade*)(detectors[classID]), storage, overlapThreshold); |
||||
|
||||
// convert results
|
||||
objectDetections.reserve( objectDetections.size() + detections->total ); |
||||
for( int detectionIdx = 0; detectionIdx < detections->total; detectionIdx++ ) |
||||
{ |
||||
CvObjectDetection detection = *(CvObjectDetection*)cvGetSeqElem( detections, detectionIdx ); |
||||
objectDetections.push_back( ObjectDetection(Rect(detection.rect), detection.score, (int)classID) ); |
||||
} |
||||
|
||||
cvReleaseMemStorage( &storage ); |
||||
} |
||||
} |
||||
|
||||
} // namespace cv
|
||||
} |
@ -0,0 +1,285 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, University of Nizhny Novgorod, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
#include "_lsvmc_matching.h" |
||||
#include <stdio.h> |
||||
|
||||
#ifndef max |
||||
#define max(a,b) (((a) > (b)) ? (a) : (b)) |
||||
#endif |
||||
|
||||
#ifndef min |
||||
#define min(a,b) (((a) < (b)) ? (a) : (b)) |
||||
#endif |
||||
namespace cv |
||||
{ |
||||
namespace lsvm |
||||
{ |
||||
|
||||
void sort(int n, const float* x, int* indices); |
||||
|
||||
/*
|
||||
// Computation border size for feature map
|
||||
//
|
||||
// API
|
||||
// int computeBorderSize(int maxXBorder, int maxYBorder, int *bx, int *by);
|
||||
// INPUT
|
||||
// maxXBorder - the largest root filter size (X-direction)
|
||||
// maxYBorder - the largest root filter size (Y-direction)
|
||||
// OUTPUT
|
||||
// bx - border size (X-direction)
|
||||
// by - border size (Y-direction)
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int computeBorderSize(int maxXBorder, int maxYBorder, int *bx, int *by) |
||||
{ |
||||
*bx = (int)ceilf(((float) maxXBorder) / 2.0f + 1.0f); |
||||
*by = (int)ceilf(((float) maxYBorder) / 2.0f + 1.0f); |
||||
return LATENT_SVM_OK; |
||||
} |
||||
|
||||
/*
|
||||
// Addition nullable border to the feature map
|
||||
//
|
||||
// API
|
||||
// int addNullableBorder(featureMap *map, int bx, int by);
|
||||
// INPUT
|
||||
// map - feature map
|
||||
// bx - border size (X-direction)
|
||||
// by - border size (Y-direction)
|
||||
// OUTPUT
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int addNullableBorder(CvLSVMFeatureMapCaskade *map, int bx, int by) |
||||
{ |
||||
int sizeX, sizeY, i, j, k; |
||||
float *new_map; |
||||
sizeX = map->sizeX + 2 * bx; |
||||
sizeY = map->sizeY + 2 * by; |
||||
new_map = (float *)malloc(sizeof(float) * sizeX * sizeY * map->numFeatures); |
||||
for (i = 0; i < sizeX * sizeY * map->numFeatures; i++) |
||||
{ |
||||
new_map[i] = 0.0; |
||||
} |
||||
for (i = by; i < map->sizeY + by; i++) |
||||
{ |
||||
for (j = bx; j < map->sizeX + bx; j++) |
||||
{ |
||||
for (k = 0; k < map->numFeatures; k++) |
||||
{ |
||||
new_map[(i * sizeX + j) * map->numFeatures + k] = |
||||
map->map[((i - by) * map->sizeX + j - bx) * map->numFeatures + k]; |
||||
} |
||||
} |
||||
} |
||||
map->sizeX = sizeX; |
||||
map->sizeY = sizeY; |
||||
free(map->map); |
||||
map->map = new_map; |
||||
return LATENT_SVM_OK; |
||||
} |
||||
|
||||
/*
|
||||
// Computation maximum filter size for each dimension
|
||||
//
|
||||
// API
|
||||
// int getMaxFilterDims(const CvLSVMFilterObjectCaskade **filters, int kComponents,
|
||||
const int *kPartFilters,
|
||||
unsigned int *maxXBorder, unsigned int *maxYBorder); |
||||
// INPUT
|
||||
// filters - a set of filters (at first root filter, then part filters
|
||||
and etc. for all components) |
||||
// kComponents - number of components
|
||||
// kPartFilters - number of part filters for each component
|
||||
// OUTPUT
|
||||
// maxXBorder - maximum of filter size at the horizontal dimension
|
||||
// maxYBorder - maximum of filter size at the vertical dimension
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int getMaxFilterDims(const CvLSVMFilterObjectCaskade **filters, int kComponents, |
||||
const int *kPartFilters,
|
||||
unsigned int *maxXBorder, unsigned int *maxYBorder) |
||||
{ |
||||
int i, componentIndex;
|
||||
*maxXBorder = filters[0]->sizeX; |
||||
*maxYBorder = filters[0]->sizeY; |
||||
componentIndex = kPartFilters[0] + 1; |
||||
for (i = 1; i < kComponents; i++) |
||||
{ |
||||
if (unsigned(filters[componentIndex]->sizeX) > *maxXBorder) |
||||
{ |
||||
*maxXBorder = filters[componentIndex]->sizeX; |
||||
} |
||||
if (unsigned(filters[componentIndex]->sizeY) > *maxYBorder) |
||||
{ |
||||
*maxYBorder = filters[componentIndex]->sizeY; |
||||
} |
||||
componentIndex += (kPartFilters[i] + 1); |
||||
} |
||||
return LATENT_SVM_OK; |
||||
} |
||||
|
||||
void sort(int n, const float* x, int* indices) |
||||
{ |
||||
int i, j; |
||||
for (i = 0; i < n; i++) |
||||
for (j = i + 1; j < n; j++) |
||||
{ |
||||
if (x[indices[j]] > x[indices[i]]) |
||||
{ |
||||
//float x_tmp = x[i];
|
||||
int index_tmp = indices[i]; |
||||
//x[i] = x[j];
|
||||
indices[i] = indices[j]; |
||||
//x[j] = x_tmp;
|
||||
indices[j] = index_tmp; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/*
|
||||
// Perform non-maximum suppression algorithm (described in original paper)
|
||||
// to remove "similar" bounding boxes
|
||||
//
|
||||
// API
|
||||
// int nonMaximumSuppression(int numBoxes, const CvPoint *points,
|
||||
const CvPoint *oppositePoints, const float *score, |
||||
float overlapThreshold, |
||||
int *numBoxesOut, CvPoint **pointsOut, |
||||
CvPoint **oppositePointsOut, float **scoreOut); |
||||
// INPUT
|
||||
// numBoxes - number of bounding boxes
|
||||
// points - array of left top corner coordinates
|
||||
// oppositePoints - array of right bottom corner coordinates
|
||||
// score - array of detection scores
|
||||
// overlapThreshold - threshold: bounding box is removed if overlap part
|
||||
is greater than passed value |
||||
// OUTPUT
|
||||
// numBoxesOut - the number of bounding boxes algorithm returns
|
||||
// pointsOut - array of left top corner coordinates
|
||||
// oppositePointsOut - array of right bottom corner coordinates
|
||||
// scoreOut - array of detection scores
|
||||
// RESULT
|
||||
// Error status
|
||||
*/ |
||||
int nonMaximumSuppression(int numBoxes, const CvPoint *points, |
||||
const CvPoint *oppositePoints, const float *score, |
||||
float overlapThreshold, |
||||
int *numBoxesOut, CvPoint **pointsOut, |
||||
CvPoint **oppositePointsOut, float **scoreOut) |
||||
{ |
||||
int i, j, index; |
||||
float* box_area = (float*)malloc(numBoxes * sizeof(float)); |
||||
int* indices = (int*)malloc(numBoxes * sizeof(int)); |
||||
int* is_suppressed = (int*)malloc(numBoxes * sizeof(int)); |
||||
|
||||
for (i = 0; i < numBoxes; i++) |
||||
{ |
||||
indices[i] = i; |
||||
is_suppressed[i] = 0; |
||||
box_area[i] = (float)( (oppositePoints[i].x - points[i].x + 1) * |
||||
(oppositePoints[i].y - points[i].y + 1)); |
||||
} |
||||
|
||||
sort(numBoxes, score, indices); |
||||
for (i = 0; i < numBoxes; i++) |
||||
{ |
||||
if (!is_suppressed[indices[i]]) |
||||
{ |
||||
for (j = i + 1; j < numBoxes; j++) |
||||
{ |
||||
if (!is_suppressed[indices[j]]) |
||||
{ |
||||
int x1max = max(points[indices[i]].x, points[indices[j]].x); |
||||
int x2min = min(oppositePoints[indices[i]].x, oppositePoints[indices[j]].x); |
||||
int y1max = max(points[indices[i]].y, points[indices[j]].y); |
||||
int y2min = min(oppositePoints[indices[i]].y, oppositePoints[indices[j]].y); |
||||
int overlapWidth = x2min - x1max + 1; |
||||
int overlapHeight = y2min - y1max + 1; |
||||
if (overlapWidth > 0 && overlapHeight > 0) |
||||
{ |
||||
float overlapPart = (overlapWidth * overlapHeight) / box_area[indices[j]]; |
||||
if (overlapPart > overlapThreshold) |
||||
{ |
||||
is_suppressed[indices[j]] = 1; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
*numBoxesOut = 0; |
||||
for (i = 0; i < numBoxes; i++) |
||||
{ |
||||
if (!is_suppressed[i]) (*numBoxesOut)++; |
||||
} |
||||
|
||||
*pointsOut = (CvPoint *)malloc((*numBoxesOut) * sizeof(CvPoint)); |
||||
*oppositePointsOut = (CvPoint *)malloc((*numBoxesOut) * sizeof(CvPoint)); |
||||
*scoreOut = (float *)malloc((*numBoxesOut) * sizeof(float)); |
||||
index = 0; |
||||
for (i = 0; i < numBoxes; i++) |
||||
{ |
||||
if (!is_suppressed[indices[i]]) |
||||
{ |
||||
(*pointsOut)[index].x = points[indices[i]].x; |
||||
(*pointsOut)[index].y = points[indices[i]].y; |
||||
(*oppositePointsOut)[index].x = oppositePoints[indices[i]].x; |
||||
(*oppositePointsOut)[index].y = oppositePoints[indices[i]].y; |
||||
(*scoreOut)[index] = score[indices[i]]; |
||||
index++; |
||||
} |
||||
|
||||
} |
||||
|
||||
free(indices); |
||||
free(box_area); |
||||
free(is_suppressed); |
||||
|
||||
return LATENT_SVM_OK; |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,71 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, University of Nizhny Novgorod, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
#include "_lsvmc_resizeimg.h" |
||||
#include <stdio.h> |
||||
#include <assert.h> |
||||
#include <math.h> |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace lsvm |
||||
{ |
||||
|
||||
IplImage* resize_opencv(IplImage* img, float scale) |
||||
{ |
||||
IplImage* imgTmp; |
||||
|
||||
int W, H, tW, tH; |
||||
|
||||
W = img->width; |
||||
H = img->height; |
||||
|
||||
tW = (int)(((float)W) * scale + 0.5); |
||||
tH = (int)(((float)H) * scale + 0.5); |
||||
|
||||
imgTmp = cvCreateImage(cvSize(tW , tH), img->depth, img->nChannels); |
||||
cvResize(img, imgTmp, CV_INTER_AREA); |
||||
|
||||
return imgTmp; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,129 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, University of Nizhny Novgorod, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
#include "_lsvmc_routine.h" |
||||
namespace cv |
||||
{ |
||||
namespace lsvm |
||||
{ |
||||
int allocFilterObject(CvLSVMFilterObjectCaskade **obj, const int sizeX, |
||||
const int sizeY, const int numFeatures)
|
||||
{ |
||||
int i; |
||||
(*obj) = (CvLSVMFilterObjectCaskade *)malloc(sizeof(CvLSVMFilterObjectCaskade)); |
||||
(*obj)->sizeX = sizeX; |
||||
(*obj)->sizeY = sizeY; |
||||
(*obj)->numFeatures = numFeatures; |
||||
(*obj)->fineFunction[0] = 0.0f; |
||||
(*obj)->fineFunction[1] = 0.0f; |
||||
(*obj)->fineFunction[2] = 0.0f; |
||||
(*obj)->fineFunction[3] = 0.0f; |
||||
(*obj)->V.x = 0; |
||||
(*obj)->V.y = 0; |
||||
(*obj)->V.l = 0; |
||||
(*obj)->H = (float *) malloc(sizeof (float) *
|
||||
(sizeX * sizeY * numFeatures)); |
||||
for(i = 0; i < sizeX * sizeY * numFeatures; i++) |
||||
{ |
||||
(*obj)->H[i] = 0.0f; |
||||
} |
||||
return LATENT_SVM_OK; |
||||
} |
||||
int freeFilterObject (CvLSVMFilterObjectCaskade **obj) |
||||
{ |
||||
if(*obj == NULL) return LATENT_SVM_MEM_NULL; |
||||
free((*obj)->H); |
||||
free(*obj); |
||||
(*obj) = NULL; |
||||
return LATENT_SVM_OK; |
||||
} |
||||
|
||||
int allocFeatureMapObject(CvLSVMFeatureMapCaskade **obj, const int sizeX,
|
||||
const int sizeY, const int numFeatures) |
||||
{ |
||||
int i; |
||||
(*obj) = (CvLSVMFeatureMapCaskade *)malloc(sizeof(CvLSVMFeatureMapCaskade)); |
||||
(*obj)->sizeX = sizeX; |
||||
(*obj)->sizeY = sizeY; |
||||
(*obj)->numFeatures = numFeatures; |
||||
(*obj)->map = (float *) malloc(sizeof (float) *
|
||||
(sizeX * sizeY * numFeatures)); |
||||
for(i = 0; i < sizeX * sizeY * numFeatures; i++) |
||||
{ |
||||
(*obj)->map[i] = 0.0f; |
||||
} |
||||
return LATENT_SVM_OK; |
||||
} |
||||
int freeFeatureMapObject (CvLSVMFeatureMapCaskade **obj) |
||||
{ |
||||
if(*obj == NULL) return LATENT_SVM_MEM_NULL; |
||||
free((*obj)->map); |
||||
free(*obj); |
||||
(*obj) = NULL; |
||||
return LATENT_SVM_OK; |
||||
} |
||||
|
||||
int allocFeaturePyramidObject(CvLSVMFeaturePyramidCaskade **obj, |
||||
const int numLevels)
|
||||
{ |
||||
(*obj) = (CvLSVMFeaturePyramidCaskade *)malloc(sizeof(CvLSVMFeaturePyramidCaskade)); |
||||
(*obj)->numLevels = numLevels; |
||||
(*obj)->pyramid = (CvLSVMFeatureMapCaskade **)malloc( |
||||
sizeof(CvLSVMFeatureMapCaskade *) * numLevels); |
||||
return LATENT_SVM_OK; |
||||
} |
||||
|
||||
int freeFeaturePyramidObject (CvLSVMFeaturePyramidCaskade **obj) |
||||
{ |
||||
int i;
|
||||
if(*obj == NULL) return LATENT_SVM_MEM_NULL; |
||||
for(i = 0; i < (*obj)->numLevels; i++) |
||||
{ |
||||
freeFeatureMapObject(&((*obj)->pyramid[i])); |
||||
} |
||||
free((*obj)->pyramid); |
||||
free(*obj); |
||||
(*obj) = NULL; |
||||
return LATENT_SVM_OK; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,44 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, University of Nizhny Novgorod, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
/* End of file. */ |
@ -0,0 +1,67 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, University of Nizhny Novgorod, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_PRECOMP_H__ |
||||
#define __OPENCV_PRECOMP_H__ |
||||
|
||||
#ifdef HAVE_CVCONFIG_H |
||||
#include "cvconfig.h" |
||||
#endif |
||||
|
||||
#ifdef __cplusplus |
||||
#include <map> |
||||
#include <deque> |
||||
#endif |
||||
|
||||
#include "opencv2/latentsvm.hpp" |
||||
#include "opencv2/imgproc.hpp" |
||||
#include "opencv2/imgproc/imgproc_c.h" |
||||
#include "opencv2/core/core_c.h" |
||||
|
||||
#include "opencv2/opencv_modules.hpp" |
||||
#include "opencv2/highgui/highgui_c.h" |
||||
|
||||
|
||||
#ifdef HAVE_TEGRA_OPTIMIZATION |
||||
#include "opencv2/objdetect/objdetect_tegra.hpp" |
||||
#endif |
||||
|
||||
#endif |
@ -0,0 +1,217 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp" |
||||
|
||||
#include <string> |
||||
|
||||
#ifdef HAVE_CVCONFIG_H |
||||
#include "cvconfig.h" |
||||
#endif |
||||
|
||||
#ifdef HAVE_TBB |
||||
#include "tbb/task_scheduler_init.h" |
||||
#endif |
||||
|
||||
using namespace cv; |
||||
|
||||
const float score_thr = 0.05f; |
||||
|
||||
class LatentSVMDetectorCaskadeTest : public cvtest::BaseTest |
||||
{ |
||||
protected: |
||||
void run(int); |
||||
}; |
||||
|
||||
static void writeDetections( FileStorage& fs, const std::string& nodeName, const std::vector<lsvm::LSVMDetector::ObjectDetection>& detections ) |
||||
{ |
||||
fs << nodeName << "["; |
||||
for( size_t i = 0; i < detections.size(); i++ ) //FIXME operator <<
|
||||
{ |
||||
lsvm::LSVMDetector::ObjectDetection const &d = detections[i]; |
||||
fs << d.rect.x << d.rect.y << d.rect.width << d.rect.height |
||||
<< d.score << d.classID; |
||||
} |
||||
fs << "]"; |
||||
} |
||||
|
||||
static void readDetections( FileStorage fs, const std::string& nodeName,
|
||||
std::vector<lsvm::LSVMDetector::ObjectDetection>& detections ) |
||||
{ |
||||
detections.clear(); |
||||
|
||||
FileNode fn = fs.root()[nodeName]; |
||||
FileNodeIterator fni = fn.begin(); |
||||
while( fni != fn.end() ) |
||||
{ |
||||
lsvm::LSVMDetector::ObjectDetection d; |
||||
fni >> d.rect.x >> d.rect.y >> d.rect.width >> d.rect.height |
||||
>> d.score >> d.classID; |
||||
detections.push_back( d ); |
||||
} |
||||
} |
||||
|
||||
static inline bool isEqualCaskad( const lsvm::LSVMDetector::ObjectDetection& d1, |
||||
const lsvm::LSVMDetector::ObjectDetection& d2, int eps, float threshold) |
||||
{ |
||||
return ( |
||||
std::abs(d1.rect.x - d2.rect.x) <= eps |
||||
&& std::abs(d1.rect.y - d2.rect.y) <= eps |
||||
&& std::abs(d1.rect.width - d2.rect.width) <= eps |
||||
&& std::abs(d1.rect.height - d2.rect.height) <= eps |
||||
&& (d1.classID == d2.classID) |
||||
&& std::abs(d1.score - d2.score) <= threshold |
||||
); |
||||
} |
||||
|
||||
|
||||
bool compareResults( const std::vector<lsvm::LSVMDetector::ObjectDetection>& calc, |
||||
const std::vector<lsvm::LSVMDetector::ObjectDetection>& valid, int eps, float threshold) |
||||
{ |
||||
if( calc.size() != valid.size() ) |
||||
return false; |
||||
|
||||
for( size_t i = 0; i < calc.size(); i++ ) |
||||
{ |
||||
lsvm::LSVMDetector::ObjectDetection const &c = calc[i]; |
||||
lsvm::LSVMDetector::ObjectDetection const &v = valid[i]; |
||||
|
||||
if( !isEqualCaskad(c, v, eps, threshold) ) |
||||
{ |
||||
std::cerr << "Expected: " << v.rect << " class=" << v.classID << " score=" << v.score << std::endl; |
||||
std::cerr << "Actual: " << c.rect << " class=" << c.classID << " score=" << c.score << std::endl; |
||||
return false; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
|
||||
void LatentSVMDetectorCaskadeTest::run( int /* start_from */) |
||||
{ |
||||
std::string img_path_cat = std::string(ts->get_data_path()) + "cat.png"; |
||||
std::string img_path_cars = std::string(ts->get_data_path()) + "cars.png"; |
||||
|
||||
std::string model_path_cat = std::string(ts->get_data_path()) + "models_VOC2007_cascade/cat.xml"; |
||||
std::string model_path_car = std::string(ts->get_data_path()) + "models_VOC2007_cascade/car.xml"; |
||||
|
||||
std::string true_res_path = std::string(ts->get_data_path()) + "results_cascade.xml"; |
||||
|
||||
|
||||
#ifdef HAVE_TBB |
||||
int numThreads = 2; |
||||
#endif |
||||
|
||||
Mat image_cat = imread( img_path_cat ); |
||||
Mat image_cars = imread( img_path_cars ); |
||||
if( image_cat.empty() || image_cars.empty() ) |
||||
{ |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); |
||||
return; |
||||
} |
||||
|
||||
// We will test 2 cases:
|
||||
// detector1 - to test case of one class 'cat'
|
||||
// detector12 - to test case of two (several) classes 'cat' and car
|
||||
|
||||
// Load detectors
|
||||
cv::Ptr<lsvm::LSVMDetector> detector1 = lsvm::LSVMDetector::create(std::vector<std::string>(1,model_path_cat)); |
||||
|
||||
std::vector<std::string> models_pathes(2); |
||||
models_pathes[0] = model_path_cat; |
||||
models_pathes[1] = model_path_car; |
||||
cv::Ptr<lsvm::LSVMDetector> detector12 = lsvm::LSVMDetector::create(models_pathes); |
||||
|
||||
if( detector1->isEmpty() || detector12->isEmpty() || detector12->getClassCount() != 2 ) |
||||
{ |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); |
||||
return; |
||||
} |
||||
|
||||
// 1. Test method detect
|
||||
// Run detectors
|
||||
std::vector<lsvm::LSVMDetector::ObjectDetection> detections1_cat, detections12_cat, detections12_cars; |
||||
detector1->detect( image_cat, detections1_cat, 0.5); |
||||
detector12->detect( image_cat, detections12_cat, 0.5); |
||||
detector12->detect( image_cars, detections12_cars, 0.5); |
||||
|
||||
// Load true results
|
||||
FileStorage fs( true_res_path, FileStorage::READ ); |
||||
if( fs.isOpened() ) |
||||
{ |
||||
std::vector<lsvm::LSVMDetector::ObjectDetection> true_detections1_cat, true_detections12_cat, true_detections12_cars; |
||||
readDetections( fs, "detections1_cat", true_detections1_cat ); |
||||
readDetections( fs, "detections12_cat", true_detections12_cat ); |
||||
readDetections( fs, "detections12_cars", true_detections12_cars ); |
||||
|
||||
if( !compareResults(detections1_cat, true_detections1_cat, 1, score_thr) ) |
||||
{ |
||||
std::cerr << "Results of detector1 are invalid on image cat.png" << std::endl; |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); |
||||
} |
||||
if( !compareResults(detections12_cat, true_detections12_cat, 1, score_thr) ) |
||||
{ |
||||
std::cerr << "Results of detector12 are invalid on image cat.png" << std::endl; |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); |
||||
} |
||||
if( !compareResults(detections12_cars, true_detections12_cars, 1, score_thr) ) |
||||
{ |
||||
std::cerr << "Results of detector12 are invalid on image cars.png" << std::endl; |
||||
ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
fs.open( true_res_path, FileStorage::WRITE ); |
||||
if( fs.isOpened() ) |
||||
{ |
||||
writeDetections( fs, "detections1_cat", detections1_cat ); |
||||
writeDetections( fs, "detections12_cat", detections12_cat ); |
||||
writeDetections( fs, "detections12_cars", detections12_cars ); |
||||
} |
||||
else |
||||
std::cerr << "File " << true_res_path << " cann't be opened to save test results" << std::endl; |
||||
} |
||||
|
||||
ts->set_failed_test_info( cvtest::TS::OK); |
||||
} |
||||
|
||||
TEST(Objdetect_LatentSVMDetectorCaskade_cpp, regression) { LatentSVMDetectorCaskadeTest test; test.safe_run(); } |
@ -0,0 +1,3 @@ |
||||
#include "test_precomp.hpp" |
||||
|
||||
CV_TEST_MAIN("latentsvm") |
@ -0,0 +1 @@ |
||||
#include "test_precomp.hpp" |
@ -0,0 +1,17 @@ |
||||
#ifdef __GNUC__ |
||||
# pragma GCC diagnostic ignored "-Wmissing-declarations" |
||||
# if defined __clang__ || defined __APPLE__ |
||||
# pragma GCC diagnostic ignored "-Wmissing-prototypes" |
||||
# pragma GCC diagnostic ignored "-Wextra" |
||||
# endif |
||||
#endif |
||||
|
||||
#ifndef __OPENCV_TEST_PRECOMP_HPP__ |
||||
#define __OPENCV_TEST_PRECOMP_HPP__ |
||||
|
||||
#include "opencv2/ts.hpp" |
||||
#include "opencv2/latentsvm.hpp" |
||||
#include "opencv2/imgproc.hpp" |
||||
#include "opencv2/highgui.hpp" |
||||
|
||||
#endif |
After Width: | Height: | Size: 202 KiB |
After Width: | Height: | Size: 311 KiB |
@ -0,0 +1,99 @@ |
||||
function [] = mat2xml(fname_in, fname_out) |
||||
load(fname_in); |
||||
num_feat = 31; |
||||
rootfilters = []; |
||||
for i = 1:length(model.rootfilters) |
||||
rootfilters{i} = model.rootfilters{i}.w; |
||||
end |
||||
partfilters = []; |
||||
for i = 1:length(model.partfilters) |
||||
partfilters{i} = model.partfilters{i}.w; |
||||
end |
||||
for c = 1:model.numcomponents |
||||
ridx{c} = model.components{c}.rootindex; |
||||
oidx{c} = model.components{c}.offsetindex; |
||||
root{c} = model.rootfilters{ridx{c}}.w; |
||||
rsize{c} = [size(root{c},1) size(root{c},2)]; |
||||
numparts{c} = length(model.components{c}.parts); |
||||
for j = 1:numparts{c} |
||||
pidx{c,j} = model.components{c}.parts{j}.partindex; |
||||
didx{c,j} = model.components{c}.parts{j}.defindex; |
||||
part{c,j} = model.partfilters{pidx{c,j}}.w; |
||||
psize{c,j} = [size(part{c,j},1) size(part{c,j},2)]; |
||||
% reverse map from partfilter index to (component, part#) |
||||
% rpidx{pidx{c,j}} = [c j]; |
||||
end |
||||
end |
||||
|
||||
f = fopen(fname_out, 'wb'); |
||||
fprintf(f, '<Model>\n'); |
||||
fprintf(f, '\t<!-- Number of components -->\n'); |
||||
fprintf(f, '\t<NumComponents>%d</NumComponents>\n', model.numcomponents); |
||||
fprintf(f, '\t<!-- Number of features -->\n'); |
||||
fprintf(f, '\t<P>%d</P>\n', num_feat); |
||||
fprintf(f, '\t<!-- Score threshold -->\n'); |
||||
fprintf(f, '\t<ScoreThreshold>%.16f</ScoreThreshold>\n', model.thresh); |
||||
for c = 1:model.numcomponents |
||||
fprintf(f, '\t<Component>\n'); |
||||
fprintf(f, '\t\t<!-- Root filter description -->\n'); |
||||
fprintf(f, '\t\t<RootFilter>\n'); |
||||
fprintf(f, '\t\t\t<!-- Dimensions -->\n'); |
||||
rootfilter = root{c}; |
||||
fprintf(f, '\t\t\t<sizeX>%d</sizeX>\n', rsize{c}(2)); |
||||
fprintf(f, '\t\t\t<sizeY>%d</sizeY>\n', rsize{c}(1)); |
||||
fprintf(f, '\t\t\t<!-- Weights (binary representation) -->\n'); |
||||
fprintf(f, '\t\t\t<Weights>'); |
||||
for jj = 1:rsize{c}(1) |
||||
for ii = 1:rsize{c}(2) |
||||
for kk = 1:num_feat |
||||
fwrite(f, rootfilter(jj, ii, kk), 'double'); |
||||
end |
||||
end |
||||
end |
||||
fprintf(f, '\t\t\t</Weights>\n'); |
||||
fprintf(f, '\t\t\t<!-- Linear term in score function -->\n'); |
||||
fprintf(f, '\t\t\t<LinearTerm>%.16f</LinearTerm>\n', model.offsets{1,c}.w); |
||||
fprintf(f, '\t\t</RootFilter>\n\n'); |
||||
fprintf(f, '\t\t<!-- Part filters description -->\n'); |
||||
fprintf(f, '\t\t<PartFilters>\n'); |
||||
fprintf(f, '\t\t\t<NumPartFilters>%d</NumPartFilters>\n', numparts{c}); |
||||
|
||||
for j=1:numparts{c} |
||||
fprintf(f, '\t\t\t<!-- Part filter ¹%d description -->\n', j); |
||||
fprintf(f, '\t\t\t<PartFilter>\n'); |
||||
partfilter = part{c,j}; |
||||
anchor = model.defs{didx{c,j}}.anchor; |
||||
def = model.defs{didx{c,j}}.w; |
||||
|
||||
fprintf(f, '\t\t\t\t<!-- Dimensions -->\n'); |
||||
fprintf(f, '\t\t\t\t<sizeX>%d</sizeX>\n', psize{c,j}(2)); |
||||
fprintf(f, '\t\t\t\t<sizeY>%d</sizeY>\n', psize{c,j}(1)); |
||||
fprintf(f, '\t\t\t\t<!-- Weights (binary representation) -->\n'); |
||||
fprintf(f, '\t\t\t\t<Weights>'); |
||||
for jj = 1:psize{c,j}(1) |
||||
for ii = 1:psize{c,j}(2) |
||||
for kk = 1:num_feat |
||||
fwrite(f, partfilter(jj, ii, kk), 'double'); |
||||
end |
||||
end |
||||
end |
||||
fprintf(f, '\t\t\t\t</Weights>\n'); |
||||
fprintf(f, '\t\t\t\t<!-- Part filter offset -->\n'); |
||||
fprintf(f, '\t\t\t\t<V>\n'); |
||||
fprintf(f, '\t\t\t\t\t<Vx>%d</Vx>\n', anchor(1)); |
||||
fprintf(f, '\t\t\t\t\t<Vy>%d</Vy>\n', anchor(2)); |
||||
fprintf(f, '\t\t\t\t</V>\n'); |
||||
fprintf(f, '\t\t\t\t<!-- Quadratic penalty function coefficients -->\n'); |
||||
fprintf(f, '\t\t\t\t<Penalty>\n'); |
||||
fprintf(f, '\t\t\t\t\t<dx>%.16f</dx>\n', def(2)); |
||||
fprintf(f, '\t\t\t\t\t<dy>%.16f</dy>\n', def(4)); |
||||
fprintf(f, '\t\t\t\t\t<dxx>%.16f</dxx>\n', def(1)); |
||||
fprintf(f, '\t\t\t\t\t<dyy>%.16f</dyy>\n', def(3)); |
||||
fprintf(f, '\t\t\t\t</Penalty>\n'); |
||||
fprintf(f, '\t\t\t</PartFilter>\n'); |
||||
end |
||||
fprintf(f, '\t\t</PartFilters>\n'); |
||||
fprintf(f, '\t</Component>\n'); |
||||
end |
||||
fprintf(f, '</Model>'); |
||||
fclose(f); |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,12 @@ |
||||
<?xml version="1.0"?> |
||||
<opencv_storage> |
||||
<detections1_cat> |
||||
0 0 340 485 -0.837739 0</detections1_cat> |
||||
<detections12_cat> |
||||
0 0 340 485 -0.837739 0 129 0 181 155 -0.795819 1</detections12_cat> |
||||
<detections12_cars> |
||||
218 24 218 121 2.36436 1 0 285 233 129 1.93423 1 0 21 190 105 1.7496 1 202 183 202 |
||||
73 1.57262 1 0 171 171 68 1.49932 1 238 312 165 91 0.504801 1 0 181 226 90 0.404986 |
||||
1 0 0 240 171 0.158534 1 207 155 233 129 -0.1988589 1 195 278 250 139 -0.50933 1 |
||||
89 0 328 119 -0.570692 1 0 295 422 154 -0.922104 1</detections12_cars> |
||||
</opencv_storage> |
Loading…
Reference in new issue