Initial commit.
Final release of the project Anonymizer (2015). Project settings for the Qt Creator (ver. 3.6).
This commit is contained in:
116
3rdparty/include/opencvx/cvanglemean.h
vendored
Normal file
116
3rdparty/include/opencvx/cvanglemean.h
vendored
Normal file
@ -0,0 +1,116 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_ANGLEMEAN_INCLUDED
|
||||
#define CV_ANGLEMEAN_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
#include <float.h>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
/**
|
||||
* Compute mean of angle elements of an array (each channel independently).
|
||||
*
|
||||
* There is a fact that 0 degrees and 360 degrees are identical angles,
|
||||
* so that for example 180 degrees is not a sensible mean of 2 degrees and
|
||||
* 358 degrees, but 0 degree is the mean.
|
||||
* Algorithm works as 1. compute means of cosine and sine
|
||||
* 2. take arc tangent of the mean consine and sine.
|
||||
*
|
||||
* @param arr array
|
||||
* @param weight Weight to compute mean. The deafult is 1/num (uniform).
|
||||
* The size must be same with arr.
|
||||
* @param wrap The unit of wrapping around.
|
||||
* The defeault is 360 as angle.
|
||||
* @return angle mean for each channel
|
||||
*/
|
||||
CVAPI(CvScalar) cvAngleMean( const CvArr *arr,
|
||||
const CvArr *weight CV_DEFAULT(NULL),
|
||||
double wrap CV_DEFAULT(360) )
|
||||
{
|
||||
CvMat* mat, matstub;
|
||||
CvMat* wmat = NULL, wmatstub;
|
||||
CvScalar mean = cvScalar(0,0,0,0);
|
||||
int row, col, ch;
|
||||
int nChannels;
|
||||
CvScalar elem;
|
||||
CvScalar mean_cos = cvScalar(0,0,0,0);
|
||||
CvScalar mean_sin = cvScalar(0,0,0,0);
|
||||
CvScalar welem;
|
||||
CV_FUNCNAME( "cvAngleMean" );
|
||||
__CV_BEGIN__;
|
||||
|
||||
mat = (CvMat*)arr;
|
||||
if( !CV_IS_MAT(mat) )
|
||||
{
|
||||
CV_CALL( mat = cvGetMat( mat, &matstub ) );
|
||||
}
|
||||
if( weight != NULL )
|
||||
{
|
||||
wmat = (CvMat*)weight;
|
||||
if( !CV_IS_MAT(wmat) )
|
||||
{
|
||||
CV_CALL( wmat = cvGetMat( wmat, &wmatstub ) );
|
||||
}
|
||||
CV_ASSERT(
|
||||
mat->rows == wmat->rows &&
|
||||
mat->cols == wmat->cols &&
|
||||
CV_MAT_CN(mat->type) == CV_MAT_CN(wmat->type)
|
||||
);
|
||||
}
|
||||
nChannels = CV_MAT_CN(mat->type);
|
||||
if( wmat == NULL ) // uniform
|
||||
{
|
||||
double w = 1.0 / (double)mat->rows * (double)mat->cols;
|
||||
welem = cvScalar( w, w, w, w );
|
||||
}
|
||||
for( row = 0; row < mat->rows; row++ )
|
||||
{
|
||||
for( col = 0; col < mat->cols; col++ )
|
||||
{
|
||||
elem = cvGet2D( mat, row, col );
|
||||
if( wmat != NULL ) welem = cvGet2D( wmat, row, col );
|
||||
for( ch = 0; ch < nChannels; ch++ )
|
||||
{
|
||||
mean_cos.val[ch] +=
|
||||
cos( elem.val[ch] * 2*M_PI / wrap ) * welem.val[ch];
|
||||
mean_sin.val[ch] +=
|
||||
sin( elem.val[ch] * 2*M_PI / wrap ) * welem.val[ch];
|
||||
}
|
||||
}
|
||||
}
|
||||
for( ch = 0; ch < nChannels; ch++ )
|
||||
{
|
||||
mean.val[ch] =
|
||||
atan( mean_sin.val[ch] / mean_cos.val[ch] ) * wrap / (2*M_PI);
|
||||
}
|
||||
__CV_END__;
|
||||
return mean;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
134
3rdparty/include/opencvx/cvbackground.h
vendored
Normal file
134
3rdparty/include/opencvx/cvbackground.h
vendored
Normal file
@ -0,0 +1,134 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_BACKGROUND_INCLUDED
|
||||
#define CV_BACKGROUND_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
/**
|
||||
* Obtain non-background pixels using reference image (such as previous frame in video )
|
||||
*
|
||||
* @param _img The target image
|
||||
* @param _ref The reference image. Usually the previous frame of video
|
||||
* @param _mask The generated mask image where 0 is for bg and 1 is for non-bg.
|
||||
* Must be 8U and 1 channel
|
||||
* @param thresh The threshold. [0 - 255^2] for single channel image.
|
||||
* [0 - 255^2 * 3] for 3 channel image.
|
||||
* @return
|
||||
*/
|
||||
CVAPI(void) cvBackground( const IplImage* _img,
|
||||
const IplImage* _ref,
|
||||
IplImage* _mask,
|
||||
int thresh CV_DEFAULT(100) )
|
||||
{
|
||||
IplImage *img;
|
||||
IplImage *ref;
|
||||
IplImage *mask;
|
||||
CV_FUNCNAME( "cvBackground" ); // error handling
|
||||
__CV_BEGIN__;
|
||||
CV_ASSERT( _img->width == _ref->width );
|
||||
CV_ASSERT( _img->width == _mask->width );
|
||||
CV_ASSERT( _img->height == _ref->height );
|
||||
CV_ASSERT( _img->height == _ref->height );
|
||||
CV_ASSERT( _img->nChannels == _ref->nChannels );
|
||||
CV_ASSERT( _mask->nChannels == 1 );
|
||||
CV_ASSERT( _mask->depth == IPL_DEPTH_8U );
|
||||
|
||||
img = cvCreateImage( cvGetSize(_img), IPL_DEPTH_32F, _img->nChannels );
|
||||
ref = cvCreateImage( cvGetSize(_img), IPL_DEPTH_32F, _img->nChannels );
|
||||
mask = cvCreateImage( cvGetSize(_img), IPL_DEPTH_32F, 1 );
|
||||
cvConvert( _img, img );
|
||||
cvConvert( _ref, ref );
|
||||
cvSub( img, ref, img );
|
||||
cvMul( img, img, img ); // square
|
||||
|
||||
if( img->nChannels > 1 )
|
||||
{
|
||||
IplImage* imgB = cvCreateImage( cvGetSize(img), img->depth, 1 );
|
||||
IplImage* imgG = cvCreateImage( cvGetSize(img), img->depth, 1 );
|
||||
IplImage* imgR = cvCreateImage( cvGetSize(img), img->depth, 1 );
|
||||
cvSplit( img, imgB, imgG, imgR, NULL );
|
||||
cvAdd( imgB, imgG, mask );
|
||||
cvAdd( mask, imgR, mask );
|
||||
cvReleaseImage( &imgB );
|
||||
cvReleaseImage( &imgG );
|
||||
cvReleaseImage( &imgR );
|
||||
}
|
||||
else
|
||||
{
|
||||
cvCopy( img, mask );
|
||||
}
|
||||
cvThreshold( mask, _mask, thresh, 1, CV_THRESH_BINARY );
|
||||
|
||||
cvReleaseImage( &img );
|
||||
cvReleaseImage( &ref );
|
||||
cvReleaseImage( &mask );
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
/*
|
||||
//this is a sample for foreground detection functions
|
||||
//this is not training, but using pre-determined params
|
||||
//See cvCreateGaussainBGModel in ./cvaux/src/cvbgfg_gaussmix.cpp
|
||||
//This is setting paramets such as CV_BGFG_MOG_BACKGROUND_THRESHOLD (cvaux.h)
|
||||
//cvUpdateBGStatModel means just setting bg_model->foreground, background
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
IplImage* tmp_frame = NULL;
|
||||
CvCapture* video = NULL;
|
||||
|
||||
video = cvCaptureFromFile(argv[1]);
|
||||
tmp_frame = cvQueryFrame(video);
|
||||
if(!tmp_frame)
|
||||
{
|
||||
printf("bad video \n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
cvNamedWindow("BG", 1);
|
||||
cvNamedWindow("FG", 1);
|
||||
|
||||
//create BG model
|
||||
CvBGStatModel* bg_model = cvCreateGaussianBGModel( tmp_frame );
|
||||
|
||||
for( int fr = 1;tmp_frame; tmp_frame = cvQueryFrame(video), fr++ )
|
||||
{
|
||||
cvUpdateBGStatModel( tmp_frame, bg_model );
|
||||
cvShowImage("BG", bg_model->background);
|
||||
cvShowImage("FG", bg_model->foreground);
|
||||
int k = cvWaitKey(5);
|
||||
if( k == 27 ) break;
|
||||
//printf("frame# %d \r", fr);
|
||||
}
|
||||
|
||||
|
||||
cvReleaseBGStatModel( &bg_model );
|
||||
cvReleaseCapture(&video);
|
||||
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
#endif
|
142
3rdparty/include/opencvx/cvcat.h
vendored
Normal file
142
3rdparty/include/opencvx/cvcat.h
vendored
Normal file
@ -0,0 +1,142 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_CAT_INCLUDED
|
||||
#define CV_CAT_INCLUDED
|
||||
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cvsetrow.h"
|
||||
#include "cvsetcol.h"
|
||||
|
||||
/**
|
||||
* Concatinate arrays horizontally
|
||||
*
|
||||
* @param src1 Input array 1
|
||||
* @param src2 Input array 2
|
||||
* @param dst Target array
|
||||
* @see cvCat, cvVcat
|
||||
*/
|
||||
#define cvHcat( src1, src2, dst ) cvCat( (src1), (src2), (dst), 0 )
|
||||
|
||||
/**
|
||||
* Concatinate arrays vertically
|
||||
*
|
||||
* @param src1 Input array 1
|
||||
* @param src2 Input array 2
|
||||
* @param dst Target array
|
||||
* @see cvCat, cvHcat
|
||||
*/
|
||||
#define cvVcat( src1, src2, dst ) cvCat( (src1), (src2), (dst), 1 )
|
||||
|
||||
/**
|
||||
* Concatinate arrays
|
||||
*
|
||||
* Example)
|
||||
* @code
|
||||
* IplImage* img = cvCreateImage( cvSize(4,4), IPL_DEPTH_8U, 1 ); // width(cols), height(rows)
|
||||
* IplImage* subimg = cvCreateImage( cvSize(1,4), IPL_DEPTH_8U, 1 );
|
||||
* IplImage* catimg = cvCreateImage( cvSize(5,4), IPL_DEPTH_8U, 1 );
|
||||
* cvSet( img, cvScalar(1) );
|
||||
* cvSet( subimg, cvScalar(0) );
|
||||
* cvHcat( img, subimg, catimg ); // 4x4 + 4x1 = 4x5
|
||||
* cvMatPrint( catimg );
|
||||
* @endcode
|
||||
*
|
||||
* @param src1 Input array 1
|
||||
* @param src2 Input array 2
|
||||
* @param dst Target array
|
||||
* @param dim 0 horizontally, 1 vertically, -1 flexibly
|
||||
* @see cvHcat( src1, src2, dst ) // cvCat( src1, src2, dst, 0 )
|
||||
* @see cvVcat( src1, src2, dst ) // cvCat( src1, src2, dst, 1 )
|
||||
*/
|
||||
CVAPI(void) cvCat( const CvArr* src1arr, const CvArr* src2arr, CvArr* dstarr, int dim CV_DEFAULT(-1) )
|
||||
{
|
||||
int coi = 0;
|
||||
CvMat *src1 = (CvMat*)src1arr, src1stub;
|
||||
CvMat *src2 = (CvMat*)src2arr, src2stub;
|
||||
CvMat *dst = (CvMat*)dstarr, dststub;
|
||||
CV_FUNCNAME( "cvCat" );
|
||||
__CV_BEGIN__;
|
||||
if( !CV_IS_MAT(src1) )
|
||||
{
|
||||
src1 = cvGetMat( src1, &src1stub, &coi );
|
||||
if (coi != 0) CV_Error(CV_BadCOI, "");//CV_ERROR_FROM_CODE(CV_BadCOI);
|
||||
}
|
||||
if( !CV_IS_MAT(src2) )
|
||||
{
|
||||
src2 = cvGetMat( src2, &src2stub, &coi );
|
||||
if (coi != 0) CV_Error(CV_BadCOI, "");//CV_ERROR_FROM_CODE(CV_BadCOI);
|
||||
}
|
||||
if( !CV_IS_MAT(dst) )
|
||||
{
|
||||
dst = cvGetMat( dst, &dststub, &coi );
|
||||
if (coi != 0) CV_Error(CV_BadCOI, "");//CV_ERROR_FROM_CODE(CV_BadCOI);
|
||||
}
|
||||
if( dim == -1 )
|
||||
{
|
||||
if( src1->rows == src2->rows && src1->rows == dst->rows )
|
||||
{
|
||||
dim = 0;
|
||||
}
|
||||
else if( src1->cols == src2->cols && src1->cols == dst->cols )
|
||||
{
|
||||
dim = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
CV_ERROR( CV_StsBadArg, "The size of matrices does not fit to concatinate." );
|
||||
}
|
||||
}
|
||||
if( dim == 0 ) // horizontal cat
|
||||
{
|
||||
CV_ASSERT( src1->rows == src2->rows && src1->rows == dst->rows );
|
||||
CV_ASSERT( src1->cols + src2->cols == dst->cols );
|
||||
}
|
||||
else if( dim == 1 ) // vertical cat
|
||||
{
|
||||
CV_ASSERT( src1->cols == src2->cols && src1->cols == dst->cols );
|
||||
CV_ASSERT( src1->rows + src2->rows == dst->rows );
|
||||
}
|
||||
else
|
||||
{
|
||||
CV_ERROR( CV_StsBadArg, "The dim is 0 (horizontal) or 1 (vertical) or -1 (flexible)." );
|
||||
}
|
||||
|
||||
if( dim == 0 ) // horizontal cat
|
||||
{
|
||||
cvSetCols( src1, dst, 0, src1->cols );
|
||||
cvSetCols( src2, dst, src1->cols, src1->cols + src2->cols );
|
||||
}
|
||||
else // vertical cat
|
||||
{
|
||||
cvSetRows( src1, dst, 0, src1->rows );
|
||||
cvSetRows( src2, dst, src1->rows, src1->rows + src2->rows );
|
||||
}
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
54
3rdparty/include/opencvx/cvclosing.h
vendored
Normal file
54
3rdparty/include/opencvx/cvclosing.h
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_CLOSING_INCLUDED
|
||||
#define CV_CLOSING_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
/**
|
||||
* Closing morphological operation
|
||||
*
|
||||
* closing operation would help to fill disconnected contour
|
||||
*
|
||||
* @param src Input Array
|
||||
* @param dst Output Array
|
||||
* @param element Kernel shape. see cvErode or cvDilate
|
||||
* @param iterations
|
||||
* @return CVAPI(void)
|
||||
*
|
||||
* References)
|
||||
* R. Gonzalez, R. Woods, "Digital Image Processing," chapter 9
|
||||
*/
|
||||
CVAPI(void) cvClosing( const CvArr* src, CvArr* dst,
|
||||
IplConvKernel* element CV_DEFAULT(NULL),
|
||||
int iterations CV_DEFAULT(1) )
|
||||
{
|
||||
cvDilate( dst, dst, element, iterations );
|
||||
cvErode( src, dst, element, iterations );
|
||||
}
|
||||
|
||||
|
||||
#endif
|
99
3rdparty/include/opencvx/cvcreateaffine.h
vendored
Normal file
99
3rdparty/include/opencvx/cvcreateaffine.h
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_CREATEAFFINE_INCLUDED
|
||||
#define CV_CREATEAFFINE_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#include "cvrect32f.h"
|
||||
|
||||
/**
|
||||
* Create an affine transform matrix from parameters.
|
||||
*
|
||||
* @param affine The 2 x 3 CV_32FC1|CV_64FC1 affine matrix to be created
|
||||
* @param rect The translation (x, y) and scaling (width, height) and
|
||||
* rotation (angle) paramenter in degree
|
||||
* @param shear The shear deformation parameter shx and shy
|
||||
* @return CVAPI(void)
|
||||
*
|
||||
* References)
|
||||
* @verbatim
|
||||
@Book{Hartley2004,
|
||||
author = "Hartley, R.~I. and Zisserman, A.",
|
||||
title = "Multiple View Geometry in Computer Vision",
|
||||
edition = "Second",
|
||||
year = "2004",
|
||||
publisher = "Cambridge University Press, ISBN: 0521540518"
|
||||
} @endverbatim
|
||||
*/
|
||||
CVAPI(void) cvCreateAffine( CvMat* affine,
|
||||
CvRect32f rect CV_DEFAULT(cvRect32f(0,0,1,1,0)),
|
||||
CvPoint2D32f shear CV_DEFAULT(cvPoint2D32f(0,0)) )
|
||||
{
|
||||
double c, s;
|
||||
CvMat *R, *S, *A, hdr;
|
||||
CV_FUNCNAME( "cvCreateAffine" );
|
||||
__CV_BEGIN__;
|
||||
CV_ASSERT( rect.width > 0 && rect.height > 0 );
|
||||
CV_ASSERT( affine->rows == 2 && affine->cols == 3 );
|
||||
|
||||
// affine = [ A T ]
|
||||
// A = [ a b; c d ]
|
||||
// Translation T = [ tx; ty ]
|
||||
// (1) A = Rotation * Shear(-phi) * [sx 0; 0 sy] * Shear(phi)
|
||||
// (2) A = Rotation * [sx shx; shy sy]
|
||||
// Use (2)
|
||||
|
||||
// T = [tx; ty]
|
||||
cvmSet( affine, 0, 2, rect.x ); cvmSet( affine, 1, 2, rect.y );
|
||||
|
||||
// R = [cos -sin; sin cos]
|
||||
R = cvCreateMat( 2, 2, affine->type );
|
||||
/*CvMat* R = cvCreateMat( 2, 3, CV_32FC1 );
|
||||
cv2DRotationMatrix( cvPoint2D32f( 0, 0 ), rect.angle, 1.0, R ); */
|
||||
c = cos( -M_PI / 180 * rect.angle );
|
||||
s = sin( -M_PI / 180 * rect.angle );
|
||||
cvmSet( R, 0, 0, c ); cvmSet( R, 0, 1, -s );
|
||||
cvmSet( R, 1, 0, s ); cvmSet( R, 1, 1, c );
|
||||
|
||||
// S = [sx shx; shy sy]
|
||||
S = cvCreateMat( 2, 2, affine->type );
|
||||
cvmSet( S, 0, 0, rect.width ); cvmSet( S, 0, 1, shear.x );
|
||||
cvmSet( S, 1, 0, shear.y ); cvmSet( S, 1, 1, rect.height );
|
||||
|
||||
// A = R * S
|
||||
A = cvGetCols( affine, &hdr, 0, 2 );
|
||||
cvMatMul ( R, S, A );
|
||||
|
||||
cvReleaseMat( &R );
|
||||
cvReleaseMat( &S );
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
186
3rdparty/include/opencvx/cvcreateaffineimage.h
vendored
Normal file
186
3rdparty/include/opencvx/cvcreateaffineimage.h
vendored
Normal file
@ -0,0 +1,186 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_CREATEAFFINEIMAGE_INCLUDED
|
||||
#define CV_CREATEAFFINEIMAGE_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "cvinvaffine.h"
|
||||
|
||||
#define CV_AFFINE_SAME 0
|
||||
#define CV_AFFINE_FULL 1
|
||||
|
||||
//CV_INLINE IplImage*
|
||||
//cvCreateAffineMask( const IplImage* src, const CvMat* affine,
|
||||
// int flags = CV_AFFINE_SAME, CvPoint* origin = NULL );
|
||||
//IplImage*
|
||||
//cvCreateAffineImage( const IplImage* src, const CvMat* affine,
|
||||
// int flags = CV_AFFINE_SAME, CvPoint* origin = NULL,
|
||||
// CvScalar bgcolor = CV_RGB(0,0,0) );
|
||||
|
||||
/**
|
||||
* Affine transform of an image.
|
||||
*
|
||||
* Memory is allocated. Do not forget cvReleaseImage( &ret );
|
||||
*
|
||||
* @param src Image
|
||||
* @param affine 2 x 3 Affine transform matrix
|
||||
* @param flags CV_AFFINE_SAME - Outside image coordinates are cut off.
|
||||
* CV_AFFINE_FULL - Fully contain the original image pixel values
|
||||
* @param origin The coordinate of origin is returned. The origin is the
|
||||
* coordinate in original image respective to the transformed
|
||||
* image origin. Useful when CV_AFFINE_FULL is used.
|
||||
* @param bgcolor The color used when corresponding coordinate is not
|
||||
* available in the original image.
|
||||
* @return
|
||||
* @see cvWarpAffine
|
||||
* this does not support CV_AFFINE_FULL, but supports
|
||||
* everal interpolation methods and so on.
|
||||
*/
|
||||
IplImage*
|
||||
cvCreateAffineImage( const IplImage* src, const CvMat* affine,
|
||||
int flags = CV_AFFINE_SAME, CvPoint* origin = NULL,
|
||||
CvScalar bgcolor = CV_RGB(0,0,0) )
|
||||
{
|
||||
IplImage* dst;
|
||||
int minx = INT_MAX;
|
||||
int miny = INT_MAX;
|
||||
int maxx = INT_MIN;
|
||||
int maxy = INT_MIN;
|
||||
int i, x, y, xx, yy, xp, yp;
|
||||
int ch, width, height;
|
||||
CvPoint pt[4];
|
||||
CvMat* invaffine;
|
||||
CV_FUNCNAME( "cvAffineImage" );
|
||||
__CV_BEGIN__;
|
||||
CV_ASSERT( src->depth == IPL_DEPTH_8U );
|
||||
CV_ASSERT( affine->rows == 2 && affine->cols == 3 );
|
||||
|
||||
// cvBoxPoints supports only rotation (no shear deform)
|
||||
// original 4 corner
|
||||
pt[0].x = 0; pt[0].y = 0;
|
||||
pt[1].x = src->width - 1; pt[1].y = 0;
|
||||
pt[2].x = 0; pt[2].y = src->height - 1;
|
||||
pt[3].x = src->width - 1; pt[3].y = src->height - 1;
|
||||
// 4 corner after transformed
|
||||
for( i = 0; i < 4; i++ )
|
||||
{
|
||||
x = cvRound( pt[i].x * cvmGet( affine, 0, 0 ) +
|
||||
pt[i].y * cvmGet( affine, 0, 1 ) +
|
||||
cvmGet( affine, 0, 2 ) );
|
||||
y = cvRound( pt[i].x * cvmGet( affine, 1, 0 ) +
|
||||
pt[i].y * cvmGet( affine, 1, 1 ) +
|
||||
cvmGet( affine, 1, 2 ) );
|
||||
pt[i].x = x; pt[i].y = y;
|
||||
}
|
||||
// min, max
|
||||
for( i = 0; i < 4; i++ )
|
||||
{
|
||||
minx = MIN( pt[i].x, minx );
|
||||
miny = MIN( pt[i].y, miny );
|
||||
maxx = MAX( pt[i].x, maxx );
|
||||
maxy = MAX( pt[i].y, maxy );
|
||||
}
|
||||
// target image width and height
|
||||
if( flags == CV_AFFINE_FULL )
|
||||
{
|
||||
width = maxx - minx + 1;
|
||||
height = maxy - miny + 1;
|
||||
}
|
||||
else if( flags == CV_AFFINE_SAME )
|
||||
{
|
||||
width = src->width;
|
||||
height = src->height;
|
||||
minx = miny = 0;
|
||||
maxx = src->width - 1;
|
||||
maxy = src->height - 1;
|
||||
}
|
||||
//cvPrintMat( affine );
|
||||
//printf( "%d %d %d %d\n", minx, miny, maxx, maxy );
|
||||
if( origin != NULL )
|
||||
{
|
||||
origin->x = minx;
|
||||
origin->y = miny;
|
||||
}
|
||||
dst = cvCreateImage( cvSize(width, height), src->depth, src->nChannels );
|
||||
cvSet( dst, bgcolor );
|
||||
|
||||
// inverse affine
|
||||
invaffine = cvCreateMat( 2, 3, affine->type );
|
||||
cvInvAffine( affine, invaffine );
|
||||
|
||||
// loop based on image coordinates of transformed image
|
||||
for( x = 0; x < width; x++ )
|
||||
{
|
||||
xx = x + minx;
|
||||
for( y = 0; y < height; y++ )
|
||||
{
|
||||
yy = y + miny;
|
||||
xp = cvRound( xx * cvmGet( invaffine, 0, 0 ) +
|
||||
yy * cvmGet( invaffine, 0, 1 ) +
|
||||
cvmGet( invaffine, 0, 2 ) );
|
||||
yp = cvRound( xx * cvmGet( invaffine, 1, 0 ) +
|
||||
yy * cvmGet( invaffine, 1, 1 ) +
|
||||
cvmGet( invaffine, 1, 2 ) );
|
||||
if( xp < 0 || xp >= src->width || yp < 0 || yp >= src->height ) continue;
|
||||
for( ch = 0; ch < src->nChannels; ch++ )
|
||||
{
|
||||
dst->imageData[dst->widthStep * y + x * dst->nChannels + ch]
|
||||
= src->imageData[src->widthStep * yp + xp * src->nChannels + ch];
|
||||
}
|
||||
}
|
||||
}
|
||||
cvReleaseMat( &invaffine );
|
||||
__CV_END__;
|
||||
return dst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a mask image for cvCreateAffineImage
|
||||
*
|
||||
* @param src Image. Used to get image size.
|
||||
* @param affine 2 x 3 Affine transform matrix
|
||||
* @param flags CV_AFFINE_SAME - Outside image coordinates are cut off
|
||||
* CV_AFFINE_FULL - Fully contain the original image pixel values
|
||||
* @param origin The coordinate of origin (the coordinate in original image respective to
|
||||
* the transformed image origin).
|
||||
* Useful when CV_AFFINE_FULL is used.
|
||||
*/
|
||||
CV_INLINE IplImage*
|
||||
cvCreateAffineMask( const IplImage* src, const CvMat* affine,
|
||||
int flags = CV_AFFINE_SAME, CvPoint* origin = NULL )
|
||||
{
|
||||
IplImage* orig = cvCreateImage( cvGetSize(src), IPL_DEPTH_8U, 1 );
|
||||
cvSet( orig, cvScalar(1) );
|
||||
IplImage* mask = cvCreateAffineImage( orig, affine, flags, origin, cvScalar(0) );
|
||||
cvReleaseImage( &orig );
|
||||
return mask;
|
||||
}
|
||||
|
||||
#endif
|
187
3rdparty/include/opencvx/cvcropimageroi.h
vendored
Normal file
187
3rdparty/include/opencvx/cvcropimageroi.h
vendored
Normal file
@ -0,0 +1,187 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_CROPIMAGEROI_INCLUDED
|
||||
#define CV_CROPIMAGEROI_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#include "cvcreateaffine.h"
|
||||
#include "cvrect32f.h"
|
||||
#include "cvget2dinter.h"
|
||||
|
||||
//CVAPI(void)
|
||||
//cvCropImageROI( const IplImage* img, IplImage* dst,
|
||||
// CvRect32f rect32f = cvRect32f(0,0,1,1,0),
|
||||
// CvPoint2D32f shear = cvPoint2D32f(0,0) );
|
||||
//CV_INLINE void
|
||||
//cvShowCroppedImage( const char* w_name, IplImage* img,
|
||||
// CvRect32f rect32f = cvRect32f(0,0,1,1,0),
|
||||
// CvPoint2D32f shear = cvPoint2D32f(0,0) );
|
||||
|
||||
/**
|
||||
* Crop image with rotated and sheared rectangle
|
||||
*
|
||||
* @code
|
||||
* IplImage* dst = cvCreateImage( cvSize( rect.width, rect.height ), img->depth, img->nChannels );
|
||||
* @endcode
|
||||
* If you want define rotation center as the center of the rectangle,
|
||||
* use CvBox32f and use cvRect32fBox32( box32f ) for the rect32f argument.
|
||||
*
|
||||
* @param img The target image
|
||||
* @param dst The cropped image
|
||||
* @param rect32f The rectangle region (x,y,width,height) to crop and
|
||||
* the rotation angle in degree where the rotation center is (x,y)
|
||||
* @param shear The shear deformation parameter shx and shy
|
||||
* @param interpolation The interpolation method.
|
||||
* CV_INTER_NN - Nearest Neighborhood method
|
||||
* CV_INTER_LINEAR - Bilinear interpolation
|
||||
* @return CVAPI(void)
|
||||
*/
|
||||
CVAPI(void)
|
||||
cvCropImageROI( const IplImage* img, IplImage* dst,
|
||||
CvRect32f rect32f CV_DEFAULT(cvRect32f(0,0,1,1,0)),
|
||||
CvPoint2D32f shear CV_DEFAULT(cvPoint2D32f(0,0)),
|
||||
int interpolation CV_DEFAULT(CV_INTER_LINEAR) )
|
||||
{
|
||||
CvRect rect = cvRectFromRect32f( rect32f );
|
||||
float angle = rect32f.angle;
|
||||
CV_FUNCNAME( "cvCropImageROI" );
|
||||
__CV_BEGIN__;
|
||||
CV_ASSERT( rect.width > 0 && rect.height > 0 );
|
||||
CV_ASSERT( dst->width == rect.width );
|
||||
CV_ASSERT( dst->height == rect.height );
|
||||
|
||||
if( angle == 0 && shear.x == 0 && shear.y == 0 &&
|
||||
rect.x >= 0 && rect.y >= 0 &&
|
||||
rect.x + rect.width < img->width && rect.y + rect.height < img->height )
|
||||
{
|
||||
CvMat subimg;
|
||||
cvGetSubRect( img, &subimg, rect );
|
||||
cvConvert( &subimg, dst );
|
||||
}
|
||||
else if( shear.x == 0 && shear.y == 0 )
|
||||
{
|
||||
int x, y;
|
||||
float xp, yp;
|
||||
double c = cos( -M_PI / 180 * angle );
|
||||
double s = sin( -M_PI / 180 * angle );
|
||||
CvScalar color;
|
||||
/*CvMat* R = cvCreateMat( 2, 3, CV_32FC1 );
|
||||
cv2DRotationMatrix( cvPoint2D32f( 0, 0 ), angle, 1.0, R );
|
||||
double c = cvmGet( R, 0, 0 );
|
||||
double s = cvmGet( R, 1, 0 );
|
||||
cvReleaseMat( &R );*/
|
||||
cvZero( dst );
|
||||
|
||||
for( x = 0; x < rect.width; x++ )
|
||||
{
|
||||
for( y = 0; y < rect.height; y++ )
|
||||
{
|
||||
xp = ( c * x + -s * y ) + rect.x;
|
||||
yp = ( s * x + c * y ) + rect.y;
|
||||
if( xp <= -0.5 || xp >= img->width - 0.5 || yp <= -0.5 || yp >= img->height - 0.5 ) continue;
|
||||
color = cvGet2DInter( img, yp, xp, interpolation );
|
||||
cvSet2D( dst, y, x, color );
|
||||
//xp = cvRound( c * x + -s * y ) + rect.x;
|
||||
//yp = cvRound( s * x + c * y ) + rect.y;
|
||||
//if( xp < 0 || xp >= img->width || yp < 0 || yp >= img->height ) continue;
|
||||
//for( ch = 0; ch < img->nChannels; ch++ )
|
||||
//{
|
||||
// dst->imageData[dst->widthStep * y + x * dst->nChannels + ch]
|
||||
// = img->imageData[img->widthStep * yp + xp * img->nChannels + ch];
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int x, y;
|
||||
float xp, yp;
|
||||
CvScalar color;
|
||||
CvMat* affine = cvCreateMat( 2, 3, CV_32FC1 );
|
||||
CvMat* xy = cvCreateMat( 3, 1, CV_32FC1 );
|
||||
CvMat* xyp = cvCreateMat( 2, 1, CV_32FC1 );
|
||||
cvCreateAffine( affine, rect32f, shear );
|
||||
cvmSet( xy, 2, 0, 1.0 );
|
||||
cvZero( dst );
|
||||
|
||||
for( x = 0; x < rect.width; x++ )
|
||||
{
|
||||
cvmSet( xy, 0, 0, x / rect32f.width );
|
||||
for( y = 0; y < rect.height; y++ )
|
||||
{
|
||||
cvmSet( xy, 1, 0, y / rect32f.height );
|
||||
cvMatMul( affine, xy, xyp );
|
||||
xp = cvmGet( xyp, 0, 0 );
|
||||
yp = cvmGet( xyp, 1, 0 );
|
||||
if( xp <= -0.5 || xp >= img->width - 0.5 || yp <= -0.5 || yp >= img->height - 0.5 ) continue;
|
||||
color = cvGet2DInter( img, yp, xp, interpolation );
|
||||
cvSet2D( dst, y, x, color );
|
||||
//xp = cvRound( cvmGet( xyp, 0, 0 ) );
|
||||
//yp = cvRound( cvmGet( xyp, 1, 0 ) );
|
||||
//if( xp < 0 || xp >= img->width || yp < 0 || yp >= img->height ) continue;
|
||||
//for( ch = 0; ch < img->nChannels; ch++ )
|
||||
//{
|
||||
// dst->imageData[dst->widthStep * y + x * dst->nChannels + ch]
|
||||
// = img->imageData[img->widthStep * yp + xp * img->nChannels + ch];
|
||||
//}
|
||||
}
|
||||
}
|
||||
cvReleaseMat( &affine );
|
||||
cvReleaseMat( &xy );
|
||||
cvReleaseMat( &xyp );
|
||||
}
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crop and show the Cropped Image
|
||||
*
|
||||
* @param w_name Window name
|
||||
* @param img Image to be cropped
|
||||
* @param rect32f The rectangle region (x,y,width,height) to crop and
|
||||
* the rotation angle in degree
|
||||
* @param shear The shear deformation parameter shx and shy
|
||||
* @return CVAPI(void)
|
||||
* @uses cvCropImageROI
|
||||
*/
|
||||
CV_INLINE void
|
||||
cvShowCroppedImage( const char* w_name, IplImage* img,
|
||||
CvRect32f rect32f CV_DEFAULT(cvRect32f(0,0,1,1,0)),
|
||||
CvPoint2D32f shear CV_DEFAULT(cvPoint2D32f(0,0)) )
|
||||
{
|
||||
CvRect rect = cvRectFromRect32f( rect32f );
|
||||
if( rect.width <= 0 || rect.height <= 0 ) return;
|
||||
IplImage* crop = cvCreateImage( cvSize( rect.width, rect.height ), img->depth, img->nChannels );
|
||||
cvCropImageROI( img, crop, rect32f, shear );
|
||||
cvShowImage( w_name, crop );
|
||||
cvReleaseImage( &crop );
|
||||
}
|
||||
|
||||
|
||||
#endif
|
216
3rdparty/include/opencvx/cvdrawrectangle.h
vendored
Normal file
216
3rdparty/include/opencvx/cvdrawrectangle.h
vendored
Normal file
@ -0,0 +1,216 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_DRAWRECTANGLE_INCLUDED
|
||||
#define CV_DRAWRECTANGLE_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#include "cvcreateaffine.h"
|
||||
#include "cvrect32f.h"
|
||||
|
||||
//CVAPI(void)
|
||||
//cvDrawRectangle( IplImage* img,
|
||||
// CvRect32f rect32f = cvRect32f(0,0,1,1,0),
|
||||
// CvPoint2D32f shear = cvPoint2D32f(0,0),
|
||||
// CvScalar color = CV_RGB(255, 255, 255),
|
||||
// int thickness = 1,
|
||||
// int line_type = 8,
|
||||
// int shift = 0 );
|
||||
//CV_INLINE void
|
||||
//cvShowImageAndRectangle( const char* w_name, const IplImage* img,
|
||||
// CvRect32f rect32f = cvRect32f(0,0,1,1,0),
|
||||
// CvPoint2D32f shear = cvPoint2D32f(0,0),
|
||||
// CvScalar color = CV_RGB(255, 255, 0),
|
||||
// int thickness = 1, int line_type = 8,
|
||||
// int shift = 0 );
|
||||
|
||||
/**
|
||||
* Draw an rotated and sheared rectangle
|
||||
*
|
||||
* If you want define rotation center as the center of the rectangle,
|
||||
* use CvBox32f and use cvRect32fBox32( box32f ) for the rect32f argument.
|
||||
*
|
||||
* @param img The image to be drawn rectangle
|
||||
* @param rect32f The rectangle (x,y,width,height) to be shown and
|
||||
* the rotation angle in degree where the rotation center is (x,y)
|
||||
* @param shear The shear deformation parameter shx and shy
|
||||
* @param color Line color (RGB) or brightness (grayscale image).
|
||||
* @param thickness Thickness of lines that make up the rectangle.
|
||||
* Negative values, e.g. CV_FILLED, make the function
|
||||
* to draw a filled rectangle.
|
||||
* @param line_type Type of the line, see cvLine description.
|
||||
* @param shift Number of fractional bits in the point coordinates.
|
||||
* @todo thickness, line_type, and shift are available only when rotate == 0 && shear == 0 currently.
|
||||
* @return CVAPI(void)
|
||||
* @uses cvRectangle
|
||||
*/
|
||||
CVAPI(void)
|
||||
cvDrawRectangle( IplImage* img,
|
||||
CvRect32f rect32f CV_DEFAULT(cvRect32f(0,0,1,1,0)),
|
||||
CvPoint2D32f shear CV_DEFAULT(cvPoint2D32f(0,0)),
|
||||
CvScalar color CV_DEFAULT(CV_RGB(255, 255, 255)),
|
||||
int thickness CV_DEFAULT(1),
|
||||
int line_type CV_DEFAULT(8),
|
||||
int shift CV_DEFAULT(0) )
|
||||
{
|
||||
CvRect rect = cvRectFromRect32f( rect32f );
|
||||
float angle = rect32f.angle;
|
||||
CV_FUNCNAME( "cvDrawRectangle" );
|
||||
__CV_BEGIN__;
|
||||
CV_ASSERT( rect.width > 0 && rect.height > 0 );
|
||||
|
||||
if( angle == 0 && shear.x == 0 && shear.y == 0 )
|
||||
{
|
||||
CvPoint pt1 = cvPoint( rect.x, rect.y );
|
||||
CvPoint pt2 = cvPoint( rect.x + rect.width - 1, rect.y + rect.height - 1 );
|
||||
cvRectangle( img, pt1, pt2, color, thickness, line_type, shift );
|
||||
}
|
||||
else if( shear.x == 0 && shear.y == 0 )
|
||||
{
|
||||
int x, y, ch, xp, yp;
|
||||
double c = cos( -M_PI / 180 * angle );
|
||||
double s = sin( -M_PI / 180 * angle );
|
||||
/*CvMat* R = cvCreateMat( 2, 3, CV_32FC1 );
|
||||
cv2DRotationMatrix( cvPoint2D32f( 0, 0 ), angle, 1.0, R );
|
||||
double c = cvmGet( R, 0, 0 );
|
||||
double s = cvmGet( R, 1, 0 );
|
||||
cvReleaseMat( &R );*/
|
||||
|
||||
for( x = 0; x < rect.width; x++ )
|
||||
{
|
||||
for( y = 0; y < rect.height; y += MAX(1, rect.height - 1) )
|
||||
{
|
||||
xp = cvRound( c * x + -s * y ) + rect.x;
|
||||
yp = cvRound( s * x + c * y ) + rect.y;
|
||||
if( xp < 0 || xp >= img->width || yp < 0 || yp >= img->height ) continue;
|
||||
for( ch = 0; ch < img->nChannels; ch++ )
|
||||
{
|
||||
img->imageData[img->widthStep * yp + xp * img->nChannels + ch] = (char)color.val[ch];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( y = 0; y < rect.height; y++ )
|
||||
{
|
||||
for( x = 0; x < rect.width; x += MAX( 1, rect.width - 1) )
|
||||
{
|
||||
xp = cvRound( c * x + -s * y ) + rect.x;
|
||||
yp = cvRound( s * x + c * y ) + rect.y;
|
||||
if( xp < 0 || xp >= img->width || yp < 0 || yp >= img->height ) continue;
|
||||
for( ch = 0; ch < img->nChannels; ch++ )
|
||||
{
|
||||
img->imageData[img->widthStep * yp + xp * img->nChannels + ch] = (char)color.val[ch];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int x, y, ch, xp, yp;
|
||||
CvMat* affine = cvCreateMat( 2, 3, CV_32FC1 );
|
||||
CvMat* xy = cvCreateMat( 3, 1, CV_32FC1 );
|
||||
CvMat* xyp = cvCreateMat( 2, 1, CV_32FC1 );
|
||||
cvmSet( xy, 2, 0, 1.0 );
|
||||
cvCreateAffine( affine, rect32f, shear );
|
||||
|
||||
for( x = 0; x < rect.width; x++ )
|
||||
{
|
||||
cvmSet( xy, 0, 0, x / rect32f.width );
|
||||
for( y = 0; y < rect.height; y += MAX(1, rect.height - 1) )
|
||||
{
|
||||
cvmSet( xy, 1, 0, y / rect32f.height );
|
||||
cvMatMul( affine, xy, xyp );
|
||||
xp = cvRound( cvmGet( xyp, 0, 0 ) );
|
||||
yp = cvRound( cvmGet( xyp, 1, 0 ) );
|
||||
if( xp < 0 || xp >= img->width || yp < 0 || yp >= img->height ) continue;
|
||||
for( ch = 0; ch < img->nChannels; ch++ )
|
||||
{
|
||||
img->imageData[img->widthStep * yp + xp * img->nChannels + ch] = (char)color.val[ch];
|
||||
}
|
||||
}
|
||||
}
|
||||
for( y = 0; y < rect.height; y++ )
|
||||
{
|
||||
cvmSet( xy, 1, 0, y / rect32f.height );
|
||||
for( x = 0; x < rect.width; x += MAX( 1, rect.width - 1) )
|
||||
{
|
||||
cvmSet( xy, 0, 0, x / rect32f.width );
|
||||
cvMatMul( affine, xy, xyp );
|
||||
xp = cvRound( cvmGet( xyp, 0, 0 ) );
|
||||
yp = cvRound( cvmGet( xyp, 1, 0 ) );
|
||||
if( xp < 0 || xp >= img->width || yp < 0 || yp >= img->height ) continue;
|
||||
for( ch = 0; ch < img->nChannels; ch++ )
|
||||
{
|
||||
img->imageData[img->widthStep * yp + xp * img->nChannels + ch] = (char)color.val[ch];
|
||||
}
|
||||
}
|
||||
}
|
||||
cvReleaseMat( &affine );
|
||||
cvReleaseMat( &xy );
|
||||
cvReleaseMat( &xyp );
|
||||
}
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show Image and Rectangle
|
||||
*
|
||||
* @param w_name Window name
|
||||
* @param img Image to be shown
|
||||
* @param rect32f The rectangle (x,y,width,height) to be shown and
|
||||
* the rotation angle in degree where the rotation center is (x,y)
|
||||
* @param shear The shear deformation parameter shx and shy
|
||||
* @param color Line color (RGB) or brightness (grayscale image).
|
||||
* @param thickness Thickness of lines that make up the rectangle.
|
||||
* Negative values, e.g. CV_FILLED, make the function
|
||||
* to draw a filled rectangle.
|
||||
* @param line_type Type of the line, see cvLine description.
|
||||
* @param shift Number of fractional bits in the point coordinates.
|
||||
* @todo thickness, line_type, and shift are available only when angle == 0 && shear == 0 currently.
|
||||
* @return CVAPI(void)
|
||||
* @uses cvDrawRectangle
|
||||
*/
|
||||
CV_INLINE void
|
||||
cvShowImageAndRectangle( const char* w_name, const IplImage* img,
|
||||
CvRect32f rect32f CV_DEFAULT(cvRect32f(0,0,1,1,0)),
|
||||
CvPoint2D32f shear CV_DEFAULT(cvPoint2D32f(0,0)),
|
||||
CvScalar color CV_DEFAULT(CV_RGB(255, 255, 0)),
|
||||
int thickness CV_DEFAULT(1),
|
||||
int line_type CV_DEFAULT(8),
|
||||
int shift CV_DEFAULT(0) )
|
||||
{
|
||||
CvRect rect = cvRectFromRect32f( rect32f );
|
||||
if( rect.width <= 0 || rect.height <= 0 ) { cvShowImage( w_name, img ); return; }
|
||||
IplImage* clone = cvCloneImage( img );
|
||||
cvDrawRectangle( clone, rect32f, shear, color, thickness, line_type, shift );
|
||||
cvShowImage( w_name, clone );
|
||||
cvReleaseImage( &clone );
|
||||
}
|
||||
|
||||
|
||||
#endif
|
112
3rdparty/include/opencvx/cvgaussnorm.h
vendored
Normal file
112
3rdparty/include/opencvx/cvgaussnorm.h
vendored
Normal file
@ -0,0 +1,112 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_GAUSSNORM_INCLUDED
|
||||
#define CV_GAUSSNORM_INCLUDED
|
||||
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#include "cvmatelemcn.h"
|
||||
|
||||
// @todo
|
||||
// CVAPI(void) cvMatGaussNorm( const CvMat* samples, CvMat* dst );
|
||||
// #define cvGaussNorm( sample, dst ) cvMatGaussNorm( sample, dst )
|
||||
// CVAPI(void) cvImgGaussNorm( const IplImage* img, IplImage* normed ) {
|
||||
// IplImage* sample, samplehdr;
|
||||
// IplImage* dst, dsthdr;
|
||||
// sample = cvReshape( img, &samplehdr, 1, img->nChannels );
|
||||
// dst = cvReshape( normed, &dsthdr, 1, dst->nChannels );
|
||||
// // make sure how it is reshaped
|
||||
// cvMatGaussNorm( sample, dst );
|
||||
// }
|
||||
|
||||
/**
|
||||
* Zero mean and unit covariance normalization of an image
|
||||
* Each channel is processed independently
|
||||
*
|
||||
* @param src input image
|
||||
* @param dst normalized image. 32F or 64F should be preferred.
|
||||
*/
|
||||
CVAPI(void) cvGaussNormImage( const CvArr* src, CvArr* dst )
|
||||
{
|
||||
CvMat instub, *in = (CvMat*)src;
|
||||
CvMat outstub, *out = (CvMat*)dst;
|
||||
int coi = 0;
|
||||
CvScalar mean, std;
|
||||
int rows, cols, nChannels;
|
||||
int ch, row, col;
|
||||
CvScalar inval;
|
||||
CvMat *tmp_in;
|
||||
CvMat *sub_in;
|
||||
CV_FUNCNAME( "cvGaussNormImage" );
|
||||
__CV_BEGIN__;
|
||||
if( !CV_IS_MAT(in) )
|
||||
{
|
||||
CV_CALL( in = cvGetMat( in, &instub, &coi ) );
|
||||
if (coi != 0) CV_ERROR_FROM_CODE(CV_BadCOI);
|
||||
}
|
||||
if( !CV_IS_MAT(out) )
|
||||
{
|
||||
CV_CALL( out = cvGetMat( out, &outstub, &coi ) );
|
||||
if (coi != 0) CV_ERROR_FROM_CODE(CV_BadCOI);
|
||||
}
|
||||
CV_ASSERT( in->rows == out->rows && in->cols == out->cols );
|
||||
CV_ASSERT( CV_MAT_CN(in->type) == CV_MAT_CN(out->type) );
|
||||
|
||||
if( in->type != out->type ) {
|
||||
tmp_in = cvCreateMat( out->rows, out->cols, out->type );
|
||||
cvConvert( in, tmp_in );
|
||||
} else {
|
||||
tmp_in = in;
|
||||
}
|
||||
sub_in = cvCreateMat( out->rows, out->cols, out->type );
|
||||
|
||||
cvAvgSdv( tmp_in, &mean, &std );
|
||||
cvSubS( tmp_in, mean, sub_in );
|
||||
//cvScale( sub_in, out, 1.0/std.val[0] ); // do channel
|
||||
rows = out->rows;
|
||||
cols = out->cols;
|
||||
nChannels = CV_MAT_CN(out->type);
|
||||
for( row = 0; row < rows; row++ ) {
|
||||
for( col = 0; col < cols; col++ ) {
|
||||
inval = cvGet2D( sub_in, row, col );
|
||||
for( ch = 0; ch < nChannels; ch++ ) {
|
||||
inval.val[ch] /= std.val[ch];
|
||||
}
|
||||
cvSet2D( out, row, col, inval );
|
||||
}
|
||||
}
|
||||
|
||||
if( in->type != out->type ) {
|
||||
cvReleaseMat( &tmp_in );
|
||||
}
|
||||
cvReleaseMat( &sub_in );
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
175
3rdparty/include/opencvx/cvgausspdf.h
vendored
Normal file
175
3rdparty/include/opencvx/cvgausspdf.h
vendored
Normal file
@ -0,0 +1,175 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_GAUSSPDF_INCLUDED
|
||||
#define CV_GAUSSPDF_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
//CVAPI(void)
|
||||
//cvMatGaussPdf( const CvMat* samples, const CvMat* mean, const CvMat* cov,
|
||||
// CvMat* probs, bool normalize = false, bool logprob = false );
|
||||
//CV_INLINE double
|
||||
//cvGaussPdf( const CvMat* sample, const CvMat* mean, const CvMat* cov,
|
||||
// bool normalize = false, bool logprob = false );
|
||||
|
||||
/**
|
||||
* Compute multivariate gaussian pdf for a set of sample vectors
|
||||
*
|
||||
* Example)
|
||||
* @code
|
||||
* double vs[] = { 3, 4, 5,
|
||||
* 3, 4, 5 }; // col vectors
|
||||
* double m[] = { 5,
|
||||
* 5 };
|
||||
* double a[] = { 1, 0,
|
||||
* 0, 1 };
|
||||
* CvMat vecs = cvMat(2, 3, CV_64FC1, vs);
|
||||
* CvMat mean = cvMat(2, 1, CV_64FC1, m);
|
||||
* CvMat cov = cvMat(2, 2, CV_64FC1, a);
|
||||
* CvMat *probs = cvCreateMat(1, 3, CV_64FC1);
|
||||
* cvMatGaussPdf( &vecs, &mean, &cov, probs, false, false);
|
||||
* cvMatPrint( probs ); // 0.018316 0.367879 1.000000
|
||||
* cvMatGaussPdf( &vecs, &mean, &cov, probs, true, false);
|
||||
* cvMatPrint( probs ); // 0.002915 0.058550 0.159155
|
||||
* cvMatGaussPdf( &vecs, &mean, &cov, probs, false, true);
|
||||
* cvMatPrint( probs ); // -4.000000 -1.000000 -0.000000
|
||||
* cvMatGaussPdf( &vecs, &mean, &cov, probs, true, true);
|
||||
* cvMatPrint( probs ); // -5.837877 -2.837877 -1.837877
|
||||
* cvReleaseMat( &probs );
|
||||
* @endcode
|
||||
*
|
||||
* @param samples D x N data vectors where D is the number of
|
||||
* dimensions and N is the number of data
|
||||
* (Note: not N x D for clearness of matrix operation)
|
||||
* @param mean D x 1 mean vector
|
||||
* @param cov D x D covariance matrix
|
||||
* @param probs 1 x N computed probabilites
|
||||
* @param normalize Compute normalization term or not
|
||||
* @param logprob Log probability or not
|
||||
* @return CVAPI(void)
|
||||
* @see cvCalcCovarMatrix, cvAvg
|
||||
*/
|
||||
CVAPI(void)
|
||||
cvMatGaussPdf( const CvMat* samples,
|
||||
const CvMat* mean,
|
||||
const CvMat* cov,
|
||||
CvMat* probs,
|
||||
bool normalize CV_DEFAULT(true),
|
||||
bool logprob CV_DEFAULT(false) )
|
||||
{
|
||||
int D = samples->rows;
|
||||
int N = samples->cols;
|
||||
int type = samples->type;
|
||||
CV_FUNCNAME( "cvMatGaussPdf" ); // error handling
|
||||
__CV_BEGIN__;
|
||||
CV_ASSERT( CV_IS_MAT(samples) );
|
||||
CV_ASSERT( CV_IS_MAT(mean) );
|
||||
CV_ASSERT( CV_IS_MAT(cov) );
|
||||
CV_ASSERT( CV_IS_MAT(probs) );
|
||||
CV_ASSERT( D == mean->rows && 1 == mean->cols );
|
||||
CV_ASSERT( D == cov->rows && D == cov->cols );
|
||||
CV_ASSERT( 1 == probs->rows && N == probs->cols );
|
||||
|
||||
CvMat *invcov = cvCreateMat( D, D, type );
|
||||
cvInvert( cov, invcov, CV_SVD );
|
||||
|
||||
CvMat *sample = cvCreateMat( D, 1, type );
|
||||
CvMat *subsample = cvCreateMat( D, 1, type );
|
||||
CvMat *subsample_T = cvCreateMat( 1, D, type );
|
||||
CvMat *value = cvCreateMat( 1, 1, type );
|
||||
double prob;
|
||||
for( int n = 0; n < N; n++ )
|
||||
{
|
||||
cvGetCol( samples, sample, n );
|
||||
|
||||
cvSub( sample, mean, subsample );
|
||||
cvTranspose( subsample, subsample_T );
|
||||
cvMatMul( subsample_T, invcov, subsample_T );
|
||||
cvMatMul( subsample_T, subsample, value );
|
||||
prob = -0.5 * cvmGet(value, 0, 0);
|
||||
if( !logprob ) prob = exp( prob );
|
||||
|
||||
cvmSet( probs, 0, n, prob );
|
||||
}
|
||||
if( normalize )
|
||||
{
|
||||
double norm = pow( 2* M_PI, D/2.0 ) * sqrt( cvDet( cov ) );
|
||||
if( logprob ) cvSubS( probs, cvScalar( log( norm ) ), probs );
|
||||
else cvConvertScale( probs, probs, 1.0 / norm );
|
||||
}
|
||||
|
||||
cvReleaseMat( &invcov );
|
||||
cvReleaseMat( &sample );
|
||||
cvReleaseMat( &subsample );
|
||||
cvReleaseMat( &subsample_T );
|
||||
cvReleaseMat( &value );
|
||||
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute multivariate gaussian pdf
|
||||
*
|
||||
* Example)
|
||||
* @code
|
||||
* double v[] = { 3,
|
||||
* 3 };
|
||||
* double m[] = { 5,
|
||||
* 5 };
|
||||
* double a[] = { 1, 0,
|
||||
* 0, 1 };
|
||||
* CvMat vec = cvMat(2, 1, CV_64FC1, v);
|
||||
* CvMat mean = cvMat(2, 1, CV_64FC1, m);
|
||||
* CvMat cov = cvMat(2, 2, CV_64FC1, a);
|
||||
* std::cout << cvGaussPdf( &vec, &mean, &cov, false ) << std::endl;
|
||||
* @endcode
|
||||
*
|
||||
* @param sample D x 1 data vector
|
||||
* @param mean D x 1 mean vector
|
||||
* @param cov D x D covariance matrix
|
||||
* @param normalize Compute normalization term or not
|
||||
* @param logprob Log probability or not
|
||||
* @return double probability
|
||||
* @see cvCalcCovarMatrix, cvAvg
|
||||
* @see cvMatGaussPdf
|
||||
*/
|
||||
CV_INLINE double
|
||||
cvGaussPdf( const CvMat* sample, const CvMat* mean, const CvMat* cov,
|
||||
bool normalize CV_DEFAULT(true), bool logprob CV_DEFAULT(false) )
|
||||
{
|
||||
double prob;
|
||||
CvMat *_probs = cvCreateMat( 1, 1, sample->type );
|
||||
|
||||
cvMatGaussPdf( sample, mean, cov, _probs, normalize, logprob );
|
||||
prob = cvmGet(_probs, 0, 0);
|
||||
|
||||
cvReleaseMat( &_probs );
|
||||
return prob;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
161
3rdparty/include/opencvx/cvget2dinter.h
vendored
Normal file
161
3rdparty/include/opencvx/cvget2dinter.h
vendored
Normal file
@ -0,0 +1,161 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_GET2D_INTER_INCLUDED
|
||||
#define CV_GET2D_LINEAR_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
/**
|
||||
* Nearest Neighbor Interpolation
|
||||
*
|
||||
* Get a color at a floating position using nearest neighbor (round) method.
|
||||
*
|
||||
* @param arr array
|
||||
* @param row
|
||||
* @param col
|
||||
* @return color
|
||||
* @see cvInterLinear
|
||||
*/
|
||||
CVAPI(CvScalar)
|
||||
icvGet2DInterNn( const CvArr *arr, float row, float col )
|
||||
{
|
||||
IplImage* img, imgstub;
|
||||
int ix, iy;
|
||||
CvScalar color;
|
||||
CV_FUNCNAME( "cvInterNn" );
|
||||
__CV_BEGIN__;
|
||||
img = (IplImage*)arr;
|
||||
if( !CV_IS_IMAGE(img) )
|
||||
{
|
||||
CV_CALL( img = cvGetImage( img, &imgstub ) );
|
||||
}
|
||||
ix = cvRound( col );
|
||||
iy = cvRound( row );
|
||||
color = cvGet2D( img, iy, ix );
|
||||
__CV_END__;
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bilinear Interpolation
|
||||
*
|
||||
* Get a color at a floating position using bilinear interpolation method
|
||||
* Floating origin is the center of (0,0) pixel.
|
||||
*
|
||||
* @param arr array
|
||||
* @param row
|
||||
* @param col
|
||||
* @return color
|
||||
*/
|
||||
CVAPI(CvScalar)
|
||||
icvGet2DInterLinear( const CvArr *arr, float row, float col )
|
||||
{
|
||||
IplImage* img, imgstub;
|
||||
int ix, iy;
|
||||
float dx, dy;
|
||||
CvPoint pt[4];
|
||||
CvScalar c[4];
|
||||
CvScalar color;
|
||||
int i, ch;
|
||||
CV_FUNCNAME( "cvInterLinear" );
|
||||
__CV_BEGIN__;
|
||||
img = (IplImage*)arr;
|
||||
if( !CV_IS_IMAGE(img) )
|
||||
{
|
||||
CV_CALL( img = cvGetImage( img, &imgstub ) );
|
||||
}
|
||||
ix = cvFloor( col );
|
||||
iy = cvFloor( row );
|
||||
dx = col - ix;
|
||||
dy = row - iy;
|
||||
if( ix < 0 ) { // out of left
|
||||
pt[0].x = pt[1].x = pt[2].x = pt[3].x = 0;
|
||||
} else if( ix > img->width - 2 ) { // out of right
|
||||
pt[0].x = pt[1].x = pt[2].x = pt[3].x = img->width - 2;
|
||||
} else { // inside
|
||||
pt[0].x = pt[2].x = ix;
|
||||
pt[1].x = pt[3].x = ix + 1;
|
||||
}
|
||||
if( iy < 0 ) { // out of top
|
||||
pt[0].y = pt[1].y = pt[2].y = pt[3].y = 0;
|
||||
} else if( iy > img->height - 2 ) { // out of bottom
|
||||
pt[0].y = pt[1].y = pt[2].y = pt[3].y = img->height - 2;
|
||||
} else { // inside
|
||||
pt[0].y = pt[1].y = iy;
|
||||
pt[2].y = pt[3].y = iy + 1;
|
||||
}
|
||||
for( i = 0; i < 4; i++ )
|
||||
c[i] = cvGet2D( img, pt[i].y, pt[i].x );
|
||||
|
||||
for( ch = 0; ch < img->nChannels; ch++ )
|
||||
{
|
||||
color.val[ch] = ( c[0].val[ch] * dx + c[1].val[ch] * (1 - dx) ) * dy
|
||||
+ ( c[2].val[ch] * dx + c[3].val[ch] * (1 - dx) ) * (1 - dy);
|
||||
}
|
||||
__CV_END__;
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an element of array with interpolation method
|
||||
*
|
||||
* Get a color at a floating position using an interpolation method.
|
||||
* Floating origin is the center of (0,0) pixel.
|
||||
*
|
||||
* @param arr array
|
||||
* @param row floating row position
|
||||
* @param col floating col position
|
||||
* @param inter The interpolation method.
|
||||
* - CV_INTER_NN - Nearest Neighborhood method
|
||||
* - CV_INTER_LINEAR - Bilinear interpolation
|
||||
* @return color
|
||||
* @see cvResize has "interpolation" method,
|
||||
* but it was not reusable.
|
||||
*/
|
||||
CVAPI(CvScalar)
|
||||
cvGet2DInter( const CvArr *arr, float row, float col,
|
||||
int inter CV_DEFAULT(CV_INTER_LINEAR) )
|
||||
{
|
||||
CvScalar color;
|
||||
CV_FUNCNAME( "cvGet2DInter" );
|
||||
__CV_BEGIN__;
|
||||
switch( inter )
|
||||
{
|
||||
case CV_INTER_NN:
|
||||
color = icvGet2DInterNn( arr, row, col );
|
||||
break;
|
||||
case CV_INTER_LINEAR:
|
||||
color = icvGet2DInterLinear( arr, row, col );
|
||||
break;
|
||||
default:
|
||||
CV_ERROR( 0, "No such interpolation method is available." );
|
||||
break;
|
||||
}
|
||||
__CV_END__;
|
||||
return color;
|
||||
}
|
||||
|
||||
#endif
|
167
3rdparty/include/opencvx/cvgmmpdf.h
vendored
Normal file
167
3rdparty/include/opencvx/cvgmmpdf.h
vendored
Normal file
@ -0,0 +1,167 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_GMMPDF_INCLUDED
|
||||
#define CV_GMMPDF_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#include "cvgausspdf.h"
|
||||
|
||||
//CVAPI(void)
|
||||
//cvMatGmmPdf( const CvMat* samples, const CvMat* means, CvMat** covs,
|
||||
// const CvMat* weights, CvMat* probs, bool normalize = false );
|
||||
//CV_INLINE double
|
||||
//cvGmmPdf( const CvMat* sample, const CvMat* means, CvMat** covs,
|
||||
// const CvMat* weights, CvMat* probs = NULL, bool normalize = false );
|
||||
|
||||
/**
|
||||
* Compute gaussian mixture pdf for a set of sample vectors
|
||||
*
|
||||
* Example)
|
||||
* @code
|
||||
* const int D = 2;
|
||||
* const int N = 3;
|
||||
* const int K = 2;
|
||||
*
|
||||
* double vs[] = { 3, 4, 5,
|
||||
* 3, 4, 5 }; * col vectors
|
||||
* double ms[] = { 3, 5,
|
||||
* 3, 5 }; * col vectors
|
||||
* double cs0[] = { 1, 0,
|
||||
* 0, 1 };
|
||||
* double cs1[] = { 1, 0.1,
|
||||
* 0.1, 1 };
|
||||
* double ws[] = { 0.5, 0.5 };
|
||||
*
|
||||
* CvMat vecs = cvMat(D, N, CV_64FC1, vs);
|
||||
* CvMat means = cvMat(D, K, CV_64FC1, ms);
|
||||
* CvMat **covs = (CvMat**)cvAlloc( K * sizeof(*covs) );
|
||||
* covs[0] = &cvMat(D, D, CV_64FC1, cs0);
|
||||
* covs[1] = &cvMat(D, D, CV_64FC1, cs0);
|
||||
* CvMat weights = cvMat( 1, K, CV_64FC1, ws);
|
||||
* CvMat *probs = cvCreateMat(K, N, CV_64FC1);
|
||||
* cvMatGmmPdf( &vecs, &means, covs, &weights, probs, false);
|
||||
* cvMatPrint( probs );
|
||||
* cvReleaseMat( &probs );
|
||||
* cvFree( &covs );
|
||||
* @endcode
|
||||
*
|
||||
* @param samples D x N data vector (Note: not N x D for clearness of matrix operation)
|
||||
* @param means D x K mean vector
|
||||
* @param covs (D x D) x K covariance matrix for each cluster
|
||||
* @param weights 1 x K weights
|
||||
* @param probs K x N or 1 x N computed probabilites
|
||||
* @param normalize Compute normalization term or not
|
||||
* @see cvGaussPdf
|
||||
*/
|
||||
CVAPI(void)
|
||||
cvMatGmmPdf( const CvMat* samples, const CvMat* means, CvMat** covs,
|
||||
const CvMat* weights, CvMat* probs, bool normalize CV_DEFAULT(true) )
|
||||
{
|
||||
int D = samples->rows;
|
||||
int N = samples->cols;
|
||||
int K = means->cols;
|
||||
int type = samples->type;
|
||||
CV_FUNCNAME( "cvMatGmmPdf" ); // error handling
|
||||
__CV_BEGIN__;
|
||||
CV_ASSERT( CV_IS_MAT(samples) );
|
||||
CV_ASSERT( CV_IS_MAT(means) );
|
||||
for( int k = 0; k < K; k++ )
|
||||
CV_ASSERT( CV_IS_MAT(covs[k]) );
|
||||
CV_ASSERT( CV_IS_MAT(weights) );
|
||||
CV_ASSERT( CV_IS_MAT(probs) );
|
||||
CV_ASSERT( D == means->rows );
|
||||
for( int k = 0; k < K; k++ )
|
||||
CV_ASSERT( D == covs[k]->rows && D == covs[k]->cols ); // D x D
|
||||
CV_ASSERT( 1 == weights->rows && K == weights->cols ); // 1 x K
|
||||
CV_ASSERT( ( 1 == probs->rows || K == probs->rows ) && N == probs->cols ); // 1 x N or K x N
|
||||
|
||||
CvMat *mean = cvCreateMat( D, 1, type );
|
||||
const CvMat *cov;
|
||||
CvMat *_probs = cvCreateMat( 1, N, type );
|
||||
cvZero( probs );
|
||||
for( int k = 0; k < K; k++ )
|
||||
{
|
||||
cvGetCol( means, mean, k );
|
||||
cov = covs[k];
|
||||
cvMatGaussPdf( samples, mean, cov, _probs, normalize );
|
||||
cvConvertScale( _probs, _probs, cvmGet( weights, 0, k ) );
|
||||
if( 1 == probs->rows )
|
||||
{
|
||||
cvAdd( probs, _probs, probs );
|
||||
}
|
||||
else
|
||||
{
|
||||
for( int n = 0; n < N; n++ )
|
||||
{
|
||||
cvmSet( probs, k, n, cvmGet( _probs, 0, n ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cvReleaseMat( &mean );
|
||||
cvReleaseMat( &_probs );
|
||||
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute gaussian mixture pdf
|
||||
*
|
||||
* @param sample D x 1 sample vector
|
||||
* @param means D x K mean vector for each cluster
|
||||
* @param covs (D x D) x K covariance matrix for each cluster
|
||||
* @param weights 1 x K weights
|
||||
* @param probs K x 1 probabilities for each cluster if want
|
||||
* @param normalize use normalization term or not
|
||||
* @return double prob
|
||||
* @see cvMatGmmPdf
|
||||
*/
|
||||
CV_INLINE double
|
||||
cvGmmPdf( const CvMat* sample, const CvMat* means, CvMat** covs,
|
||||
const CvMat* weights, CvMat* probs CV_DEFAULT(NULL), bool normalize CV_DEFAULT(true) )
|
||||
{
|
||||
double prob;
|
||||
CvMat* _probs;
|
||||
int K = means->cols;
|
||||
if( probs )
|
||||
_probs = probs;
|
||||
else
|
||||
_probs = cvCreateMat( K, 1, sample->type );
|
||||
|
||||
cvMatGmmPdf( sample, means, covs, weights, _probs, normalize );
|
||||
prob = cvSum( _probs ).val[0];
|
||||
|
||||
if( !probs )
|
||||
cvReleaseMat( &probs );
|
||||
return prob;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
80
3rdparty/include/opencvx/cvhaarlike.h
vendored
Normal file
80
3rdparty/include/opencvx/cvhaarlike.h
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
/** @file
|
||||
* Haar-like features
|
||||
*
|
||||
* You need to set include path to opencvx/HaarTraining such as
|
||||
* g++ -Iopencvx/HaarTraining
|
||||
*
|
||||
* @see samples/cvhaarlike.cpp
|
||||
**/
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_HAARLIKE_INCLUDED
|
||||
#define CV_HAARLIKE_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
// cvIntegral( img, sum )
|
||||
|
||||
// @see HaarTraining/cvhaartraing.h/cpp
|
||||
// CvIntHaarFeatures* haar = icvCreateIntHaarFeatures( cvGetSize(sum), 0, 0 );
|
||||
|
||||
// @see HaarTraining/_cvhaartraining.h
|
||||
// typedef struct CvTHaarFeature
|
||||
// {
|
||||
// char desc[CV_HAAR_FEATURE_DESC_MAX];
|
||||
// int tilted;
|
||||
// struct
|
||||
// {
|
||||
// CvRect r;
|
||||
// float weight;
|
||||
// } rect[CV_HAAR_FEATURE_MAX];
|
||||
// } CvTHaarFeature;
|
||||
//
|
||||
// typedef struct CvFastHaarFeature
|
||||
// {
|
||||
// int tilted;
|
||||
// struct
|
||||
// {
|
||||
// int p0, p1, p2, p3;
|
||||
// float weight;
|
||||
// } rect[CV_HAAR_FEATURE_MAX];
|
||||
// } CvFastHaarFeature;
|
||||
//
|
||||
// typedef struct CvIntHaarFeatures
|
||||
// {
|
||||
// CvSize winsize;
|
||||
// int count;
|
||||
// CvTHaarFeature* feature;
|
||||
// CvFastHaarFeature* fastfeature;
|
||||
// } CvIntHaarFeatures;
|
||||
|
||||
#include "HaarTraining/cvhaartraining.h"
|
||||
#include "HaarTraining/cvhaartraining.cpp"
|
||||
#include "HaarTraining/cvboost.cpp"
|
||||
#include "HaarTraining/cvhaarclassifier.cpp"
|
||||
#include "HaarTraining/cvcommon.cpp"
|
||||
#include "HaarTraining/cvsamples.cpp"
|
||||
|
||||
#endif
|
60
3rdparty/include/opencvx/cvinvaffine.h
vendored
Normal file
60
3rdparty/include/opencvx/cvinvaffine.h
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_INVAFFINE_INCLUDED
|
||||
#define CV_INVAFFINE_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
#include "cvsetrow.h"
|
||||
|
||||
/**
|
||||
* Create an inv affine transform matrix from an affine transform matrix
|
||||
*
|
||||
* @param affine The 2 x 3 CV_32FC1|CV_64FC1 affine matrix
|
||||
* @param invaffine The 2 x 3 CV_32FC1|CV_64FC1 affine matrix to be created
|
||||
*/
|
||||
CVAPI(void) cvInvAffine( const CvMat* affine, CvMat* invaffine )
|
||||
{
|
||||
CvMat* Affine;
|
||||
CvMat* InvAffine;
|
||||
CV_FUNCNAME( "cvCreateAffine" );
|
||||
__CV_BEGIN__;
|
||||
CV_ASSERT( affine->rows == 2 && affine->cols == 3 );
|
||||
CV_ASSERT( invaffine->rows == 2 && invaffine->cols == 3 );
|
||||
CV_ASSERT( affine->type == invaffine->type );
|
||||
|
||||
Affine = cvCreateMat( 3, 3, affine->type );
|
||||
InvAffine = cvCreateMat( 3, 3, affine->type );
|
||||
cvSetIdentity( Affine );
|
||||
cvSetRows( affine, Affine, 0, 2 );
|
||||
cvInv( Affine, InvAffine );
|
||||
cvSetRows( InvAffine, invaffine, 0, 2 );
|
||||
cvReleaseMat( &Affine );
|
||||
cvReleaseMat( &InvAffine );
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
#endif
|
82
3rdparty/include/opencvx/cvipltocvdepth.h
vendored
Normal file
82
3rdparty/include/opencvx/cvipltocvdepth.h
vendored
Normal file
@ -0,0 +1,82 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_IPLTOCVDEPTH_INCLUDED
|
||||
#define CV_IPLTOCVDEPTH_INCLUDED
|
||||
|
||||
|
||||
#include "cv.h"
|
||||
|
||||
/**
|
||||
* Convert IplImage depth to CvMat depth
|
||||
*
|
||||
* Below codes would be useful as a reference:
|
||||
* @code
|
||||
* int depth, nChannels, type;
|
||||
* depth = CV_MAT_DEPTH(mat->type);
|
||||
* depth = img->depth;
|
||||
* nChannels = CV_MAT_CN(mat->type);
|
||||
* nChannels = img->nChannels;
|
||||
* type = CV_MAKETYPE(depth, nChannels);
|
||||
* type = mat->type;
|
||||
* type = cvElemType(mat);
|
||||
* type = cvElemType(img);
|
||||
* @endcode
|
||||
*
|
||||
* @param int IplImage depth
|
||||
* @return int cvMat depth
|
||||
* @reference cxcore/src/_cxcore.h#icvIplToCvDepth
|
||||
* @reference ./cxcore/src/cxtables.cpp
|
||||
* @see cvCvToIplDepth(mat->type)
|
||||
*/
|
||||
CVAPI(int) cvIplToCvDepth( int depth )
|
||||
{
|
||||
/*
|
||||
#define CV_8U 0
|
||||
#define CV_8S 1
|
||||
#define CV_16U 2
|
||||
#define CV_16S 3
|
||||
#define CV_32S 4
|
||||
#define CV_32F 5
|
||||
#define CV_64F 6
|
||||
#define CV_USRTYPE1 7 */
|
||||
/*
|
||||
#define IPL_DEPTH_SIGN 0x80000000
|
||||
#define IPL_DEPTH_1U 1
|
||||
#define IPL_DEPTH_8U 8
|
||||
#define IPL_DEPTH_16U 16
|
||||
#define IPL_DEPTH_32F 32
|
||||
#define IPL_DEPTH_64F 64
|
||||
#define IPL_DEPTH_8S (IPL_DEPTH_SIGN| 8)
|
||||
#define IPL_DEPTH_16S (IPL_DEPTH_SIGN|16)
|
||||
#define IPL_DEPTH_32S (IPL_DEPTH_SIGN|32) */
|
||||
static const signed char IplToCvDepth[] =
|
||||
{
|
||||
-1, -1, CV_8U, CV_8S, CV_16U, CV_16S, -1, -1,
|
||||
CV_32F, CV_32S, -1, -1, -1, -1, -1, -1, CV_64F, -1
|
||||
};
|
||||
return IplToCvDepth[(((depth) & 255) >> 2) + ((depth) < 0)];
|
||||
}
|
||||
|
||||
|
||||
#endif
|
44
3rdparty/include/opencvx/cvipltocvtype.h
vendored
Normal file
44
3rdparty/include/opencvx/cvipltocvtype.h
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_IPLTOCVDEPTH_INCLUDED
|
||||
#define CV_IPLTOCVDEPTH_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvipltocvdepth.h"
|
||||
|
||||
/**
|
||||
* Convert IplImage depth and nChannels to CvMat type
|
||||
*
|
||||
* @param depth IplImage depth. img->depth
|
||||
* @param nChannels Number of channels. img->nChannels
|
||||
* @return int CvMat type. mat->type
|
||||
*/
|
||||
CV_INLINE int cvIplToCvType( int ipl_depth, int nChannels )
|
||||
{
|
||||
int cvmat_depth = cvIplToCvDepth( ipl_depth );
|
||||
return CV_MAKETYPE( cvmat_depth, nChannels );
|
||||
}
|
||||
|
||||
|
||||
#endif
|
84
3rdparty/include/opencvx/cvlogsum.h
vendored
Normal file
84
3rdparty/include/opencvx/cvlogsum.h
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_LOGSUM_INCLUDED
|
||||
#define CV_LOGSUM_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
|
||||
/**
|
||||
* Compute log(sum) of log values
|
||||
*
|
||||
* Get log(a + b + c) from log(a), log(b), log(c)
|
||||
* Useful to take sum of probabilities from log probabilities
|
||||
* Useful to avoid loss of precision caused by taking exp
|
||||
*
|
||||
* @param arr array having log values. 32F or 64F
|
||||
* @return CvScalar log sum for each channel
|
||||
*/
|
||||
CVAPI(CvScalar) cvLogSum( const CvArr *arr )
|
||||
{
|
||||
IplImage* img = (IplImage*)arr, imgstub;
|
||||
IplImage *tmp, *tmp2;
|
||||
int ch;
|
||||
CvScalar sumval;
|
||||
CvScalar minval, maxval;
|
||||
CV_FUNCNAME( "cvLogSum" );
|
||||
__CV_BEGIN__;
|
||||
|
||||
if( !CV_IS_IMAGE(img) )
|
||||
{
|
||||
CV_CALL( img = cvGetImage( img, &imgstub ) );
|
||||
}
|
||||
tmp = cvCreateImage( cvGetSize(img), img->depth, img->nChannels );
|
||||
tmp2 = cvCreateImage( cvGetSize(img), img->depth, img->nChannels );
|
||||
|
||||
// to avoid loss of precision caused by taking exp as much as possible
|
||||
// if this trick is not required, cvExp -> cvSum are enough
|
||||
for( ch = 0; ch < img->nChannels; ch++ )
|
||||
{
|
||||
cvSetImageCOI( img, ch + 1 );
|
||||
cvMinMaxLoc( img, &minval.val[ch], &maxval.val[ch] );
|
||||
}
|
||||
cvSetImageCOI( img, 0 );
|
||||
cvSubS( img, maxval, tmp );
|
||||
|
||||
cvExp( tmp, tmp2 );
|
||||
sumval = cvSum( tmp2 );
|
||||
for( ch = 0; ch < img->nChannels; ch++ )
|
||||
{
|
||||
sumval.val[ch] = log( sumval.val[ch] ) + maxval.val[ch];
|
||||
}
|
||||
cvReleaseImage( &tmp );
|
||||
cvReleaseImage( &tmp2 );
|
||||
__CV_END__;
|
||||
return sumval;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
30
3rdparty/include/opencvx/cvmatelemcn.h
vendored
Normal file
30
3rdparty/include/opencvx/cvmatelemcn.h
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_MATELEMCN_INCLUDED
|
||||
#define CV_MATELEMCN_INCLUDED
|
||||
|
||||
#define CV_MAT_ELEM_CN( mat, elemtype, row, chcol ) \
|
||||
(*(elemtype*)((mat).data.ptr + (size_t)(mat).step*(row) + sizeof(elemtype)*(chcol)))
|
||||
|
||||
#endif
|
77
3rdparty/include/opencvx/cvmuls.h
vendored
Normal file
77
3rdparty/include/opencvx/cvmuls.h
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_MULS_INCLUDED
|
||||
#define CV_MULS_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
/**
|
||||
* Multiply a scalar to an array
|
||||
*
|
||||
* @param src source array
|
||||
* @param scalar scalar to multiply
|
||||
* @param dst destination array
|
||||
*/
|
||||
CVAPI(void) cvMulS( const CvArr *src, const CvScalar scalar, CvArr *dst )
|
||||
{
|
||||
IplImage* _src = (IplImage*)src, _srchdr;
|
||||
IplImage* _dst = (IplImage*)dst, _dsthdr;
|
||||
int ch, row, col;
|
||||
CV_FUNCNAME( "cvMulS" );
|
||||
__CV_BEGIN__;
|
||||
if( !CV_IS_IMAGE(_src) )
|
||||
{
|
||||
CV_CALL( _src = cvGetImage( _src, &_srchdr ) );
|
||||
}
|
||||
if( !CV_IS_IMAGE(_dst) )
|
||||
{
|
||||
CV_CALL( _dst = cvGetImage( _dst, &_dsthdr ) );
|
||||
}
|
||||
CV_ASSERT( _src->width == _dst->width );
|
||||
CV_ASSERT( _src->height == _dst->height );
|
||||
CV_ASSERT( _src->nChannels == _dst->nChannels );
|
||||
|
||||
// cvScale does not support COI
|
||||
// for( ch = 0; ch < _src->nChannels; ch++ )
|
||||
// {
|
||||
// cvSetImageCOI( _src, ch + 1 );
|
||||
// cvScale( _src, _dst, scalar.val[ch] );
|
||||
// }
|
||||
|
||||
for( row = 0; row < _src->height; row++ )
|
||||
{
|
||||
for( col = 0; col < _src->width; col++ )
|
||||
{
|
||||
CvScalar value = cvGet2D( _src, row, col );
|
||||
for( ch = 0; ch < _src->nChannels; ch++ )
|
||||
value.val[ch] *= scalar.val[ch];
|
||||
cvSet2D( _dst, row, col, value );
|
||||
}
|
||||
}
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
#endif
|
33
3rdparty/include/opencvx/cvmx.h
vendored
Normal file
33
3rdparty/include/opencvx/cvmx.h
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
/** @file
|
||||
* OpenCV versus Matlab C Library (MEX) interfaces
|
||||
* verified under OpenCV 1.00 and Matlab 2007b
|
||||
*/
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CVMX_INCLUDED
|
||||
#define CVMX_INCLUDED
|
||||
|
||||
#include "cvmxtypeconv.h"
|
||||
#include "cvmxmatconv.h"
|
||||
|
||||
#endif
|
214
3rdparty/include/opencvx/cvmxmatconv.h
vendored
Normal file
214
3rdparty/include/opencvx/cvmxmatconv.h
vendored
Normal file
@ -0,0 +1,214 @@
|
||||
/** @file
|
||||
* OpenCV versus Matlab C Library (MEX) interfaces
|
||||
* verified under OpenCV 1.00 and Matlab 2007b
|
||||
*
|
||||
* Matrix conversion
|
||||
*/
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CVMX_MATCONV_INCLUDED
|
||||
#define CVMX_MATCONV_INCLUDED
|
||||
|
||||
|
||||
#include "cv.h"
|
||||
#include "mat.h"
|
||||
#include "matrix.h"
|
||||
#include "cvmxtypeconv.h"
|
||||
|
||||
/**
|
||||
* Convert IplImage to mxArray. Allocate memory too
|
||||
*
|
||||
* Currently support only uint8, float, double
|
||||
* Currently support only 1 channel (grayscale) and 3 channels (rgb etc)
|
||||
*
|
||||
* @param img
|
||||
* @return mxArray*
|
||||
*/
|
||||
#define cvmxArrayFromIplImage(img) (cvmxArrayFromCvArr(img))
|
||||
|
||||
/**
|
||||
* Convert CvMat to mxArray. Allocate memory too
|
||||
*
|
||||
* Currently support only uint8, float, double
|
||||
* Currently support only 1 channel (grayscale) and 3 channels (rgb etc)
|
||||
*
|
||||
* @param mat
|
||||
* @return mxArray*
|
||||
*/
|
||||
#define cvmxArrayFromCvMat(mat) (cvmxArrayFromCvArr(mat))
|
||||
|
||||
/**
|
||||
* Convert CvArr to mxArray. Allocate memory too
|
||||
*
|
||||
* Currently support only uint8, float, double
|
||||
* Currently support only 1 channel (grayscale) and 3 channels (rgb etc)
|
||||
*
|
||||
* @param arr
|
||||
* @return mxArray*
|
||||
*/
|
||||
CVAPI(mxArray*) cvmxArrayFromCvArr(const CvArr* arr)
|
||||
{
|
||||
CV_FUNCNAME( "cvmxArraFromCvArr" );
|
||||
IplImage imghdr, *img = (IplImage*)arr;
|
||||
int nChannel, nRow, nCol, nDim;
|
||||
mwSize dims[3];
|
||||
mxClassID classid; mxArray* mxarr = NULL;
|
||||
int row, col, ch;
|
||||
|
||||
__CV_BEGIN__;
|
||||
if (!CV_IS_IMAGE(img)) {
|
||||
CV_CALL(img = cvGetImage(img, &imghdr));
|
||||
}
|
||||
nChannel = img->nChannels;
|
||||
nRow = img->height;
|
||||
nCol = img->width;
|
||||
nDim = 2;
|
||||
classid = cvmxClassIDFromIplDepth(img->depth);
|
||||
dims[0] = nRow; dims[1] = nCol; dims[2] = nChannel;
|
||||
if (nChannel > 1) nDim = 3;
|
||||
mxarr = mxCreateNumericArray(nDim, dims, classid, mxREAL);
|
||||
|
||||
if (classid == mxUINT8_CLASS) {
|
||||
unsigned char *mxData = (unsigned char*)mxGetData(mxarr);
|
||||
for (ch = 0; ch < nChannel; ch++) {
|
||||
for (row = 0; row < dims[0]; row++) {
|
||||
for (col = 0; col < dims[1]; col++) {
|
||||
mxData[dims[0] * dims[1] * ch + dims[0] * col + row]
|
||||
= CV_IMAGE_ELEM(img, unsigned char, row, nChannel * col + ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (classid == mxDOUBLE_CLASS) {
|
||||
double *mxData = (double*)mxGetData(mxarr);
|
||||
for (ch = 0; ch < nChannel; ch++) {
|
||||
for (row = 0; row < dims[0]; row++) {
|
||||
for (col = 0; col < dims[1]; col++) {
|
||||
mxData[dims[0] * dims[1] * ch + dims[0] * col + row]
|
||||
= CV_IMAGE_ELEM(img, double, row, nChannel * col + ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (classid == mxSINGLE_CLASS) {
|
||||
float *mxData = (float*)mxGetData(mxarr);
|
||||
for (ch = 0; ch < nChannel; ch++) {
|
||||
for (row = 0; row < dims[0]; row++) {
|
||||
for (col = 0; col < dims[1]; col++) {
|
||||
mxData[dims[0] * dims[1] * ch + dims[0] * col + row]
|
||||
= CV_IMAGE_ELEM(img, float, row, nChannel * col + ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
__CV_END__;
|
||||
return mxarr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert mxArray to IplImage. Allocate memory too
|
||||
*
|
||||
* Currently support only uint8, float, double
|
||||
* Currently support only 1 channel (grayscale) and 3 channels (rgb etc)
|
||||
*
|
||||
* @param mxarr
|
||||
* @return IplImage*
|
||||
*/
|
||||
CVAPI(IplImage*) cvmxArrayToIplImage(const mxArray* mxarr)
|
||||
{
|
||||
CV_FUNCNAME( "cvmxArrayToCvArr" );
|
||||
IplImage *img = NULL;
|
||||
int depth;
|
||||
mwSize nChannel = 1;
|
||||
mwSize nDim;
|
||||
const mwSize *dims;
|
||||
mxClassID classid;
|
||||
int row, col, ch;
|
||||
|
||||
__CV_BEGIN__;
|
||||
classid = mxGetClassID(mxarr);
|
||||
nDim = mxGetNumberOfDimensions(mxarr);
|
||||
dims = mxGetDimensions(mxarr);
|
||||
if (nDim >= 3) nChannel = dims[2];
|
||||
depth = cvmxClassIDToIplDepth(mxGetClassID(mxarr));
|
||||
img = cvCreateImage(cvSize(dims[1], dims[0]), depth, nChannel);
|
||||
|
||||
if (classid == mxUINT8_CLASS) {
|
||||
unsigned char *mxData = (unsigned char*)mxGetData(mxarr);
|
||||
for (ch = 0; ch < nChannel; ch++) {
|
||||
for (row = 0; row < dims[0]; row++) {
|
||||
for (col = 0; col < dims[1]; col++) {
|
||||
CV_IMAGE_ELEM(img, unsigned char, row, nChannel * col + ch)
|
||||
= mxData[dims[0] * dims[1] * ch + dims[0] * col + row];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (classid == mxDOUBLE_CLASS) {
|
||||
double *mxData = (double*)mxGetData(mxarr);
|
||||
for (ch = 0; ch < nChannel; ch++) {
|
||||
for (row = 0; row < dims[0]; row++) {
|
||||
for (col = 0; col < dims[1]; col++) {
|
||||
CV_IMAGE_ELEM(img, double, row, nChannel * col + ch)
|
||||
= mxData[dims[0] * dims[1] * ch + dims[0] * col + row];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (classid == mxSINGLE_CLASS) {
|
||||
float *mxData = (float*)mxGetData(mxarr);
|
||||
for (ch = 0; ch < nChannel; ch++) {
|
||||
for (row = 0; row < dims[0]; row++) {
|
||||
for (col = 0; col < dims[1]; col++) {
|
||||
CV_IMAGE_ELEM(img, float, row, nChannel * col + ch)
|
||||
= mxData[dims[0] * dims[1] * ch + dims[0] * col + row];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
__CV_END__;
|
||||
return img;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert mxArray to CvMat. Allocate memory too
|
||||
*
|
||||
* Currently support only uint8, float, double
|
||||
* Currently support only 1 channel (grayscale) and 3 channels (rgb etc)
|
||||
*
|
||||
* @param mxarr
|
||||
* @return CvMat*
|
||||
*/
|
||||
CVAPI(CvMat*) cvmxArrayToCvMat(const mxArray* mxarr)
|
||||
{
|
||||
IplImage* img = cvmxArrayToIplImage(mxarr);
|
||||
CvMat *mat = cvCreateMat(img->height, img->width, CV_MAKETYPE(cvmxIplToCvDepth(img->depth), img->nChannels));
|
||||
cvConvert(img, mat);
|
||||
cvReleaseImage(&img);
|
||||
// @todo: why cvGetMat results in error?
|
||||
//int coi = 0;
|
||||
//IplImage *img = cvmxArrayToIplImage(mxarr);
|
||||
//CvMat *mat, mathdr;
|
||||
//mat = cvGetMat(mat, &mathdr, &coi, 0);
|
||||
return mat;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
190
3rdparty/include/opencvx/cvmxtypeconv.h
vendored
Normal file
190
3rdparty/include/opencvx/cvmxtypeconv.h
vendored
Normal file
@ -0,0 +1,190 @@
|
||||
/** @file
|
||||
* OpenCV versus Matlab C Library (MEX) interfaces
|
||||
* verified under OpenCV 1.00 and Matlab 2007b
|
||||
*
|
||||
* Type conversion
|
||||
*/
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CVMX_TYPECONV_INCLUDED
|
||||
#define CVMX_TYPECONV_INCLUDED
|
||||
|
||||
|
||||
#include "cv.h"
|
||||
#include "mat.h"
|
||||
#include "matrix.h"
|
||||
#include "cvipltocvdepth.h"
|
||||
|
||||
/************** Definitions *******************************/
|
||||
#define cvmxCvToIplDepth(type) (cvCvToIplDepth(type))
|
||||
#define cvmxIplToCvDepth(depth) (cvIplToCvDepth(depth))
|
||||
//mxClassID cvmxClassIDFromIplDepth(int depth)
|
||||
//int cvmxClassIDToIplDepth(mxClassID classid)
|
||||
//CV_INLINE mxClassID cvmxClassIDFromCvDepth(int type)
|
||||
//CV_INLINE int cvmxClassIDToCvDepth(mxClassID classid)
|
||||
|
||||
/********************* Memo *******************************/
|
||||
/*
|
||||
* @reference cxcore/src/_cxcore.h#icvIplToCvDepth
|
||||
* @reference ./cxcore/src/cxtables.cpp
|
||||
*/
|
||||
/*
|
||||
#define CV_8U 0
|
||||
#define CV_8S 1
|
||||
#define CV_16U 2
|
||||
#define CV_16S 3
|
||||
#define CV_32S 4
|
||||
#define CV_32F 5
|
||||
#define CV_64F 6
|
||||
#define CV_USRTYPE1 7 */
|
||||
/*
|
||||
#define IPL_DEPTH_SIGN 0x80000000
|
||||
#define IPL_DEPTH_1U 1
|
||||
#define IPL_DEPTH_8U 8
|
||||
#define IPL_DEPTH_16U 16
|
||||
#define IPL_DEPTH_32F 32
|
||||
#define IPL_DEPTH_64F 64
|
||||
#define IPL_DEPTH_8S (IPL_DEPTH_SIGN| 8)
|
||||
#define IPL_DEPTH_16S (IPL_DEPTH_SIGN|16)
|
||||
#define IPL_DEPTH_32S (IPL_DEPTH_SIGN|32) */
|
||||
/*
|
||||
typedef enum {
|
||||
mxUNKNOWN_CLASS,
|
||||
mxCELL_CLASS,
|
||||
mxSTRUCT_CLASS,
|
||||
mxLOGICAL_CLASS,
|
||||
mxCHAR_CLASS,
|
||||
mxDOUBLE_CLASS,
|
||||
mxSINGLE_CLASS,
|
||||
mxINT8_CLASS,
|
||||
mxUINT8_CLASS,
|
||||
mxINT16_CLASS,
|
||||
mxUINT16_CLASS,
|
||||
mxINT32_CLASS,
|
||||
mxUINT32_CLASS,
|
||||
mxINT64_CLASS,
|
||||
mxUINT64_CLASS,
|
||||
mxFUNCTION_CLASS
|
||||
} mxClassID; */
|
||||
|
||||
/************** Functions *********************************/
|
||||
|
||||
/**
|
||||
* Get mxClassID from IplImage depth
|
||||
*
|
||||
* @param int depth IplImage depth
|
||||
* @return mxClassID
|
||||
* @see cvmxClassIDFromCvDepth
|
||||
* @see cvmxClassIDToCvDepth
|
||||
* @see cvmxClassIDFromIplDepth
|
||||
* @see cvmxClassIDToIplDepth
|
||||
* @see cvmxIplToCvDepth
|
||||
* @see cvCvToIplDepth
|
||||
*/
|
||||
CVAPI(mxClassID) cvmxClassIDFromIplDepth(int depth)
|
||||
{
|
||||
static const unsigned char ClassIDFromIplDepth[] =
|
||||
{
|
||||
0, 0, mxUINT8_CLASS, mxINT8_CLASS, mxUINT16_CLASS, mxINT16_CLASS, 0, 0,
|
||||
mxSINGLE_CLASS, mxINT32_CLASS, 0, 0, 0, 0, 0, 0, mxDOUBLE_CLASS, 0
|
||||
};
|
||||
if (depth == IPL_DEPTH_1U) {
|
||||
return mxLOGICAL_CLASS;
|
||||
} else {
|
||||
return (mxClassID)ClassIDFromIplDepth[(((depth) & 255) >> 2) + ((depth) < 0)];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert mxClassID to IplImage depth
|
||||
*
|
||||
* @param classid mxClassID of a mxArr
|
||||
* @return IplImage depth
|
||||
* @see cvmxClassIDFromCvDepth
|
||||
* @see cvmxClassIDToCvDepth
|
||||
* @see cvmxClassIDFromIplDepth
|
||||
* @see cvmxClassIDToIplDepth
|
||||
* @see cvmxIplToCvDepth
|
||||
* @see cvCvToIplDepth
|
||||
*/
|
||||
CVAPI(int) cvmxClassIDToIplDepth(mxClassID classid)
|
||||
{
|
||||
static const signed int ClassIDToIplDepth[] = {
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
IPL_DEPTH_1U,
|
||||
0,
|
||||
IPL_DEPTH_32F,
|
||||
IPL_DEPTH_64F,
|
||||
IPL_DEPTH_8S,
|
||||
IPL_DEPTH_8U,
|
||||
IPL_DEPTH_16S,
|
||||
IPL_DEPTH_16U,
|
||||
IPL_DEPTH_32S,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
};
|
||||
return ClassIDToIplDepth[classid];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mxClassID from cvMat type
|
||||
*
|
||||
* @param int cvMat type
|
||||
* @return mxClassID
|
||||
* @see cvmxClassIDFromCvDepth
|
||||
* @see cvmxClassIDToCvDepth
|
||||
* @see cvmxClassIDFromIplDepth
|
||||
* @see cvmxClassIDToIplDepth
|
||||
* @see cvmxIplToCvDepth
|
||||
* @see cvCvToIplDepth
|
||||
*/
|
||||
CV_INLINE mxClassID cvmxClassIDFromCvDepth(int type)
|
||||
{
|
||||
return cvmxClassIDFromIplDepth(cvCvToIplDepth(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert mxClassID to cvMat depth
|
||||
*
|
||||
* One may use CV_MAKETYPE(depth, nChannel) to create cvMat type
|
||||
*
|
||||
* @param mxClassID classid
|
||||
* @return int cvMat depth
|
||||
* @see cvmxClassIDFromCvDepth
|
||||
* @see cvmxClassIDToCvDepth
|
||||
* @see cvmxClassIDFromIplDepth
|
||||
* @see cvmxClassIDToIplDepth
|
||||
* @see cvmxIplToCvDepth
|
||||
* @see cvCvToIplDepth
|
||||
*/
|
||||
CV_INLINE int cvmxClassIDToCvDepth(mxClassID classid)
|
||||
{
|
||||
return cvmxIplToCvDepth(cvmxClassIDToIplDepth(classid));
|
||||
}
|
||||
|
||||
|
||||
#endif
|
54
3rdparty/include/opencvx/cvopening.h
vendored
Normal file
54
3rdparty/include/opencvx/cvopening.h
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_OPENING_INCLUDED
|
||||
#define CV_OPENING_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
/**
|
||||
* Opening morphological operation
|
||||
*
|
||||
* opening operation would help to remove noise
|
||||
*
|
||||
* @param src Input Array
|
||||
* @param dst Output Array
|
||||
* @param element Kernel shape. see cvErode or cvDilate
|
||||
* @param iterations
|
||||
* @return void
|
||||
*
|
||||
* References)
|
||||
* R. Gonzalez, R. Woods, "Digital Image Processing," chapter 9
|
||||
*/
|
||||
CV_INLINE void cvOpening( const CvArr* src, CvArr* dst,
|
||||
IplConvKernel* element CV_DEFAULT(NULL),
|
||||
int iterations CV_DEFAULT(1) )
|
||||
{
|
||||
cvErode( src, dst, element, iterations );
|
||||
cvDilate( dst, dst, element, iterations );
|
||||
}
|
||||
|
||||
|
||||
#endif
|
565
3rdparty/include/opencvx/cvparticle.h
vendored
Normal file
565
3rdparty/include/opencvx/cvparticle.h
vendored
Normal file
@ -0,0 +1,565 @@
|
||||
/*
|
||||
************************** SLEDOVANIE OBJEKTU VO VIDEU *************************
|
||||
********************************* Peter Betko **********************************
|
||||
|
||||
autor: Peter Betko
|
||||
datum: 11.10.2011
|
||||
|
||||
Program na sledovanie objektu vo videu, s vyuzitim algoritmov zalozenych na baze
|
||||
Casticoveho filtra (Particle filter).
|
||||
|
||||
subor cvparticle.h - systemovy model, praca s casticami
|
||||
*/
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
#ifndef CV_PARTICLE_INCLUDED
|
||||
#define CV_PARTICLE_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
#include <time.h>
|
||||
#include "cvsetrow.h"
|
||||
#include "cvsetcol.h"
|
||||
#include "cvlogsum.h"
|
||||
#include "cvanglemean.h"
|
||||
#include "cvrandgauss.h"
|
||||
|
||||
/******************************* Structures **********************************/
|
||||
/**
|
||||
* Particle Filter structure
|
||||
*/
|
||||
typedef struct CvParticle {
|
||||
// config
|
||||
int num_states; /**< Number of tracking states, e.g.,
|
||||
4 if x, y, width, height */
|
||||
int num_particles; /**< Number of particles */
|
||||
bool logweight; /**< log weights are stored in "weights". */
|
||||
// transition
|
||||
CvMat* dynamics; /**< num_states x num_states. Dynamics model. */
|
||||
CvRNG rng; /**< Random seed */
|
||||
CvMat* std; /**< num_states x 1. Standard deviation for gaussian noise
|
||||
Set standard deviation == 0 for no noise */
|
||||
CvMat* stds; /**< num_states x num_particles.
|
||||
Std for each particle so that you could be varying
|
||||
noise variance for each particle.
|
||||
"std" is used if "stds" is not set. */
|
||||
CvMat* bound; /**< num_states x 3 (lowerbound, upperbound,
|
||||
wrap_around (like angle) flag 0 or 1)
|
||||
Set lowerbound == upperbound to express no bound */
|
||||
// particle states
|
||||
CvMat* particles; /**< num_states x num_particles. The particles.
|
||||
The transition states values of all particles. */
|
||||
CvMat* weights; /**< 1 x num_particles. The weights of
|
||||
each particle respect to the particle id in "particles".
|
||||
"weights" are used to approximated the posterior pdf. */
|
||||
} CvParticle;
|
||||
|
||||
/**************************** Function Prototypes ****************************/
|
||||
|
||||
#ifndef NO_DOXYGEN
|
||||
CVAPI(CvParticle*) cvCreateParticle( int num_states, int num_particles, bool logweight );
|
||||
CVAPI(void) cvReleaseParticle( CvParticle** p );
|
||||
|
||||
CVAPI(void) cvParticleSetDynamics( CvParticle* p, const CvMat* dynamics );
|
||||
CVAPI(void) cvParticleSetNoise( CvParticle* p, CvRNG rng, const CvMat* std );
|
||||
CVAPI(void) cvParticleSetBound( CvParticle* p, const CvMat* bound );
|
||||
|
||||
CVAPI(int) cvParticleGetMax( const CvParticle* p );
|
||||
CVAPI(void) cvParticleGetMean( const CvParticle* p, CvMat* meanp );
|
||||
CVAPI(void) cvParticlePrint( const CvParticle* p, int p_id );
|
||||
|
||||
CVAPI(void) cvParticleBound( CvParticle* p );
|
||||
CVAPI(void) cvParticleNormalize( CvParticle* p );
|
||||
|
||||
CVAPI(void) cvParticleInit( CvParticle* p, const CvParticle* init );
|
||||
CVAPI(void) cvParticleTransition( CvParticle* p );
|
||||
CVAPI(void) cvParticleResample( CvParticle* p );
|
||||
#endif
|
||||
|
||||
/*************************** Constructor / Destructor *************************/
|
||||
|
||||
/**
|
||||
* Allocate Particle filter structure
|
||||
*
|
||||
* @param num_states Number of tracking states, e.g., 4 if x, y, width, height
|
||||
* @param num_particles Number of particles
|
||||
* @param logweight The weights parameter is log or not
|
||||
* @return CvParticle*
|
||||
*/
|
||||
CVAPI(CvParticle*) cvCreateParticle( int num_states,
|
||||
int num_particles,
|
||||
bool logweight CV_DEFAULT(false) )
|
||||
{
|
||||
CvParticle *p = NULL;
|
||||
CV_FUNCNAME( "cvCreateParticle" );
|
||||
__CV_BEGIN__;
|
||||
CV_ASSERT( num_states > 0 );
|
||||
CV_ASSERT( num_particles > 0 );
|
||||
p = (CvParticle *) cvAlloc( sizeof( CvParticle ) );
|
||||
p->num_particles = num_particles;
|
||||
p->num_states = num_states;
|
||||
p->dynamics = cvCreateMat( num_states, num_states, CV_32FC1 );
|
||||
p->rng = 1;
|
||||
p->std = cvCreateMat( num_states, 1, CV_32FC1 );
|
||||
p->bound = cvCreateMat( num_states, 3, CV_32FC1 );
|
||||
p->particles = cvCreateMat( num_states, num_particles, CV_32FC1 );
|
||||
p->weights = cvCreateMat( 1, num_particles, CV_64FC1 );
|
||||
p->logweight = logweight;
|
||||
p->stds = NULL;
|
||||
|
||||
// Default dynamics: next state = curr state + noise
|
||||
cvSetIdentity( p->dynamics, cvScalar(1.0) );
|
||||
cvSet( p->std, cvScalar(1.0) );
|
||||
|
||||
cvZero( p->bound );
|
||||
|
||||
__CV_END__;
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release Particle filter structure
|
||||
*
|
||||
* @param particle
|
||||
*/
|
||||
CVAPI(void) cvReleaseParticle( CvParticle** particle )
|
||||
{
|
||||
CvParticle *p = NULL;
|
||||
CV_FUNCNAME( "cvReleaseParticle" );
|
||||
__CV_BEGIN__;
|
||||
p = *particle;
|
||||
if( !p ) __CV_EXIT__;
|
||||
|
||||
CV_CALL( cvReleaseMat( &p->dynamics ) );
|
||||
CV_CALL( cvReleaseMat( &p->std ) );
|
||||
CV_CALL( cvReleaseMat( &p->bound ) );
|
||||
CV_CALL( cvReleaseMat( &p->particles ) );
|
||||
CV_CALL( cvReleaseMat( &p->weights ) );
|
||||
if( p->stds != NULL )
|
||||
CV_CALL( cvReleaseMat( &p->stds ) );
|
||||
|
||||
CV_CALL( cvFree( &p ) );
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
/***************************** Setter ***************************************/
|
||||
|
||||
/**
|
||||
* Set dynamics model
|
||||
*
|
||||
* @param particle
|
||||
* @param dynamics (num_states) x (num_states). dynamics model
|
||||
* new_state = dynamics * curr_state + noise
|
||||
*/
|
||||
CVAPI(void) cvParticleSetDynamics( CvParticle* p, const CvMat* dynamics )
|
||||
{
|
||||
CV_FUNCNAME( "cvParticleSetDynamics" );
|
||||
__CV_BEGIN__;
|
||||
CV_ASSERT( p->num_states == dynamics->rows );
|
||||
CV_ASSERT( p->num_states == dynamics->cols );
|
||||
//cvCopy( dynamics, p->dynamics );
|
||||
cvConvert( dynamics, p->dynamics );
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set noise model
|
||||
*
|
||||
* @param particle
|
||||
* @param rng random seed. refer cvRNG(time(NULL))
|
||||
* @param std num_states x 1. standard deviation for gaussian noise
|
||||
* Set standard deviation == 0 for no noise
|
||||
*/
|
||||
CVAPI(void) cvParticleSetNoise( CvParticle* p, CvRNG rng, const CvMat* std )
|
||||
{
|
||||
CV_FUNCNAME( "cvParticleSetNoise" );
|
||||
__CV_BEGIN__;
|
||||
CV_ASSERT( p->num_states == std->rows );
|
||||
p->rng = rng;
|
||||
//cvCopy( std, p->std );
|
||||
cvConvert( std, p->std );
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set lowerbound and upperbound used for bounding tracking state transition
|
||||
*
|
||||
* @param particle
|
||||
* @param bound num_states x 3 (lowerbound, upperbound, circular flag 0 or 1)
|
||||
* Set lowerbound == upperbound to express no bound
|
||||
*/
|
||||
CVAPI(void) cvParticleSetBound( CvParticle* p, const CvMat* bound )
|
||||
{
|
||||
CV_FUNCNAME( "cvParticleSetBound" );
|
||||
__CV_BEGIN__;
|
||||
CV_ASSERT( p->num_states == bound->rows );
|
||||
CV_ASSERT( 3 == bound->cols );
|
||||
//cvCopy( bound, p->bound );
|
||||
cvConvert( bound, p->bound );
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
/************************ Utility ******************************************/
|
||||
|
||||
/**
|
||||
* Get id of the most probable particle
|
||||
*
|
||||
* @param particle
|
||||
* @return int
|
||||
*/
|
||||
CVAPI(int) cvParticleGetMax( const CvParticle* p )
|
||||
{
|
||||
double minval, maxval;
|
||||
CvPoint min_loc, max_loc;
|
||||
cvMinMaxLoc( p->weights, &minval, &maxval, &min_loc, &max_loc );
|
||||
return max_loc.x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get evaluation of the most probable particle
|
||||
*
|
||||
* @param particle
|
||||
* @return double
|
||||
*/
|
||||
CVAPI(double) cvParticleGetMaxVal( const CvParticle* p )
|
||||
{
|
||||
double minval, maxval;
|
||||
CvPoint min_loc, max_loc;
|
||||
cvMinMaxLoc( p->weights, &minval, &maxval, &min_loc, &max_loc );
|
||||
return maxval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mean state (particle)
|
||||
*
|
||||
* @param particle
|
||||
* @param meanp num_states x 1, CV_32FC1 or CV_64FC1
|
||||
* @return CVAPI(void)
|
||||
*/
|
||||
CVAPI(void) cvParticleGetMean( const CvParticle* p, CvMat* meanp )
|
||||
{
|
||||
CvMat* weights = NULL;
|
||||
CvMat* particles_i, hdr;
|
||||
int i, j;
|
||||
CV_FUNCNAME( "cvParticleGetMean" );
|
||||
__CV_BEGIN__;
|
||||
CV_ASSERT( meanp->rows == p->num_states && meanp->cols == 1 );
|
||||
if( !p->logweight )
|
||||
{
|
||||
weights = p->weights;
|
||||
}
|
||||
else
|
||||
{
|
||||
weights = cvCreateMat( 1, p->num_particles, p->weights->type );
|
||||
cvExp( p->weights, weights );
|
||||
}
|
||||
|
||||
for( i = 0; i < p->num_states; i++ )
|
||||
{
|
||||
int circular = (int) cvmGet( p->bound, i, 2 );
|
||||
if( !circular ) // usual mean
|
||||
{
|
||||
particles_i = cvGetRow( p->particles, &hdr, i );
|
||||
double mean = 0;
|
||||
for( j = 0; j < p->num_particles; j++ )
|
||||
{
|
||||
mean += cvmGet( particles_i, 0, j ) * cvmGet( weights, 0, j );
|
||||
}
|
||||
cvmSet( meanp, i, 0, mean );
|
||||
}
|
||||
else // wrapped mean (angle)
|
||||
{
|
||||
double wrap = cvmGet( p->bound, i, 1 ) - cvmGet( p->bound, i, 0 );
|
||||
particles_i = cvGetRow( p->particles, &hdr, i );
|
||||
CvScalar mean = cvAngleMean( particles_i, weights, wrap );
|
||||
cvmSet( meanp, i, 0, mean.val[0] );
|
||||
}
|
||||
}
|
||||
|
||||
if( weights != p->weights )
|
||||
cvReleaseMat( &weights );
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Print states of a particle
|
||||
*
|
||||
* @param particle
|
||||
* @param p_id particle id
|
||||
*/
|
||||
CVAPI(void) cvParticlePrint( const CvParticle*p, int p_id CV_DEFAULT(-1) )
|
||||
{
|
||||
if( p_id == -1 ) // print all
|
||||
{
|
||||
int n;
|
||||
for( n = 0; n < p->num_particles; n++ )
|
||||
{
|
||||
cvParticlePrint( p, n );
|
||||
}
|
||||
}
|
||||
else {
|
||||
int i;
|
||||
for( i = 0; i < p->num_states; i++ )
|
||||
{
|
||||
printf( "%6.1f ", cvmGet( p->particles, i, p_id ) );
|
||||
}
|
||||
printf( "\n" );
|
||||
fflush( stdout );
|
||||
}
|
||||
}
|
||||
|
||||
/****************************** Helper functions ******************************/
|
||||
/*
|
||||
* Do normalization of weights
|
||||
*
|
||||
* @param particle
|
||||
* @see cvParticleResample
|
||||
*/
|
||||
CVAPI(void) cvParticleNormalize( CvParticle* p )
|
||||
{
|
||||
if( !p->logweight )
|
||||
{
|
||||
CvScalar normterm = cvSum( p->weights );
|
||||
cvScale( p->weights, p->weights, 1.0 / normterm.val[0] );
|
||||
}
|
||||
else // log version
|
||||
{
|
||||
CvScalar normterm = cvLogSum( p->weights );
|
||||
//printf("%.3f %.3f %.3f %.3f\n", normterm.val[0],normterm.val[1],normterm.val[2],normterm.val[3]);
|
||||
cvSubS( p->weights, normterm, p->weights );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply lower bound and upper bound for particle states.
|
||||
*
|
||||
* @param particle
|
||||
* @note Used by See also functions
|
||||
* @see cvParticleTransition
|
||||
*/
|
||||
CVAPI(void) cvParticleBound( CvParticle* p )
|
||||
{
|
||||
int row, col;
|
||||
double lower, upper;
|
||||
int circular;
|
||||
CvMat* stateparticles, hdr;
|
||||
float state;
|
||||
// @todo: np.width = (double)MAX( 2.0, MIN( maxX - 1 - x, width ) );
|
||||
for( row = 0; row < p->num_states; row++ )
|
||||
{
|
||||
lower = cvmGet( p->bound, row, 0 );
|
||||
upper = cvmGet( p->bound, row, 1 );
|
||||
circular = (int) cvmGet( p->bound, row, 2 );
|
||||
if( lower == upper ) continue; // no bound flag
|
||||
if( circular ) {
|
||||
for( col = 0; col < p->num_particles; col++ ) {
|
||||
state = cvmGet( p->particles, row, col );
|
||||
state = state < lower ? state + upper : ( state >= upper ? state - upper : state );
|
||||
cvmSet( p->particles, row, col, state );
|
||||
}
|
||||
} else {
|
||||
stateparticles = cvGetRow( p->particles, &hdr, row );
|
||||
cvMinS( stateparticles, upper, stateparticles );
|
||||
cvMaxS( stateparticles, lower, stateparticles );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************* Main (Related to Algorithm) *****************************/
|
||||
|
||||
/**
|
||||
* Initialize states
|
||||
*
|
||||
* If initial states are given, these states are uniformly copied.
|
||||
* If not given, states are uniform randomly sampled within lowerbound
|
||||
* and upperbound regions.
|
||||
*
|
||||
* @param particle
|
||||
* @param init initial states.
|
||||
*/
|
||||
CVAPI(void) cvParticleInit( CvParticle* p, const CvParticle* init = NULL )
|
||||
{
|
||||
int i, c, n, s;
|
||||
if( init ) // copy
|
||||
{
|
||||
int *num_copy;
|
||||
CvMat init_particle;
|
||||
|
||||
int divide = p->num_particles / init->num_particles;
|
||||
int remain = p->num_particles - divide * init->num_particles;
|
||||
num_copy = (int*) malloc( init->num_particles * sizeof(int) );
|
||||
for( i = 0; i < init->num_particles; i++ )
|
||||
{
|
||||
num_copy[i] = divide + ( i < remain ? 1 : 0 );
|
||||
}
|
||||
|
||||
n = 0; // copy all states once
|
||||
for( i = 0; i < init->num_particles; i++ )
|
||||
{
|
||||
cvGetCol( init->particles, &init_particle, i );
|
||||
for( c = 0; c < num_copy[i]; c++ )
|
||||
{
|
||||
cvSetCol( &init_particle, p->particles, n++ );
|
||||
}
|
||||
}
|
||||
// randomize partial states if necessary
|
||||
for( s = 0; s < init->num_states; s++ )
|
||||
{
|
||||
n = 0;
|
||||
for( i = 0; i < init->num_particles; i++ )
|
||||
{
|
||||
if( FLT_MAX - cvmGet( init->particles, s, i ) < FLT_EPSILON ) // randomize flag
|
||||
{
|
||||
CvScalar lower, upper;
|
||||
CvMat* statenoiseT = cvCreateMat( num_copy[i], 1, p->particles->type );
|
||||
lower = cvScalar( cvmGet( p->bound, s, 0 ) );
|
||||
upper = cvScalar( cvmGet( p->bound, s, 1 ) );
|
||||
cvRandArr( &p->rng, statenoiseT, CV_RAND_UNI, lower, upper );
|
||||
for( c = 0; c < num_copy[i]; c++ )
|
||||
{
|
||||
cvmSet( p->particles, s, n++, cvmGet( statenoiseT, c, 0 ) );
|
||||
}
|
||||
cvReleaseMat( &statenoiseT );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free( num_copy );
|
||||
}
|
||||
else // randomize all states
|
||||
{
|
||||
CvScalar lower, upper;
|
||||
CvMat* statenoiseT = cvCreateMat( p->num_particles, 1, p->particles->type );
|
||||
CvMat* statenoise = cvCreateMat( 1, p->num_particles, p->particles->type );
|
||||
for( s = 0; s < p->num_states; s++ )
|
||||
{
|
||||
lower = cvScalar( cvmGet( p->bound, s, 0 ) );
|
||||
upper = cvScalar( cvmGet( p->bound, s, 1 ) );
|
||||
cvRandArr( &p->rng, statenoiseT, CV_RAND_UNI, lower, upper );
|
||||
cvT( statenoiseT, statenoise );
|
||||
cvSetRow( statenoise, p->particles, s );
|
||||
}
|
||||
cvReleaseMat( &statenoise );
|
||||
cvReleaseMat( &statenoiseT );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Samples new particles from given particles
|
||||
*
|
||||
* Currently suppports only linear combination of states transition model.
|
||||
* Write up a function by yourself to supports nonlinear dynamics
|
||||
* such as Taylor series model and call your function instead of this function.
|
||||
* Other functions should not necessary be modified.
|
||||
*
|
||||
* @param particle
|
||||
* @note Uses See also functions inside.
|
||||
* @see cvParticleBound
|
||||
*/
|
||||
CVAPI(void) cvParticleTransition( CvParticle* p )
|
||||
{
|
||||
int i, j;
|
||||
CvMat* transits = cvCreateMat( p->num_states, p->num_particles, p->particles->type );
|
||||
CvMat* noises = cvCreateMat( p->num_states, p->num_particles, p->particles->type );
|
||||
CvMat* noise, noisehdr;
|
||||
double std;
|
||||
|
||||
// dynamics
|
||||
cvMatMul( p->dynamics, p->particles, transits );
|
||||
|
||||
// noise generation
|
||||
if( p->stds == NULL ) //sum je pre vsetky particles rovnaky
|
||||
{
|
||||
for( i = 0; i < p->num_states; i++ ) //pre kazdy state (x,y,w,h,r)
|
||||
{
|
||||
std = cvmGet( p->std, i, 0 );
|
||||
noise = cvGetRow( noises, &noisehdr, i );
|
||||
if( std == 0.0 )
|
||||
cvZero( noise );
|
||||
else
|
||||
cvRandArr( &p->rng, noise, CV_RAND_NORMAL, cvScalar(0), cvScalar( std ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( i = 0; i < p->num_states; i++ )
|
||||
{
|
||||
for( j = 0; j < p->num_particles; j++ )
|
||||
{
|
||||
std = cvmGet( p->stds, i, j );
|
||||
if( std == 0.0 )
|
||||
cvmSet( noises, i, j, 0.0 );
|
||||
else
|
||||
cvmSet( noises, i, j, cvRandGauss( &p->rng, std ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// dynamics + noise
|
||||
cvAdd( transits, noises, p->particles );
|
||||
|
||||
cvReleaseMat( &transits );
|
||||
cvReleaseMat( &noises );
|
||||
|
||||
cvParticleBound( p );
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-samples a set of particles according to their weights to produce a
|
||||
* new set of unweighted particles
|
||||
*
|
||||
* Simply copy, not uniform randomly selects
|
||||
*
|
||||
* @param particle
|
||||
* @note Uses See also functions inside.
|
||||
*/
|
||||
CVAPI(void) cvParticleResample( CvParticle* p )
|
||||
{
|
||||
int i, j, np, k = 0;
|
||||
CvMat* particle, hdr;
|
||||
CvMat* new_particles = cvCreateMat( p->num_states, p->num_particles, p->particles->type );
|
||||
double weight;
|
||||
int max_loc;
|
||||
|
||||
k = 0;
|
||||
for( i = 0; i < p->num_particles; i++ ) //weights su uz normalizovane (ich suma je 1)
|
||||
{
|
||||
particle = cvGetCol( p->particles, &hdr, i ); //ulozi sa x,y,w,h,r o particle
|
||||
weight = cvmGet( p->weights, 0, i ); //ulozi sa weight particlu
|
||||
weight = p->logweight ? exp( weight ) : weight; //ak su vahy ulozene vo weights -> weight = e^weight
|
||||
np = cvRound( weight * p->num_particles ); //particle s vyssim ohodnotenim sa skopiruje do viacerych novych particles
|
||||
for( j = 0; j < np; j++ )
|
||||
{
|
||||
cvSetCol( particle, new_particles, k++ );
|
||||
if( k == p->num_particles )
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
|
||||
//pokial sme este neskopirovali vsekty particles, zvysne skopirujeme podla najlepsie ohodnotenej particle
|
||||
max_loc = cvParticleGetMax( p );
|
||||
particle = cvGetCol( p->particles, &hdr, max_loc );
|
||||
while( k < p->num_particles ) //kym sa nenastavia vsetky particles
|
||||
cvSetCol( particle, new_particles, k++ ); //nastav zostavajucim particles maximalne ohodnotenie?
|
||||
|
||||
exit:
|
||||
cvReleaseMat( &p->particles );
|
||||
p->particles = new_particles;
|
||||
}
|
||||
|
||||
#endif
|
234
3rdparty/include/opencvx/cvpcadiffs.h
vendored
Normal file
234
3rdparty/include/opencvx/cvpcadiffs.h
vendored
Normal file
@ -0,0 +1,234 @@
|
||||
/** @file */
|
||||
/* Copyright (c) 2008, Naotoshi Seo. All rights reserved.
|
||||
*
|
||||
* The program is free to use for non-commercial academic purposes,
|
||||
* but for course works, you must understand what is going inside to
|
||||
* use. The program can be used, modified, or re-distributed for any
|
||||
* purposes only if you or one of your group understand not only
|
||||
* programming codes but also theory and math behind (if any).
|
||||
* Please contact the authors if you are interested in using the
|
||||
* program without meeting the above conditions.
|
||||
*/
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#ifndef CV_PCADIFFS_INCLUDED
|
||||
#define CV_PCADIFFS_INCLUDED
|
||||
|
||||
#ifndef NO_DOXYGEN
|
||||
CVAPI(void)
|
||||
cvMatPcaDiffs( const CvMat* samples, const CvMat* avg, const CvMat* eigenvalues,
|
||||
const CvMat* eigenvectors, CvMat* probs,
|
||||
int normalize, bool logprob );
|
||||
CV_INLINE double
|
||||
cvPcaDiffs( const CvMat* sample, const CvMat* avg, const CvMat* eigenvalues,
|
||||
const CvMat* eigenvectors, int normalize, bool logprob );
|
||||
#endif
|
||||
|
||||
/**
|
||||
* PCA Distance "in" and "from" feature space [1]
|
||||
*
|
||||
* This computes a distance between a point to a PCA subspace as sum of
|
||||
* distance-from-feature space (DFFS) and distance-in-feature-space
|
||||
* (DIFS). The DFFS is essentially a reconstruction error and the
|
||||
* DIFS measures (mahalanobis) distance between projected point and
|
||||
* origin of PCA subpsace. DFFS and DIFS can be used to measure
|
||||
* approximated likelihood Gaussian density distribution.
|
||||
* See [1] for more details.
|
||||
*
|
||||
* @param samples D x N sample vectors
|
||||
* @param avg D x 1 mean vector
|
||||
* @param eigenvalues nEig x 1 eigen values
|
||||
* @param eigenvectors M x D or D x M (automatically adjusted) eigen vectors
|
||||
* @param probs 1 x N computed likelihood probabilities
|
||||
* @param normalize Compute normalization term or not
|
||||
* 0 - nothing
|
||||
* 1 - normalization term
|
||||
* 2 - normalize so that sum becomes 1.0
|
||||
* @param logprob Log probability or not
|
||||
* @see CVAPI(void) cvCalcPCA( const CvArr* data, CvArr* avg, CvArr* eigenvalues, CvArr* eigenvectors, int flags );
|
||||
* @see CVAPI(void) cvProjectPCA( const CvArr* data, const CvArr* avg, const CvArr* eigenvectors, CvArr* result );
|
||||
* @see CVAPI(void) cvBackProjectPCA( const CvArr* proj, const CvArr* avg,const CvArr* eigenvects, CvArr* result );
|
||||
*
|
||||
* References
|
||||
* @verbatim
|
||||
* [1] @INPROCEEDINGS{Moghaddam95probabilisticvisual,
|
||||
* author = {Baback Moghaddam and Alex Pentl},
|
||||
* title = {Probabilistic visual learning for object detection},
|
||||
* booktitle = {},
|
||||
* year = {1995},
|
||||
* pages = {786--793}
|
||||
* }
|
||||
* [2] @ARTICLE{Moghaddam02principalmanifolds,
|
||||
* author = {Baback Moghaddam},
|
||||
* title = {Principal manifolds and probabilistic subspaces for visual recognition},
|
||||
* journal = {IEEE Transactions on Pattern Analysis and Machine Intelligence},
|
||||
* year = {2002},
|
||||
* volume = {24},
|
||||
* pages = {780--788}
|
||||
* @endverbatim
|
||||
*/
|
||||
CVAPI(void)
|
||||
cvMatPcaDiffs( const CvMat* samples, const CvMat* avg, const CvMat* eigenvalues,
|
||||
const CvMat* eigenvectors, CvMat* probs,
|
||||
int normalize CV_DEFAULT(1), bool logprob CV_DEFAULT(false) )
|
||||
{
|
||||
int D = samples->rows;
|
||||
int N = samples->cols;
|
||||
int M = (eigenvectors->rows == D) ? eigenvectors->cols : eigenvectors->rows;
|
||||
int type = samples->type;
|
||||
int nEig = eigenvalues->rows;
|
||||
int d, n;
|
||||
double normterm = 0;
|
||||
CvMat *_eigenvectors; // cvProjectPCA requires M x D vec
|
||||
CvMat *proj = cvCreateMat( N, M, type );
|
||||
CvMat *subproj, subprojhdr;
|
||||
CvMat *sclsubproj = cvCreateMat( 1, M, type );
|
||||
CvMat *pLambda, pLambdaHdr;
|
||||
CvMat *rLambda, rLambdaHdr;
|
||||
CvMat *sqrt_pLambda = cvCreateMat( M, 1, type );
|
||||
CvMat *DIFS = cvCreateMat( 1, N, type );
|
||||
CvMat *DFFS = cvCreateMat( 1, N, type );
|
||||
CvMat *samples0 = cvCreateMat( D, N, type ); // mean subtracted samples
|
||||
CvMat *subsamples0, subsamples0hdr;
|
||||
CvScalar rho;
|
||||
CvMat *_proj;
|
||||
CV_FUNCNAME( "cvMatPcaDiffs" );
|
||||
__CV_BEGIN__;
|
||||
CV_ASSERT( CV_IS_MAT(samples) );
|
||||
CV_ASSERT( CV_IS_MAT(avg) );
|
||||
CV_ASSERT( CV_IS_MAT(eigenvalues) );
|
||||
CV_ASSERT( CV_IS_MAT(eigenvectors) );
|
||||
CV_ASSERT( D == eigenvectors->rows || D == eigenvectors->cols );
|
||||
CV_ASSERT( D == avg->rows && 1 == avg->cols );
|
||||
CV_ASSERT( 1 == probs->rows && N == probs->cols );
|
||||
|
||||
cvZero( DIFS );
|
||||
cvZero( DFFS );
|
||||
|
||||
if( D == eigenvectors->rows ) {
|
||||
_eigenvectors = cvCreateMat( M, D, type );
|
||||
cvT( eigenvectors, _eigenvectors );
|
||||
} else {
|
||||
_eigenvectors = (CvMat*)eigenvectors;
|
||||
}
|
||||
//cvProjectPCA( samples, avg, _eigenvectors, proj );
|
||||
for( n = 0; n < N; n++ ) { // want mean subtracted samples for laster too
|
||||
for( d = 0; d < D; d++ ) {
|
||||
cvmSet( samples0, d, n, cvmGet( samples, d, n ) - cvmGet( avg, d, 0 ) );
|
||||
}
|
||||
}
|
||||
_proj = cvCreateMat( M, N, type );
|
||||
cvMatMul( _eigenvectors, samples0, _proj );
|
||||
cvT( _proj, proj );
|
||||
cvReleaseMat( &_proj );
|
||||
|
||||
// distance in feature space
|
||||
if( M > 0 ) {
|
||||
pLambda = cvGetRows( eigenvalues, &pLambdaHdr, 0, M );
|
||||
cvPow( pLambda, sqrt_pLambda, 0.5 );
|
||||
for( n = 0; n < N; n++ ) {
|
||||
subproj = cvGetRow( proj, &subprojhdr, n );
|
||||
for( d = 0; d < M; d++ ) {
|
||||
cvmSet( sclsubproj, 0, d, cvmGet( subproj, 0, d ) / cvmGet( sqrt_pLambda, d, 0 ) );
|
||||
}
|
||||
cvmSet( DIFS, 0, n, pow(cvNorm( sclsubproj, NULL, CV_L2 ), 2) );
|
||||
}
|
||||
if( normalize == 1 ) {
|
||||
//cvLog( sqrt_pLambda, sqrt_pLambda );
|
||||
//cvSum( sqrt_pLambda );
|
||||
for( d = 0; d < M; d++ ) {
|
||||
normterm += log( cvmGet( sqrt_pLambda, d, 0 ) );
|
||||
}
|
||||
normterm += log(2*M_PI)*(M/2.0);
|
||||
}
|
||||
}
|
||||
|
||||
// distance from feature space
|
||||
if( nEig > M ) {
|
||||
rLambda = cvGetRows( eigenvalues, &rLambdaHdr, M, nEig );
|
||||
rho = cvAvg( rLambda );
|
||||
for( n = 0; n < N; n++ ) {
|
||||
subsamples0 = cvGetCol( samples0, &subsamples0hdr, n );
|
||||
subproj = cvGetRow( proj, &subprojhdr, n );
|
||||
cvmSet( DFFS, 0, n, pow(cvNorm( subsamples0, NULL, CV_L2 ),2) - pow(cvNorm( subproj, NULL, CV_L2 ),2) );
|
||||
}
|
||||
cvScale( DFFS, DFFS, 1.0/rho.val[0] );
|
||||
if( normalize == 1 ) {
|
||||
normterm += log(2*M_PI*rho.val[0]) * ((nEig - M)/2.0);
|
||||
}
|
||||
}
|
||||
|
||||
// sum DIFS and DFFS in log form
|
||||
for( n = 0; n < N; n++ ) {
|
||||
cvmSet( probs, 0, n, cvmGet( DIFS, 0, n ) / (-2) + cvmGet( DFFS, 0, n) / (-2) - normterm );
|
||||
}
|
||||
|
||||
// normalization and so on
|
||||
if( normalize == 2 ) {
|
||||
double minval, maxval;
|
||||
cvMinMaxLoc( probs, &minval, &maxval );
|
||||
cvSubS( probs, cvScalar( maxval ), probs );
|
||||
}
|
||||
if( !logprob || normalize == 2 ) {
|
||||
for( n = 0; n < N; n++ ) {
|
||||
cvmSet( probs, 0, n, exp(cvmGet( probs, 0, n )) );
|
||||
}
|
||||
if( normalize == 2 ) {
|
||||
CvScalar sumprob = cvSum( probs );
|
||||
cvScale( probs, probs, 1.0 / sumprob.val[0] );
|
||||
}
|
||||
}
|
||||
if( logprob && normalize == 2 ) {
|
||||
for( n = 0; n < N; n++ ) {
|
||||
cvmSet( probs, 0, n, log(cvmGet( probs, 0, n )) );
|
||||
}
|
||||
}
|
||||
cvReleaseMat( &proj );
|
||||
cvReleaseMat( &sclsubproj );
|
||||
cvReleaseMat( &sqrt_pLambda );
|
||||
cvReleaseMat( &DIFS );
|
||||
cvReleaseMat( &DFFS );
|
||||
cvReleaseMat( &samples0 );
|
||||
if( D == eigenvectors->rows ) {
|
||||
cvReleaseMat( &_eigenvectors );
|
||||
}
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
/**
|
||||
* PCA Distance "in" and "from" feature space
|
||||
*
|
||||
* @param sample D x 1 feature vector
|
||||
* @param avg D x 1 mean vector
|
||||
* @param eigenvalues nEig x 1 eigen values
|
||||
* @param eigenvectors M x D eigen vectors
|
||||
* @param normalize Compute normalization term or not
|
||||
* 0 - nothing
|
||||
* 1 - normalization term
|
||||
* 2 - normalize so that sum becomes 1.0
|
||||
* @param logprob Log probability or not
|
||||
* @return double likelihood
|
||||
*/
|
||||
CV_INLINE double
|
||||
cvPcaDiffs( const CvMat* sample, const CvMat* avg, const CvMat* eigenvalues,
|
||||
const CvMat* eigenvectors,
|
||||
int normalize CV_DEFAULT(1), bool logprob CV_DEFAULT(false) )
|
||||
{
|
||||
double prob;
|
||||
CvMat *_probs = cvCreateMat( 1, 1, sample->type );
|
||||
|
||||
cvMatPcaDiffs( sample, avg, eigenvalues, eigenvectors, _probs, normalize, logprob );
|
||||
prob = cvmGet(_probs, 0, 0);
|
||||
|
||||
cvReleaseMat( &_probs );
|
||||
return prob;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
122
3rdparty/include/opencvx/cvpcadist.h
vendored
Normal file
122
3rdparty/include/opencvx/cvpcadist.h
vendored
Normal file
@ -0,0 +1,122 @@
|
||||
/** @file */
|
||||
/* Copyright (c) 2008, Naotoshi Seo. All rights reserved.
|
||||
*
|
||||
* The program is free to use for non-commercial academic purposes,
|
||||
* but for course works, you must understand what is going inside to
|
||||
* use. The program can be used, modified, or re-distributed for any
|
||||
* purposes only if you or one of your group understand not only
|
||||
* programming codes but also theory and math behind (if any).
|
||||
* Please contact the authors if you are interested in using the
|
||||
* program without meeting the above conditions.
|
||||
*/
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#ifndef CV_PCADIST_INCLUDED
|
||||
#define CV_PCADIST_INCLUDED
|
||||
|
||||
#ifndef NO_DOXYGEN
|
||||
CVAPI(void)
|
||||
cvMatPcaDist( const CvMat* samples, const CvMat* avg,
|
||||
const CvMat* eigenvectors, CvMat* dists );
|
||||
CV_INLINE double
|
||||
cvPcaDist( const CvMat* sample, const CvMat* avg,
|
||||
const CvMat* eigenvectors );
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Distance between sample and PCA subspace, i.e, reconstruction error
|
||||
*
|
||||
* @param samples D x N sample vectors
|
||||
* @param avg D x 1 mean vector
|
||||
* @param eigenvectors M x D or D x M (automatically adjusted) eigen vectors
|
||||
* @param dists 1 x N computed distances
|
||||
*
|
||||
* @see CVAPI(void) cvCalcPCA( const CvArr* data, CvArr* avg, CvArr* eigenvalues, CvArr* eigenvectors, int flags );
|
||||
* @see CVAPI(void) cvProjectPCA( const CvArr* data, const CvArr* avg, const CvArr* eigenvectors, CvArr* result );
|
||||
* @see CVAPI(void) cvBackProjectPCA( const CvArr* proj, const CvArr* avg,const CvArr* eigenvects, CvArr* result );
|
||||
*/
|
||||
CVAPI(void)
|
||||
cvMatPcaDist( const CvMat* samples, const CvMat* avg,
|
||||
const CvMat* eigenvectors, CvMat* dists )
|
||||
{
|
||||
int D = samples->rows;
|
||||
int N = samples->cols;
|
||||
int M = (eigenvectors->rows == D) ? eigenvectors->cols : eigenvectors->rows;
|
||||
int type = samples->type;
|
||||
int d, n;
|
||||
CvMat *_eigenvectors; // cvProjectPCA requires M x D vec
|
||||
CvMat *proj = cvCreateMat( N, M, type );
|
||||
CvMat *subproj, subprojhdr;
|
||||
CvMat *samples0 = cvCreateMat( D, N, type ); // mean subtracted samples
|
||||
CvMat *subsamples0, subsamples0hdr;
|
||||
CvMat *_proj;
|
||||
CV_FUNCNAME( "cvMatPcaDist" );
|
||||
__CV_BEGIN__;
|
||||
CV_ASSERT( CV_IS_MAT(samples) );
|
||||
CV_ASSERT( CV_IS_MAT(avg) );
|
||||
CV_ASSERT( CV_IS_MAT(eigenvectors) );
|
||||
CV_ASSERT( D == eigenvectors->rows || D == eigenvectors->cols );
|
||||
CV_ASSERT( D == avg->rows && 1 == avg->cols );
|
||||
CV_ASSERT( 1 == dists->rows && N == dists->cols );
|
||||
if( D == eigenvectors->rows ) { // support transpose
|
||||
_eigenvectors = cvCreateMat( M, D, type );
|
||||
cvT( eigenvectors, _eigenvectors );
|
||||
} else {
|
||||
_eigenvectors = (CvMat*)eigenvectors;
|
||||
}
|
||||
|
||||
//cvProjectPCA( samples, avg, _eigenvectors, proj );
|
||||
for( n = 0; n < N; n++ ) { // want mean subtracted samples for laster too
|
||||
for( d = 0; d < D; d++ ) {
|
||||
cvmSet( samples0, d, n, cvmGet( samples, d, n ) - cvmGet( avg, d, 0 ) );
|
||||
}
|
||||
}
|
||||
_proj = cvCreateMat( M, N, type );
|
||||
cvMatMul( _eigenvectors, samples0, _proj );
|
||||
cvT( _proj, proj );
|
||||
cvReleaseMat( &_proj );
|
||||
|
||||
// distance from feature space
|
||||
for( n = 0; n < N; n++ ) {
|
||||
subsamples0 = cvGetCol( samples0, &subsamples0hdr, n );
|
||||
subproj = cvGetRow( proj, &subprojhdr, n );
|
||||
cvmSet( dists, 0, n, pow(cvNorm( subsamples0, NULL, CV_L2 ),2) - pow(cvNorm( subproj, NULL, CV_L2 ),2) );
|
||||
}
|
||||
|
||||
cvReleaseMat( &proj );
|
||||
cvReleaseMat( &samples0 );
|
||||
if( D == eigenvectors->rows ) {
|
||||
cvReleaseMat( &_eigenvectors );
|
||||
}
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
/**
|
||||
* Distance between sample and PCA subspace, i.e, reconstruction error
|
||||
*
|
||||
* @param sample D x 1 feature vector
|
||||
* @param avg D x 1 mean vector
|
||||
* @param eigenvectors M x D eigen vectors
|
||||
* @return double
|
||||
*/
|
||||
CV_INLINE double
|
||||
cvPcaDist( const CvMat* sample, const CvMat* avg, const CvMat* eigenvectors )
|
||||
{
|
||||
double prob;
|
||||
CvMat *_dists = cvCreateMat( 1, 1, sample->type );
|
||||
|
||||
cvMatPcaDist( sample, avg, eigenvectors, _dists );
|
||||
prob = cvmGet(_dists, 0, 0);
|
||||
|
||||
cvReleaseMat( &_dists );
|
||||
return prob;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
130
3rdparty/include/opencvx/cvpcaprobdist.h
vendored
Normal file
130
3rdparty/include/opencvx/cvpcaprobdist.h
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
/** @file */
|
||||
/* Copyright (c) 2008, Naotoshi Seo. All rights reserved.
|
||||
*
|
||||
* The program is free to use for non-commercial academic purposes,
|
||||
* but for course works, you must understand what is going inside to
|
||||
* use. The program can be used, modified, or re-distributed for any
|
||||
* purposes only if you or one of your group understand not only
|
||||
* programming codes but also theory and math behind (if any).
|
||||
* Please contact the authors if you are interested in using the
|
||||
* program without meeting the above conditions.
|
||||
*/
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#ifndef CV_PCAPROBDIST_INCLUDED
|
||||
#define CV_PCAPROBDIST_INCLUDED
|
||||
#include "cvpcadist.h"
|
||||
#include "cvlogsum.h"
|
||||
|
||||
#ifndef NO_DOXYGEN
|
||||
CVAPI(void)
|
||||
cvMatPcaProbDist( const CvMat* samples, const CvMat* avg,
|
||||
const CvMat* eigenvectors, double sqsigma, CvMat* probs,
|
||||
int normalize, bool logprob );
|
||||
CV_INLINE double
|
||||
cvPcaProbDist( const CvMat* sample, const CvMat* avg,
|
||||
const CvMat* eigenvectors, double sqsigma,
|
||||
int normalize, bool logprob );
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Probabilistic model of Distance from PCA subspace with Gaussian
|
||||
*
|
||||
* @param samples D x N sample vectors
|
||||
* @param avg D x 1 mean vector
|
||||
* @param eigenvectors M x D or D x M (automatically adjusted) eigen vectors
|
||||
* @param sqsigma A scalar representing sigma^2, i.e, variances
|
||||
* of distribution of reconstruction errors.
|
||||
* Estimate in training data.
|
||||
* @param probs 1 x N computed likelihood probabilities
|
||||
* @param normalize Compute normalization term or not
|
||||
* 0 - nothing
|
||||
* 1 - normalization term
|
||||
* 2 - normalize so that sum becomes 1.0
|
||||
* @param logprob Log probability or not
|
||||
*
|
||||
* @see CVAPI(void) cvCalcPCA( const CvArr* data, CvArr* avg, CvArr* eigenvalues, CvArr* eigenvectors, int flags );
|
||||
* @see CVAPI(void) cvProjectPCA( const CvArr* data, const CvArr* avg, const CvArr* eigenvectors, CvArr* result );
|
||||
* @see CVAPI(void) cvBackProjectPCA( const CvArr* proj, const CvArr* avg,const CvArr* eigenvects, CvArr* result );
|
||||
* @see cvMatPcaDist
|
||||
*/
|
||||
CVAPI(void)
|
||||
cvMatPcaProbDist( const CvMat* samples, const CvMat* avg,
|
||||
const CvMat* eigenvectors, double sqsigma, CvMat* probs,
|
||||
int normalize CV_DEFAULT(1), bool logprob CV_DEFAULT(false) )
|
||||
{
|
||||
int D = samples->rows;
|
||||
int N = samples->cols;
|
||||
int type = samples->type;
|
||||
CvMat *dists = cvCreateMat( 1, N, type );
|
||||
CV_FUNCNAME( "cvMatPcaProbDist" );
|
||||
__CV_BEGIN__;
|
||||
CV_ASSERT( CV_IS_MAT(samples) );
|
||||
CV_ASSERT( CV_IS_MAT(avg) );
|
||||
CV_ASSERT( CV_IS_MAT(eigenvectors) );
|
||||
CV_ASSERT( D == eigenvectors->rows || D == eigenvectors->cols );
|
||||
CV_ASSERT( D == avg->rows && 1 == avg->cols );
|
||||
CV_ASSERT( 1 == probs->rows && N == probs->cols );
|
||||
|
||||
cvMatPcaDist( samples, avg, eigenvectors, dists );
|
||||
cvScale( dists, probs, -1/(2*sqsigma) );
|
||||
|
||||
if( normalize == 1 )
|
||||
{
|
||||
cvSubS( probs, cvScalar(log(sqrt(2*M_PI*sqsigma))), probs );
|
||||
}
|
||||
else if( normalize == 2 )
|
||||
{
|
||||
CvScalar logsum = cvLogSum( probs );
|
||||
cvSubS( probs, logsum, probs );
|
||||
}
|
||||
|
||||
if( !logprob ) // finally make exp
|
||||
{
|
||||
cvExp( probs, probs );
|
||||
}
|
||||
|
||||
cvReleaseMat( &dists );
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
/**
|
||||
* Distance between sample and PCA subspace, i.e, reconstruction error
|
||||
* Probabiliticlly model with Gaussian
|
||||
*
|
||||
* @param sample D x 1 feature vector
|
||||
* @param avg D x 1 mean vector
|
||||
* @param eigenvectors M x D eigen vectors
|
||||
* @param sqsigma A scalar representing sigma^2, i.e, variances
|
||||
* of distribution of reconstruction errors.
|
||||
* Estimate in training data.
|
||||
* @param normalize Compute normalization term or not
|
||||
* 0 - nothing
|
||||
* 1 - normalization term
|
||||
* 2 - normalize so that sum becomes 1.0
|
||||
* @param logprob Log probability or not
|
||||
* @return double
|
||||
*/
|
||||
CV_INLINE double
|
||||
cvPcaProbDist( const CvMat* sample, const CvMat* avg,
|
||||
const CvMat* eigenvectors, double sqsigma,
|
||||
int normalize CV_DEFAULT(1), bool logprob CV_DEFAULT(false) )
|
||||
{
|
||||
double prob;
|
||||
CvMat *_probs = cvCreateMat( 1, 1, sample->type );
|
||||
|
||||
cvMatPcaProbDist( sample, avg, eigenvectors, sqsigma, _probs, normalize, logprob );
|
||||
prob = cvmGet( _probs, 0, 0);
|
||||
|
||||
cvReleaseMat( &_probs );
|
||||
return prob;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
51
3rdparty/include/opencvx/cvpointnorm.h
vendored
Normal file
51
3rdparty/include/opencvx/cvpointnorm.h
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_POINTNORM_INCLUDED
|
||||
#define CV_POINTNORM_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
#include <math.h>
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* Compute Norm between two points
|
||||
*
|
||||
* @param p1 A point 1
|
||||
* @param p2 A point 2
|
||||
* @param norm_type CV_L2 to compute L2 norm (euclidean distance)
|
||||
* CV_L1 to compute L1 norm (abs)
|
||||
* @return double
|
||||
*/
|
||||
CV_INLINE double cvPointNorm( CvPoint p1, CvPoint p2, int norm_type CV_DEFAULT(CV_L2) )
|
||||
{
|
||||
if( norm_type == CV_L1 )
|
||||
return abs( p2.x - p1.x ) + abs( p2.y - p1.y );
|
||||
else
|
||||
return sqrt( pow( (double)p2.x - p1.x, 2 ) + pow( (double)p2.y - p1.y, 2 ) );
|
||||
}
|
||||
|
||||
|
||||
#endif
|
106
3rdparty/include/opencvx/cvpointrecttest.h
vendored
Normal file
106
3rdparty/include/opencvx/cvpointrecttest.h
vendored
Normal file
@ -0,0 +1,106 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_POINTRECTTEST_INCLUDED
|
||||
#define CV_POINTRECTTEST_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
#include "cvrect32f.h"
|
||||
#include "cvcreateaffine.h"
|
||||
#include "cvrectpoints.h"
|
||||
|
||||
// double
|
||||
// cvPointRect32fTest( const CvRect32f& rect, CvPoint2D32f pt,
|
||||
// int measure_dist = 0, CvPoint2D32f shear = cvPoint2D32f(0,0) );
|
||||
// CV_INLINE double
|
||||
// cvPointRectTest( const CvRect& rect, CvPoint2D32f pt, int measure_dist = 0 );
|
||||
|
||||
/**
|
||||
* Point in rectangle test (Check whether point is in rectangle)
|
||||
*
|
||||
* @param rect Rectangle (x,y,width,height), and angle if want.
|
||||
* @param pt The point tested against the contour.
|
||||
* @param measure_dist 0 - return positive, negative, 0
|
||||
* if inside, outside, on the rectangle boundary
|
||||
* respectively.
|
||||
* 1 - return singned distance between the point
|
||||
* and the nearest rectangle edge.
|
||||
* @param shear shear deformation parameter (of affine transform)
|
||||
* @return result of test
|
||||
* @see cvPointPolygonTest, cvPointRectTest
|
||||
*/
|
||||
CVAPI(double)
|
||||
cvPointRect32fTest( const CvRect32f& rect, CvPoint2D32f pt,
|
||||
int measure_dist CV_DEFAULT(0),
|
||||
CvPoint2D32f shear CV_DEFAULT(cvPoint2D32f(0,0)) )
|
||||
{
|
||||
CvPoint2D32f points[4];
|
||||
CvMat *contour = cvCreateMat( 1, 4, CV_32FC2 );
|
||||
|
||||
cvRect32fPoints( rect, points, shear );
|
||||
for( int i = 0; i < 4; i++ )
|
||||
{
|
||||
CV_MAT_ELEM( *contour, CvPoint2D32f, 0, i ) = points[i];
|
||||
} // cvPointSeqFromMat
|
||||
|
||||
/* // CV_32FC2 is not possible
|
||||
CvPoint point;
|
||||
CvSeq *contour = cvCreateSeq( CV_32SC2, sizeof( CvSeq ), sizeof( CvPoint2D32f ), cvCreateMemStorage( 0 ) );
|
||||
for( int i = 0; i < 4; i++ )
|
||||
{
|
||||
point = cvPointFrom32f( points[i] );
|
||||
cvSeqPush( contour, &point );
|
||||
}*/
|
||||
|
||||
double test = cvPointPolygonTest( contour, pt, measure_dist );
|
||||
|
||||
cvReleaseMat( &contour );
|
||||
//cvClearMemStorage( contour->storage );
|
||||
return test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Point in rectangle test (Check whether point is in rectangle)
|
||||
*
|
||||
* @param rect Rectangle (x,y,width,height)
|
||||
* @param pt The point tested against the contour.
|
||||
* @param measure_dist 0 - return positive, negative, 0
|
||||
* if inside, outside, on the rectangle boundary
|
||||
* respectively.
|
||||
* 1 - return singned distance between the point
|
||||
* and the nearest rectangle edge.
|
||||
* @return result of test
|
||||
* @return double
|
||||
* @see cvPointPolygonTest, cvPointRect32fTest
|
||||
*/
|
||||
CV_INLINE double
|
||||
cvPointRectTest( const CvRect& rect, CvPoint2D32f pt,
|
||||
int measure_dist CV_DEFAULT(0) )
|
||||
{
|
||||
return cvPointRect32fTest( cvRect32fFromRect( rect ), pt, measure_dist );
|
||||
}
|
||||
|
||||
#endif
|
120
3rdparty/include/opencvx/cvprintmat.h
vendored
Normal file
120
3rdparty/include/opencvx/cvprintmat.h
vendored
Normal file
@ -0,0 +1,120 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_PRINTMAT_INCLUDED
|
||||
#define CV_PRINTMAT_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
//CV_INLINE void cvPrintMatProperty( const CvMat* mat );
|
||||
//CV_INLINE void cvPrintImageProperty( const IplImage* img );
|
||||
//CVAPI(void) cvPrintMat( const CvArr* arr, bool transpose = false );
|
||||
|
||||
/**
|
||||
* Print CvMat Property
|
||||
*
|
||||
* @param mat
|
||||
* @return CVAPI(void)
|
||||
*/
|
||||
CV_INLINE void cvPrintMatProperty( const CvMat* mat )
|
||||
{
|
||||
printf("CvMat Property\n");
|
||||
printf(" rows: %d\n", mat->rows);
|
||||
printf(" cols: %d\n", mat->cols);
|
||||
printf(" type: %d\n", mat->type);
|
||||
printf(" step: %d\n", mat->step);
|
||||
fflush( stdout );
|
||||
}
|
||||
|
||||
/**
|
||||
* Print IplImage Property
|
||||
*
|
||||
* @param img
|
||||
* @return CVAPI(void)
|
||||
*/
|
||||
CV_INLINE void cvPrintImageProperty( const IplImage* img )
|
||||
{
|
||||
printf("IplImage Property\n");
|
||||
printf(" width: %d\n", img->width);
|
||||
printf(" height: %d\n", img->height);
|
||||
printf(" depth: %d\n", img->depth);
|
||||
printf(" nChannels: %d\n", img->nChannels);
|
||||
fflush( stdout );
|
||||
}
|
||||
|
||||
/**
|
||||
* Print array
|
||||
*
|
||||
* @param arr array
|
||||
* @return CVAPI(void)
|
||||
*/
|
||||
CVAPI(void) cvPrintMat( const CvArr* arr, bool transpose CV_DEFAULT(false) )
|
||||
{
|
||||
CV_FUNCNAME( "cvPrintMat" );
|
||||
__CV_BEGIN__;
|
||||
int row, col, ch;
|
||||
int coi = 0;
|
||||
CvMat matstub, *mat = (CvMat*)arr;
|
||||
int depth, nChannels;
|
||||
CvScalar value;
|
||||
int rows, cols;
|
||||
if( !CV_IS_MAT( mat ) )
|
||||
{
|
||||
CV_CALL( mat = cvGetMat( mat, &matstub, &coi ) ); // i.e. IplImage to CvMat
|
||||
if (coi != 0) CV_Error(CV_BadCOI, "");//CV_ERROR_FROM_CODE(CV_BadCOI);
|
||||
}
|
||||
depth = CV_MAT_DEPTH( mat->type );
|
||||
nChannels = CV_MAT_CN( mat->type );
|
||||
rows = !transpose ? mat->rows : mat->cols;
|
||||
cols = !transpose ? mat->cols : mat->rows;
|
||||
|
||||
for( row = 0; row < rows; row++ )
|
||||
{
|
||||
for( col = 0; col < cols; col++ )
|
||||
{
|
||||
value = cvGet2D( mat, !transpose ? row : col, !transpose ? col : row );
|
||||
if( nChannels > 1 )
|
||||
{
|
||||
printf( "(%lf", value.val[0] );
|
||||
for( ch = 1; ch < nChannels; ch++ )
|
||||
{
|
||||
printf( " %lf", value.val[ch] );
|
||||
}
|
||||
printf( ") " );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "%lf ", value.val[0] );
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
fflush( stdout );
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
170
3rdparty/include/opencvx/cvputimageroi.h
vendored
Normal file
170
3rdparty/include/opencvx/cvputimageroi.h
vendored
Normal file
@ -0,0 +1,170 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_CROPIMAGEROI_INCLUDED
|
||||
#define CV_CROPIMAGEROI_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#include "cvrect32f.h"
|
||||
#include "cvcreateaffine.h"
|
||||
#include "cvcreateaffineimage.h"
|
||||
|
||||
// CVAPI(void) cvPutImageROI( const IplImage* src,
|
||||
// IplImage* dst,
|
||||
// CvRect32f rect32f = cvRect32f(0,0,1,1,0),
|
||||
// CvPoint2D32f shear = cvPoint2D32f(0,0),
|
||||
// const IplImage* mask = NULL,
|
||||
// bool circumscribe = 0 );
|
||||
|
||||
/**
|
||||
* Put a source image on the specified region on a target image
|
||||
*
|
||||
* Use CvBox32f to define rotation center as the center of rectangle,
|
||||
* and use cvRect32fBox32( box32f ) to pass argument.
|
||||
*
|
||||
* @param src The source image
|
||||
* @param dst The target image
|
||||
* @param rect32f The rectangle region (x,y,width,height) to put
|
||||
* the rotation angle in degree where the rotation center is (x,y)
|
||||
* @param shear The shear deformation parameter shx and shy
|
||||
* @param mask The mask image
|
||||
* @param circumscribe Put a circular (ellipsoidal) image as a circumscribed
|
||||
* circle (ellipsoid) rather than a inscribed circle (ellipsoid)
|
||||
* @return CVAPI(void)
|
||||
*/
|
||||
CVAPI(void) cvPutImageROI( const IplImage* src,
|
||||
IplImage* dst,
|
||||
CvRect32f rect32f CV_DEFAULT(cvRect32f(0,0,1,1,0)),
|
||||
CvPoint2D32f shear CV_DEFAULT(cvPoint2D32f(0,0)),
|
||||
const IplImage* mask CV_DEFAULT(NULL),
|
||||
bool circumscribe CV_DEFAULT(0) )
|
||||
{
|
||||
CvRect rect;
|
||||
float tx, ty, sx, sy, angle;
|
||||
IplImage* _src = NULL;
|
||||
IplImage* _mask = NULL;
|
||||
CV_FUNCNAME( "cvPutImageROI" );
|
||||
__CV_BEGIN__;
|
||||
rect = cvRectFromRect32f( rect32f );
|
||||
angle = rect32f.angle;
|
||||
|
||||
CV_ASSERT( rect.width > 0 && rect.height > 0 );
|
||||
CV_ASSERT( src->depth == dst->depth );
|
||||
CV_ASSERT( src->nChannels == dst->nChannels );
|
||||
if( mask != NULL )
|
||||
CV_ASSERT( src->width == mask->width && src->height == mask->height );
|
||||
|
||||
if( circumscribe )
|
||||
{
|
||||
CvBox32f box32f = cvBox32fFromRect32f( rect32f );
|
||||
// width and height from center (inscribed ellipsoid's a and b parameters)
|
||||
float a = box32f.width / 2.0;
|
||||
float b = box32f.height / 2.0;
|
||||
// diagonal distance to the corner of rectangle from center
|
||||
float d = sqrt( a * a + b * b );
|
||||
// get distance to the intersectional point of inscribed ellipsoid
|
||||
// line with rectangle's diagonal line from center
|
||||
float cost = a / d;
|
||||
float sint = b / d;
|
||||
float c = sqrt( pow( a * cost, 2 ) + pow( b * sint, 2 ) );
|
||||
// this ratio enables to make circumscribed ellipsoid
|
||||
float ratio = d / c;
|
||||
box32f.width *= ratio;
|
||||
box32f.height *= ratio;
|
||||
// ellipsoidal paramter to rectangle parameter
|
||||
rect32f = cvRect32fFromBox32f( box32f );
|
||||
rect = cvRectFromRect32f( rect32f );
|
||||
}
|
||||
|
||||
_src = (IplImage*)src;
|
||||
_mask = (IplImage*)mask;
|
||||
if( rect.width != src->width && rect.height != src->height )
|
||||
{
|
||||
_src = cvCreateImage( cvSize( rect.width, rect.height ), src->depth, src->nChannels );
|
||||
cvResize( src, _src );
|
||||
if( mask != NULL )
|
||||
{
|
||||
_mask = cvCreateImage( cvSize( rect.width, rect.height ), mask->depth, mask->nChannels );
|
||||
cvResize( mask, _mask );
|
||||
}
|
||||
}
|
||||
|
||||
if( angle == 0 && shear.x == 0 && shear.y == 0 &&
|
||||
rect.x >= 0 && rect.y >= 0 &&
|
||||
rect.x + rect.width < dst->width && rect.y + rect.height < dst->height )
|
||||
{
|
||||
cvSetImageROI( dst, rect );
|
||||
cvCopy( _src, dst, _mask );
|
||||
cvResetImageROI( dst );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( _mask == NULL )
|
||||
{
|
||||
_mask = cvCreateImage( cvGetSize(_src), IPL_DEPTH_8U, 1 );
|
||||
cvSet( _mask, cvScalar(1) );
|
||||
}
|
||||
|
||||
CvMat* affine = cvCreateMat( 2, 3, CV_32FC1 );
|
||||
tx = 0;
|
||||
ty = 0;
|
||||
sx = rect32f.width / (float)_src->width;
|
||||
sy = rect32f.height / (float)_src->height;
|
||||
angle = rect32f.angle;
|
||||
cvCreateAffine( affine, cvRect32f( tx, ty, sx, sy, angle ), shear );
|
||||
|
||||
CvPoint origin;
|
||||
IplImage* srctrans = cvCreateAffineImage( _src, affine, CV_AFFINE_FULL, &origin, CV_RGB(0,0,0) );
|
||||
IplImage* masktrans = cvCreateAffineImage( _mask, affine, CV_AFFINE_FULL, NULL, cvScalar(0) );
|
||||
for( int xp = 0; xp < srctrans->width; xp++ )
|
||||
{
|
||||
int x = xp + rect.x + origin.x;
|
||||
for( int yp = 0; yp < srctrans->height; yp++ )
|
||||
{
|
||||
int y = yp + rect.y + origin.y;
|
||||
if( x < 0 || x >= dst->width || y < 0 || y >= dst->height ) continue;
|
||||
if( CV_IMAGE_ELEM( masktrans, uchar, yp, xp ) == 0 ) continue;
|
||||
for( int ch = 0; ch < srctrans->nChannels; ch++ )
|
||||
{
|
||||
dst->imageData[dst->widthStep * y + x * dst->nChannels + ch]
|
||||
= srctrans->imageData[srctrans->widthStep * yp + xp * srctrans->nChannels + ch];
|
||||
}
|
||||
}
|
||||
}
|
||||
cvReleaseMat( &affine );
|
||||
cvReleaseImage( &srctrans );
|
||||
cvReleaseImage( &masktrans );
|
||||
}
|
||||
if( mask != _mask )
|
||||
cvReleaseImage( &_mask );
|
||||
if( src != _src )
|
||||
cvReleaseImage( &_src );
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
#endif
|
51
3rdparty/include/opencvx/cvrandgauss.h
vendored
Normal file
51
3rdparty/include/opencvx/cvrandgauss.h
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_RAND_INCLUDED
|
||||
#define CV_RAND_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
|
||||
/**
|
||||
* This function returns a Gaussian random variate, with mean zero and standard deviation sigma.
|
||||
*
|
||||
* @param rng cvRNG random state
|
||||
* @param sigma standard deviation
|
||||
* @return double
|
||||
*/
|
||||
CV_INLINE double cvRandGauss( CvRNG* rng, double sigma )
|
||||
{
|
||||
CvMat* mat = cvCreateMat( 1, 1, CV_64FC1 );
|
||||
double var = 0;
|
||||
cvRandArr( rng, mat, CV_RAND_NORMAL, cvRealScalar(0), cvRealScalar(sigma) );
|
||||
var = cvmGet( mat, 0, 0 );
|
||||
cvReleaseMat( &mat );
|
||||
return var;
|
||||
}
|
||||
/*
|
||||
rng.disttype = CV_RAND_NORMAL;
|
||||
cvRandSetRange( &rng, 30, 100, -1 ); */
|
||||
|
||||
|
||||
#endif
|
284
3rdparty/include/opencvx/cvrect32f.h
vendored
Normal file
284
3rdparty/include/opencvx/cvrect32f.h
vendored
Normal file
@ -0,0 +1,284 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_RECT32F_INCLUDED
|
||||
#define CV_RECT32F_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
/************************* Structure Definitions ******************************/
|
||||
|
||||
/**
|
||||
* Floating Rectangle Structure
|
||||
*/
|
||||
typedef struct CvRect32f {
|
||||
float x; /**< left x coord of rectangle */
|
||||
float y; /**< top y coord of rectangle */
|
||||
float width; /**< width of rectangle */
|
||||
float height; /**< height of rectangle */
|
||||
float angle; /**< counter-clockwise rotation angle in degree
|
||||
rotation center is (x, y) coordinates */
|
||||
} CvRect32f;
|
||||
|
||||
/**
|
||||
* Center Coordinate Floating Rectangle Structure
|
||||
*
|
||||
* This is equivalent with CvBox2D, but I wanted this structure because
|
||||
* CvBox2D's parameters are too long such as box.center.x, box.size.width and
|
||||
* CvBox2D does not have a constructor cvBox2D(...).
|
||||
*/
|
||||
typedef struct CvBox32f {
|
||||
float cx; /**< center x coord of rectangle */
|
||||
float cy; /**< center y coord of center of rectangle */
|
||||
float width; /**< width of rectangle */
|
||||
float height; /**< height of rectangle */
|
||||
float angle; /**< counter-clockwise rotation angle in degree
|
||||
rotation center is center of rectangle */
|
||||
} CvBox32f;
|
||||
|
||||
/***************************** Prototypes *************************************/
|
||||
|
||||
//CV_INLINE CvRect32f cvRect32f( float x, float y, float width, float height,
|
||||
// float angle = 0.0 );
|
||||
//CV_INLINE CvBox32f cvBox32f( float cx, float cy, float width, float height,
|
||||
// float angle = 0.0 );
|
||||
|
||||
//CVAPI(CvBox32f) cvBox32fFromRect32f( CvRect32f rect );
|
||||
//CVAPI(CvRect32f) cvRect32fFromBox32f( CvBox32f box );
|
||||
//CV_INLINE CvRect32f cvRect32fFromRect( CvRect rect, float angle = 0 );
|
||||
//CV_INLINE CvRect cvRectFromRect32f( CvRect32f rect );
|
||||
//CV_INLINE CvBox32f cvBox32fFromBox2D( CvBox2D box );
|
||||
//CV_INLINE CvBox2D cvBox2DFromBox32f( CvBox32f box );
|
||||
//CV_INLINE CvBox32f cvBox32fFromRect( CvRect rect );
|
||||
//CV_INLINE CvRect cvRectFromBox32f( CvBox32f box );
|
||||
//CV_INLINE CvRect cvRectFromBox2D( CvBox2D box );
|
||||
//CV_INLINE CvBox2D cvBox2DFromRect32f( CvRect32f rect );
|
||||
//CV_INLINE CvRect32f cvRect32fFromBox2D( CvBox2D box );
|
||||
|
||||
// CV_INLINE void cvPrintRect32f( CvRect32f rect );
|
||||
// CV_INLINE void cvPrintBox32f( CvBox32f box );
|
||||
// CV_INLINE void cvPrintBox2D( CvBox2D box );
|
||||
// CV_INLINE void cvPrintRect( CvRect rect );
|
||||
|
||||
/******************************* Constructor **********************************/
|
||||
|
||||
/**
|
||||
* The Constructor of Floating Rectangle Structure
|
||||
*
|
||||
* @param x left x coord of rectangle
|
||||
* @param y top y coord of center of rectangle
|
||||
* @param width width of rectangle
|
||||
* @param height height of rectangle
|
||||
* @param angle counter-clockwise rotation angle in degree
|
||||
* rotation center is (x, y) coordinates
|
||||
*/
|
||||
CV_INLINE CvRect32f cvRect32f( float x, float y, float width, float height,
|
||||
float angle CV_DEFAULT(0.0) )
|
||||
{
|
||||
CvRect32f rect = { x, y, width, height, angle };
|
||||
return rect;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Constructor of Center Coordinate Floating Rectangle Structure
|
||||
*
|
||||
* @param cx center x coord of rectangle
|
||||
* @param cy center y coord of center of rectangle
|
||||
* @param width width of rectangle
|
||||
* @param height height of rectangle
|
||||
* @param angle counter-clockwise rotation angle in degree
|
||||
* rotation center is center of rectangle
|
||||
*/
|
||||
CV_INLINE CvBox32f cvBox32f( float cx, float cy, float width, float height,
|
||||
float angle CV_DEFAULT(0.0) )
|
||||
{
|
||||
CvBox32f box = { cx, cy, width, height, angle };
|
||||
return box;
|
||||
}
|
||||
|
||||
/****************************** Converter *************************************/
|
||||
/**
|
||||
*cvRect32f from cvRect
|
||||
*/
|
||||
CV_INLINE CvRect32f cvRect32fFromRect( CvRect rect, float angle CV_DEFAULT(0.0) )
|
||||
{
|
||||
return cvRect32f( rect.x, rect.y, rect.width, rect.height, angle );
|
||||
}
|
||||
|
||||
/**
|
||||
* cvRect from cvRect32f
|
||||
*/
|
||||
CV_INLINE CvRect cvRectFromRect32f( CvRect32f rect )
|
||||
{
|
||||
return cvRect( cvRound( rect.x ), cvRound( rect.y ),
|
||||
cvRound( rect.width ), cvRound( rect.height ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* cvBox32f from cvBox2D
|
||||
*/
|
||||
CV_INLINE CvBox32f cvBox32fFromBox2D( CvBox2D box )
|
||||
{
|
||||
return cvBox32f( box.center.x, box.center.y,
|
||||
box.size.width, box.size.height,
|
||||
box.angle );
|
||||
}
|
||||
|
||||
/**
|
||||
* cvBox2D from cvBox32f
|
||||
*/
|
||||
CV_INLINE CvBox2D cvBox2DFromBox32f( CvBox32f box )
|
||||
{
|
||||
CvBox2D box2d;
|
||||
box2d.center.x = box.cx;
|
||||
box2d.center.y = box.cy;
|
||||
box2d.size.width = box.width;
|
||||
box2d.size.height = box.height;
|
||||
box2d.angle = box.angle;
|
||||
return box2d;
|
||||
}
|
||||
|
||||
/**
|
||||
* cvBox32f from cvRect32f
|
||||
*
|
||||
* Convert upper-left coordinate to center coordinate of the rectangle
|
||||
*/
|
||||
CvBox32f cvBox32fFromRect32f( CvRect32f rect )
|
||||
{
|
||||
CvPoint2D32f c;
|
||||
// x + ( x + width - 1 ) / 2 = cx
|
||||
c.x = ( 2 * rect.x + rect.width - 1 ) / 2.0;
|
||||
c.y = ( 2 * rect.y + rect.height - 1 ) / 2.0;
|
||||
if( rect.angle != 0 )
|
||||
{
|
||||
CvMat* R = cvCreateMat( 2, 3, CV_32FC1 );
|
||||
cv2DRotationMatrix( cvPoint2D32f( rect.x, rect.y ), rect.angle, 1.0, R );
|
||||
c = cvPoint2D32f (
|
||||
cvmGet( R, 0, 0 ) * c.x + cvmGet( R, 0, 1 ) * c.y + cvmGet( R, 0, 2 ),
|
||||
cvmGet( R, 1, 0 ) * c.x + cvmGet( R, 1, 1 ) * c.y + cvmGet( R, 1, 2 ) );
|
||||
cvReleaseMat( &R );
|
||||
}
|
||||
return cvBox32f( c.x, c.y, rect.width, rect.height, rect.angle );
|
||||
}
|
||||
|
||||
/**
|
||||
* cvRect32f from cvBox32f
|
||||
*
|
||||
* Convert center coordinate to upper-left coordinate of the rectangle
|
||||
*/
|
||||
CvRect32f cvRect32fFromBox32f( CvBox32f box )
|
||||
{
|
||||
CvPoint2D32f l;
|
||||
// x + ( x + width - 1 ) / 2 = cx
|
||||
l.x = ( 2 * box.cx + 1 - box.width ) / 2.0;
|
||||
l.y = ( 2 * box.cy + 1 - box.height ) / 2.0;
|
||||
if( box.angle != 0.0 )
|
||||
{
|
||||
CvMat* R = cvCreateMat( 2, 3, CV_32FC1 );
|
||||
cv2DRotationMatrix( cvPoint2D32f( box.cx, box.cy ), box.angle, 1.0, R );
|
||||
l = cvPoint2D32f (
|
||||
cvmGet( R, 0, 0 ) * l.x + cvmGet( R, 0, 1 ) * l.y + cvmGet( R, 0, 2 ),
|
||||
cvmGet( R, 1, 0 ) * l.x + cvmGet( R, 1, 1 ) * l.y + cvmGet( R, 1, 2 ) );
|
||||
cvReleaseMat( &R );
|
||||
}
|
||||
return cvRect32f( l.x, l.y, box.width, box.height, box.angle );
|
||||
}
|
||||
|
||||
/**
|
||||
* CvBox32f from CvRect
|
||||
*/
|
||||
CV_INLINE CvBox32f cvBox32fFromRect( CvRect rect )
|
||||
{
|
||||
return cvBox32fFromRect32f( cvRect32fFromRect( rect ) );
|
||||
}
|
||||
/**
|
||||
* CvRect from CvBox32f
|
||||
*/
|
||||
CV_INLINE CvRect cvRectFromBox32f( CvBox32f box )
|
||||
{
|
||||
return cvRectFromRect32f( cvRect32fFromBox32f( box ) );
|
||||
}
|
||||
/**
|
||||
* CvRect from CvBox2D
|
||||
*/
|
||||
CV_INLINE CvRect cvRectFromBox2D( CvBox2D box )
|
||||
{
|
||||
return cvRectFromBox32f( cvBox32fFromBox2D( box ) );
|
||||
}
|
||||
/**
|
||||
* CvBox2D from CvRect32f
|
||||
*/
|
||||
CV_INLINE CvBox2D cvBox2DFromRect32f( CvRect32f rect )
|
||||
{
|
||||
return cvBox2DFromBox32f( cvBox32fFromRect32f( rect ) );
|
||||
}
|
||||
/**
|
||||
* CvRect32f from CvBox2D
|
||||
*/
|
||||
CV_INLINE CvRect32f cvRect32fFromBox2D( CvBox2D box )
|
||||
{
|
||||
return cvRect32fFromBox32f( cvBox32fFromBox2D( box ) );
|
||||
}
|
||||
|
||||
/************************************ Print ***********************************/
|
||||
/**
|
||||
* Print CvRect32f
|
||||
*/
|
||||
CV_INLINE void cvPrintRect32f( CvRect32f rect )
|
||||
{
|
||||
printf( "x=%f y=%f width=%f height=%f angle=%f\n",
|
||||
rect.x, rect.y, rect.width, rect.height, rect.angle );
|
||||
fflush( stdout );
|
||||
}
|
||||
/**
|
||||
* Print CvBox32f
|
||||
*/
|
||||
CV_INLINE void cvPrintBox32f( CvBox32f box )
|
||||
{
|
||||
printf( "cx=%f cy=%f width=%f height=%f angle=%f\n",
|
||||
box.cx, box.cy, box.width, box.height, box.angle );
|
||||
fflush( stdout );
|
||||
}
|
||||
/**
|
||||
* Print CvBox2D
|
||||
*/
|
||||
CV_INLINE void cvPrintBox2D( CvBox2D box )
|
||||
{
|
||||
printf( "cx=%f cy=%f width=%f height=%f angle=%f\n",
|
||||
box.center.x, box.center.y, box.size.width,
|
||||
box.size.height, box.angle );
|
||||
fflush( stdout );
|
||||
}
|
||||
/**
|
||||
* Print CvRect
|
||||
*/
|
||||
CV_INLINE void cvPrintRect( CvRect rect )
|
||||
{
|
||||
printf( "x=%d y=%d width=%d height=%d",
|
||||
rect.x, rect.y, rect.width, rect.height );
|
||||
fflush( stdout );
|
||||
}
|
||||
|
||||
#endif
|
126
3rdparty/include/opencvx/cvrectpoints.h
vendored
Normal file
126
3rdparty/include/opencvx/cvrectpoints.h
vendored
Normal file
@ -0,0 +1,126 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_RECT32FPOINTS_INCLUDED
|
||||
#define CV_RECT32FPOINTS_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
#include "cvrect32f.h"
|
||||
#include "cvcreateaffine.h"
|
||||
|
||||
// CVAPI(void) cvRect32fPoints( CvRect32f rect, CvPoint2D32f pt[4],
|
||||
// CvPoint2D32f shear = cvPoint2D32f(0,0) );
|
||||
// CV_INLINE void cvBox32fPoints( CvBox32f box, CvPoint2D32f pt[4],
|
||||
// CvPoint2D32f shear = cvPoint2D32f(0,0) );
|
||||
// CV_INLINE void cvRectPoints( CvRect rect, CvPoint2D32f pt[4] );
|
||||
// cvBoxPoints
|
||||
|
||||
/**
|
||||
* Find 4 corners of rectangle
|
||||
*
|
||||
* @code
|
||||
* x y
|
||||
* [0] 0 0
|
||||
* [1] 1 0
|
||||
* [2] 1 1
|
||||
* [3] 0 1
|
||||
* @endcode
|
||||
*
|
||||
* @param rect Rectangle parameters and rotation angle parameter
|
||||
* @param pt[4] Found 4 corners
|
||||
* @param shear Shear deformation parameter if you want
|
||||
* @see cvBoxPoints, cvBox32fPoints, cvRectPoints, cvRect32fPoints
|
||||
*/
|
||||
CVAPI(void) cvRect32fPoints( CvRect32f rect, CvPoint2D32f pt[4],
|
||||
CvPoint2D32f shear CV_DEFAULT(cvPoint2D32f(0,0)) )
|
||||
{
|
||||
if( shear.x == 0 && shear.y == 0 )
|
||||
{
|
||||
CvBox2D box2d = cvBox2DFromRect32f( rect );
|
||||
cvBoxPoints( box2d, pt );
|
||||
}
|
||||
else
|
||||
{
|
||||
CvMat* A = cvCreateMat( 2, 3, CV_32FC1 );
|
||||
cvCreateAffine( A, rect, shear );
|
||||
pt[0].x = 0; pt[0].y = 0;
|
||||
pt[1].x = 1; pt[1].y = 0;
|
||||
pt[2].x = 1; pt[2].y = 1;
|
||||
pt[3].x = 0; pt[3].y = 1;
|
||||
CvPoint2D32f tmp;
|
||||
for( int i = 0; i < 4; i++ )
|
||||
{
|
||||
tmp.x = cvmGet( A, 0, 0 ) * pt[i].x + cvmGet( A, 0, 1 ) * pt[i].y + cvmGet( A, 0, 2 );
|
||||
tmp.y = cvmGet( A, 1, 0 ) * pt[i].x + cvmGet( A, 1, 1 ) * pt[i].y + cvmGet( A, 1, 2 );
|
||||
pt[i].x = tmp.x;
|
||||
pt[i].y = tmp.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find 4 corners of box
|
||||
*
|
||||
* @code
|
||||
* x y
|
||||
* [0] 0 0
|
||||
* [1] 1 0
|
||||
* [2] 1 1
|
||||
* [3] 0 1
|
||||
* @endcode
|
||||
*
|
||||
* @param box Box structure
|
||||
* @param pt[4] Found 4 corners
|
||||
* @param shear Shear deformation parameters if you want
|
||||
* @see cvBoxPoints, cvBox32fPoints, cvRectPoints, cvRect32fPoints
|
||||
*/
|
||||
CV_INLINE void cvBox32fPoints( CvBox32f box, CvPoint2D32f pt[4],
|
||||
CvPoint2D32f shear CV_DEFAULT(cvPoint2D32f(0,0)) )
|
||||
{
|
||||
cvRect32fPoints( cvRect32fFromBox32f( box ), pt, shear );
|
||||
}
|
||||
|
||||
/**
|
||||
* Find 4 corners of rectangle
|
||||
*
|
||||
* @code
|
||||
* x y
|
||||
* [0] 0 0
|
||||
* [1] 1 0
|
||||
* [2] 1 1
|
||||
* [3] 0 1
|
||||
* @endcode
|
||||
*
|
||||
* @param rect Rectangle parameter
|
||||
* @param pt[4] Found 4 points
|
||||
* @see cvBoxPoints, cvBox32fPoints, cvRectPoints, cvRect32fPoints
|
||||
*/
|
||||
CV_INLINE void cvRectPoints( CvRect rect, CvPoint2D32f pt[4] )
|
||||
{
|
||||
cvRect32fPoints( cvRect32fFromRect( rect ), pt );
|
||||
}
|
||||
|
||||
#endif
|
119
3rdparty/include/opencvx/cvsandwichfill.h
vendored
Normal file
119
3rdparty/include/opencvx/cvsandwichfill.h
vendored
Normal file
@ -0,0 +1,119 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_CLOSING_INCLUDED
|
||||
#define CV_CLOSING_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
/**
|
||||
* Search boundary (non-zero pixel) from both side and fill inside
|
||||
*
|
||||
* @param IplImage* src One channel image with 0 or 1 value (mask image)
|
||||
* @param IplImage* dst
|
||||
* @see cvSmooth( src, dst, CV_MEDIAN, 3 )
|
||||
* @see cvClosing( src, dst, NULL, 3 )
|
||||
*/
|
||||
CVAPI(void) cvSandwichFill( const IplImage* src, IplImage* dst )
|
||||
{
|
||||
cvCopy( src, dst );
|
||||
for( int y = 0; y < dst->height; y++ )
|
||||
{
|
||||
int start = -1;
|
||||
int end = -1;
|
||||
for( int x = 0; x < dst->width - 1; x++)
|
||||
{
|
||||
int p1 = dst->imageData[dst->widthStep * y + x];
|
||||
int p2 = dst->imageData[dst->widthStep * y + x + 1];
|
||||
if( p1 > 0 && p2 > 0 )
|
||||
{
|
||||
start = x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for( int x = dst->width - 1; x > start; x--)
|
||||
{
|
||||
int p1 = dst->imageData[dst->widthStep * y + x];
|
||||
int p2 = dst->imageData[dst->widthStep * y + x + 1];
|
||||
if( p1 > 0 && p2 > 0 )
|
||||
{
|
||||
end = x;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( start != -1 && end != -1 )
|
||||
{
|
||||
for( int x = start; x <= end; x++)
|
||||
{
|
||||
dst->imageData[dst->widthStep * y + x] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
for( int x = 0; x < dst->width; x++ )
|
||||
{
|
||||
int start = -1;
|
||||
int end = -1;
|
||||
for( int y = 0; y < dst->height - 1; y++)
|
||||
{
|
||||
int p1 = dst->imageData[dst->widthStep * y + x];
|
||||
int p2 = dst->imageData[dst->widthStep * y + x + 1];
|
||||
if( p1 > 0 && p2 > 0 )
|
||||
{
|
||||
start = y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for( int y = dst->height - 1; y > start; y--)
|
||||
{
|
||||
int p1 = dst->imageData[dst->widthStep * y + x];
|
||||
int p2 = dst->imageData[dst->widthStep * y + x + 1];
|
||||
if( p1 > 0 && p2 > 0 )
|
||||
{
|
||||
end = y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( start != -1 && end != -1 )
|
||||
{
|
||||
for( int y = start; y <= end; y++)
|
||||
{
|
||||
dst->imageData[dst->widthStep * y + x] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
//// Tried to use cvFindContours, but did not work for disconnected contours.
|
||||
//CvMemStorage* storage = cvCreateMemStorage(0);
|
||||
//CvSeq* contour = 0;
|
||||
//cvFindContours( dst, storage, &contour,
|
||||
// sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
|
||||
//for( ; contour != 0; contour = contour->h_next )
|
||||
//{
|
||||
// CvScalar color = cvScalar(255);
|
||||
// cvDrawContours( dst, contour, color, color, -1, CV_FILLED, 8 );
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
141
3rdparty/include/opencvx/cvsetcol.h
vendored
Normal file
141
3rdparty/include/opencvx/cvsetcol.h
vendored
Normal file
@ -0,0 +1,141 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_SETCOL_INCLUDED
|
||||
#define CV_SETCOL_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
|
||||
//CVAPI(void) cvSetCols( const CvArr* src, CvArr* dst,
|
||||
// int start_col, int end_col );
|
||||
//CV_INLINE void cvSetCol( const CvArr* src, CvArr* dst, int col );
|
||||
|
||||
/**
|
||||
* Set array col or col span
|
||||
*
|
||||
* Following code is faster than using this function because it does not
|
||||
* require cvCopy()
|
||||
* @code
|
||||
* CvMat* submat, submathdr;
|
||||
* submat = cvGetCols( mat, &submathdr, start_col, end_col, delta_col );
|
||||
* // Write on submat
|
||||
* @endcode
|
||||
*
|
||||
* @param src Source array
|
||||
* @param dst Target array. Either of array must be size of setting cols.
|
||||
* @param start_col Zero-based index of the starting col (inclusive) of the span.
|
||||
* @param end_col Zero-based index of the ending col (exclusive) of the span.
|
||||
* @return CVAPI(void)
|
||||
* @see cvSetCol( src, dst, col ) // cvSetCols( src, dst, col, col + 1 )
|
||||
*/
|
||||
CVAPI(void) cvSetCols( const CvArr* src, CvArr* dst,
|
||||
int start_col, int end_col )
|
||||
{
|
||||
int coi;
|
||||
CvMat *srcmat = (CvMat*)src, srcmatstub;
|
||||
CvMat *dstmat = (CvMat*)dst, dstmatstub;
|
||||
CvMat *refmat, refmathdr;
|
||||
int cols;
|
||||
CV_FUNCNAME( "cvSetCols" );
|
||||
__CV_BEGIN__;
|
||||
if( !CV_IS_MAT(dstmat) )
|
||||
{
|
||||
CV_CALL( dstmat = cvGetMat( dstmat, &dstmatstub, &coi ) );
|
||||
if (coi != 0) CV_Error(CV_BadCOI, "");//CV_ERROR_FROM_CODE(CV_BadCOI);
|
||||
}
|
||||
if( !CV_IS_MAT(srcmat) )
|
||||
{
|
||||
CV_CALL( srcmat = cvGetMat( srcmat, &srcmatstub, &coi ) );
|
||||
if (coi != 0) CV_Error(CV_BadCOI, "");//CV_ERROR_FROM_CODE(CV_BadCOI);
|
||||
}
|
||||
cols = end_col - start_col;
|
||||
CV_ASSERT( srcmat->cols == cols || dstmat->cols == cols );
|
||||
if( srcmat->cols == cols )
|
||||
{
|
||||
refmat = cvGetCols( dstmat, &refmathdr, start_col, end_col );
|
||||
cvCopy( srcmat, refmat );
|
||||
}
|
||||
else
|
||||
{
|
||||
refmat = cvGetCols( srcmat, &refmathdr, start_col, end_col );
|
||||
cvCopy( refmat, dstmat );
|
||||
}
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
/*
|
||||
CVAPI(void) cvSetCols( const CvArr* subarr, CvArr* arr, int start_col, int end_col )
|
||||
{
|
||||
CV_FUNCNAME( "cvSetCols" );
|
||||
__CV_BEGIN__;
|
||||
int col, row, elem;
|
||||
int coi = 0;
|
||||
CvMat* submat = (CvMat*)subarr, submatstub;
|
||||
CvMat* mat = (CvMat*)arr, matstub;
|
||||
|
||||
if( !CV_IS_MAT(submat) )
|
||||
{
|
||||
CV_CALL( submat = cvGetMat( submat, &submatstub, &coi ) );
|
||||
if (coi != 0) CV_ERROR_FROM_CODE(CV_BadCOI);
|
||||
}
|
||||
if( !CV_IS_MAT(mat) )
|
||||
{
|
||||
CV_CALL( mat = cvGetMat( mat, &matstub, &coi ) );
|
||||
if (coi != 0) CV_ERROR_FROM_CODE(CV_BadCOI);
|
||||
}
|
||||
CV_ARE_TYPES_EQ( submat, mat );
|
||||
CV_ARE_DEPTHS_EQ( submat, mat );
|
||||
CV_ASSERT( 0 <= start_col && end_col <= mat->cols );
|
||||
CV_ASSERT( end_col - start_col == submat->cols );
|
||||
CV_ASSERT( mat->rows == submat->rows );
|
||||
|
||||
int elem_size = CV_ELEM_SIZE( mat->type );
|
||||
for( col = start_col; col < end_col; col++ )
|
||||
{
|
||||
for( row = 0; row < mat->rows; row++ )
|
||||
{
|
||||
for( elem = 0; elem < elem_size; elem++ )
|
||||
{
|
||||
(mat->data.ptr + ((size_t)mat->step * row) + (elem_size * col))[elem] =
|
||||
(submat->data.ptr + ((size_t)submat->step * row) + (elem_size * (col - start_col)))[elem];
|
||||
}
|
||||
}
|
||||
}
|
||||
__CV_END__;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Set array col
|
||||
*
|
||||
* #define cvSetCol(src, dst, col) (cvSetCols( src, dst, col, col + 1))
|
||||
*/
|
||||
CV_INLINE void cvSetCol( const CvArr* src, CvArr* dst, int col )
|
||||
{
|
||||
cvSetCols( src, dst, col, col+1 );
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
147
3rdparty/include/opencvx/cvsetrow.h
vendored
Normal file
147
3rdparty/include/opencvx/cvsetrow.h
vendored
Normal file
@ -0,0 +1,147 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_SETROW_INCLUDED
|
||||
#define CV_SETROW_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
|
||||
// CVAPI(void) cvSetRows( const CvArr* src, CvArr* dst,
|
||||
// int start_row, int end_row, int delta_row = 1 );
|
||||
// CV_INLINE void cvSetRow( const CvArr* src, CvArr* dst, int row );
|
||||
|
||||
/**
|
||||
* Set array row or row span
|
||||
*
|
||||
* Following code is faster than using this function because it does not
|
||||
* require cvCopy()
|
||||
* @code
|
||||
* CvMat* submat, submathdr;
|
||||
* submat = cvGetRows( mat, &submathdr, start_row, end_row, delta_row );
|
||||
* // Write on submat
|
||||
* @endcode
|
||||
*
|
||||
* @param src Source array
|
||||
* @param dst Target array. Either of array must be size of setting rows.
|
||||
* @param start_row Zero-based index of the starting row (inclusive) of the span.
|
||||
* @param end_row Zero-based index of the ending row (exclusive) of the span.
|
||||
* @param [delta_row = 1]
|
||||
* Index step in the row span. That is, the function extracts every
|
||||
* delta_row-th row from start_row and up to (but not including) end_row.
|
||||
* @return CVAPI(void)
|
||||
* @see cvSetRow( src, dst, row ) // cvSetRows( src, dst, row, row + 1 )
|
||||
*/
|
||||
CVAPI(void) cvSetRows( const CvArr* src, CvArr* dst,
|
||||
int start_row, int end_row, int delta_row CV_DEFAULT(1) )
|
||||
{
|
||||
int coi;
|
||||
CvMat *srcmat = (CvMat*)src, srcmatstub;
|
||||
CvMat *dstmat = (CvMat*)dst, dstmatstub;
|
||||
CvMat *refmat, refmathdr;
|
||||
int rows;
|
||||
CV_FUNCNAME( "cvSetRows" );
|
||||
__CV_BEGIN__;
|
||||
if( !CV_IS_MAT(dstmat) )
|
||||
{
|
||||
CV_CALL( dstmat = cvGetMat( dstmat, &dstmatstub, &coi ) );
|
||||
if (coi != 0) CV_Error(CV_BadCOI, "");//CV_ERROR_FROM_CODE(CV_BadCOI);
|
||||
}
|
||||
if( !CV_IS_MAT(srcmat) )
|
||||
{
|
||||
CV_CALL( srcmat = cvGetMat( srcmat, &srcmatstub, &coi ) );
|
||||
if (coi != 0) CV_Error(CV_BadCOI, "");//CV_ERROR_FROM_CODE(CV_BadCOI);
|
||||
}
|
||||
rows = cvFloor( ( end_row - start_row ) / delta_row );
|
||||
CV_ASSERT( srcmat->rows == rows || dstmat->rows == rows );
|
||||
if( srcmat->rows == rows )
|
||||
{
|
||||
refmat = cvGetRows( dstmat, &refmathdr, start_row, end_row, delta_row );
|
||||
cvCopy( srcmat, refmat );
|
||||
}
|
||||
else
|
||||
{
|
||||
refmat = cvGetRows( srcmat, &refmathdr, start_row, end_row, delta_row );
|
||||
cvCopy( refmat, dstmat );
|
||||
}
|
||||
__CV_END__;
|
||||
}
|
||||
/*
|
||||
CVAPI(void) cvSetRows( const CvArr* subarr, CvArr* arr, int start_row, int end_row )
|
||||
{
|
||||
CV_FUNCNAME( "cvSetRows" );
|
||||
__CV_BEGIN__;
|
||||
int row, col, elem;
|
||||
int coi = 0;
|
||||
CvMat* submat = (CvMat*)subarr, submatstub;
|
||||
CvMat* mat = (CvMat*)arr, matstub;
|
||||
|
||||
if( !CV_IS_MAT(submat) )
|
||||
{
|
||||
CV_CALL( submat = cvGetMat( submat, &submatstub, &coi ) );
|
||||
if (coi != 0) CV_ERROR_FROM_CODE(CV_BadCOI);
|
||||
}
|
||||
if( !CV_IS_MAT(mat) )
|
||||
{
|
||||
CV_CALL( mat = cvGetMat( mat, &matstub, &coi ) );
|
||||
if (coi != 0) CV_ERROR_FROM_CODE(CV_BadCOI);
|
||||
}
|
||||
CV_ARE_TYPES_EQ( submat, mat ); // cxtypes.h
|
||||
//CV_ARE_DEPTHS_EQ( submat, mat );
|
||||
//CV_ARE_CNS_EQ( submat, mat );
|
||||
//CV_ARE_SIZES_EQ( submat, mat );
|
||||
CV_ASSERT( 0 <= start_row && end_row <= mat->rows );
|
||||
CV_ASSERT( end_row - start_row == submat->rows );
|
||||
CV_ASSERT( mat->cols == submat->cols );
|
||||
|
||||
int elem_size = CV_ELEM_SIZE( mat->type );
|
||||
// FYI: CV_ELEM_SIZE returns not number_of_channels, but number_of_uchar*
|
||||
// nChannels = CV_MAT_CN( mat->type ); refer cxarray.cpp#cvRawDataToScalar to separate into channel values
|
||||
for( row = start_row; row < end_row; row++ )
|
||||
{
|
||||
for( col = 0; col < mat->cols; col++ )
|
||||
{
|
||||
//cvSet2D( mat, row, col, cvGet2D( submat, row - start_row, col ) );
|
||||
for( elem = 0; elem < elem_size; elem++ )
|
||||
{
|
||||
// cvPtr2D( mat, row, col )[elem] = cvPtr2D( submat, row - start_row, col )[elem];
|
||||
(mat->data.ptr + ((size_t)mat->step * row) + (elem_size * col))[elem] =
|
||||
(submat->data.ptr + ((size_t)submat->step * (row - start_row)) + (elem_size * col))[elem];
|
||||
}
|
||||
}
|
||||
}
|
||||
__CV_END__;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Set array row
|
||||
*
|
||||
* #define cvSetRow(src, dst, row) (cvSetRows( src, dst, row, row + 1))
|
||||
*/
|
||||
CV_INLINE void cvSetRow( const CvArr* src, CvArr* dst, int row )
|
||||
{
|
||||
cvSetRows( src, dst, row, row+1 );
|
||||
}
|
||||
|
||||
#endif
|
136
3rdparty/include/opencvx/cvskincolorcbcr.h
vendored
Normal file
136
3rdparty/include/opencvx/cvskincolorcbcr.h
vendored
Normal file
@ -0,0 +1,136 @@
|
||||
/** @file */
|
||||
/* Copyright (c) 2008, Naotoshi Seo. All rights reserved.
|
||||
*
|
||||
* The program is free to use for non-commercial academic purposes,
|
||||
* but for course works, you must understand what is going inside to
|
||||
* use. The program can be used, modified, or re-distributed for any
|
||||
* purposes only if you or one of your group understand not only
|
||||
* programming codes but also theory and math behind (if any).
|
||||
* Please contact the authors if you are interested in using the
|
||||
* program without meeting the above conditions.
|
||||
*/
|
||||
#ifndef CV_SKINCOLOR_CBCR_INCLUDED
|
||||
#define CV_SKINCOLOR_CBCR_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
/**
|
||||
* Skin Color Detection in (Cb, Cr) space by [1][2]
|
||||
*
|
||||
* @param img Input image
|
||||
* @param mask Generated mask image. 1 for skin and 0 for others
|
||||
* @param dist The distortion valued array rather than mask if you want
|
||||
*
|
||||
* References)
|
||||
* @verbatim
|
||||
* [1] R.L. Hsu, M. Abdel-Mottaleb, A.K. Jain, "Face Detection in Color Images,"
|
||||
* IEEE Transactions on Pattern Analysis and Machine Intelligence ,vol. 24, no. 5,
|
||||
* pp. 696-706, May, 2002. (Original)
|
||||
* [2] P. Peer, J. Kovac, J. and F. Solina, ”Human skin colour
|
||||
* clustering for face detection”, In: submitted to EUROCON –
|
||||
* International Conference on Computer as a Tool , 2003. (Tuned)
|
||||
* @endverbatim
|
||||
*/
|
||||
CVAPI(void) cvSkinColorCrCb( const IplImage* _img, IplImage* mask, CvArr* _dist CV_DEFAULT(NULL) )
|
||||
{
|
||||
CV_FUNCNAME( "cvSkinColorCbCr" );
|
||||
__CV_BEGIN__;
|
||||
int width = _img->width;
|
||||
int height = _img->height;
|
||||
CvMat* dist = (CvMat*)_dist, diststub;
|
||||
int coi = 0;
|
||||
IplImage* img;
|
||||
|
||||
double Wcb = 46.97;
|
||||
double WLcb = 23;
|
||||
double WHcb = 14;
|
||||
double Wcr = 38.76;
|
||||
double WLcr = 20;
|
||||
double WHcr = 10;
|
||||
double Kl = 125;
|
||||
double Kh = 188;
|
||||
double Ymin = 16;
|
||||
double Ymax = 235;
|
||||
double alpha = 0.56;
|
||||
|
||||
double Cx = 109.38;
|
||||
double Cy = 152.02;
|
||||
double theta = 2.53;
|
||||
double ecx = 1.6;
|
||||
double ecy = 2.41;
|
||||
double a = 25.39;
|
||||
double b = 14.03;
|
||||
|
||||
CV_ASSERT( width == mask->width && height == mask->height );
|
||||
CV_ASSERT( _img->nChannels >= 3 && mask->nChannels == 1 );
|
||||
|
||||
if( dist && !CV_IS_MAT(dist) )
|
||||
{
|
||||
CV_CALL( dist = cvGetMat( dist, &diststub, &coi ) );
|
||||
if (coi != 0) CV_ERROR_FROM_CODE(CV_BadCOI);
|
||||
CV_ASSERT( width == dist->cols && height == dist->rows );
|
||||
CV_ASSERT( CV_MAT_TYPE(dist->type) == CV_32FC1 || CV_MAT_TYPE(dist->type) == CV_64FC1 );
|
||||
}
|
||||
|
||||
img = cvCreateImage( cvGetSize(_img), IPL_DEPTH_8U, 3 );
|
||||
cvCvtColor( _img, img, CV_BGR2YCrCb );
|
||||
|
||||
cvSet( mask, cvScalarAll(0) );
|
||||
for( int row = 0; row < height; row++ )
|
||||
{
|
||||
for( int col = 0; col < width; col++ )
|
||||
{
|
||||
uchar Y = img->imageData[img->widthStep * row + col * 3];
|
||||
uchar Cr = img->imageData[img->widthStep * row + col * 3 + 1];
|
||||
uchar Cb = img->imageData[img->widthStep * row + col * 3 + 2];
|
||||
|
||||
double Cb_Y, Cr_Y, Wcb_Y, Wcr_Y;
|
||||
if( Y < Kl )
|
||||
Wcb_Y = WLcb + (Y - Ymin) * (Wcb - WLcb) / (Kl - Ymin);
|
||||
else if( Kh < Y )
|
||||
Wcb_Y = WHcb + (Ymax - Y) * (Wcb - WHcb) / (Ymax - Kh);
|
||||
else
|
||||
Wcb_Y = Wcb;
|
||||
|
||||
if( Y < Kl )
|
||||
Wcr_Y = WLcr + (Y - Ymin) * (Wcr - WLcr) / (Kl - Ymin);
|
||||
else if( Kh < Y )
|
||||
Wcr_Y = WHcr + (Ymax - Y) * (Wcr - WHcr) / (Ymax - Kh);
|
||||
else
|
||||
Wcr_Y = Wcr;
|
||||
|
||||
if( Y < Kl )
|
||||
Cb_Y = 108 + (Kl - Y) * 10 / ( Kl - Ymin );
|
||||
else if( Kh < Y )
|
||||
Cb_Y = 108 + (Y - Kh) * 10 / ( Ymax - Kh );
|
||||
else
|
||||
Cb_Y = 108;
|
||||
|
||||
if( Y < Kl )
|
||||
Cr_Y = 154 - (Kl - Y) * 10 / ( Kl - Ymin );
|
||||
else if( Kh < Y )
|
||||
Cr_Y = 154 + (Y - Kh) * 22 / ( Ymax - Kh );
|
||||
else
|
||||
Cr_Y = 108;
|
||||
|
||||
double x = cos(theta) * (Cb - Cx) + sin(theta) * (Cr - Cy);
|
||||
double y = -1 * sin(theta) * (Cb - Cx) + cos(theta) * (Cr - Cy);
|
||||
|
||||
double distort = pow(x-ecx,2) / pow(a,2) + pow(y-ecy,2) / pow(b,2);
|
||||
if( dist )
|
||||
cvmSet( dist, row, col, distort );
|
||||
|
||||
if( distort <= 1 )
|
||||
{
|
||||
mask->imageData[mask->widthStep * row + col] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
94
3rdparty/include/opencvx/cvskincolorgauss.h
vendored
Normal file
94
3rdparty/include/opencvx/cvskincolorgauss.h
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
/** @file */
|
||||
/* cvskincolorgauss.h
|
||||
//
|
||||
// Copyright (c) 2008, Naotoshi Seo. All rights reserved.
|
||||
//
|
||||
// The program is free to use for non-commercial academic purposes,
|
||||
// but for course works, you must understand what is going inside to
|
||||
// use. The program can be used, modified, or re-distributed for any
|
||||
// purposes only if you or one of your group understand not only
|
||||
// programming codes but also theory and math behind (if any).
|
||||
// Please contact the authors if you are interested in using the
|
||||
// program without meeting the above conditions.
|
||||
*/
|
||||
#ifndef CV_SKINCOLOR_GAUSS_INCLUDED
|
||||
#define CV_SKINCOLOR_GAUSS_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
/**
|
||||
// Skin Color Detection with a Gaussian model
|
||||
//
|
||||
// @param img Input image
|
||||
// @param mask Generated mask image. 1 for skin and 0 for others
|
||||
// @param factor A factor to determine threshold value.
|
||||
// The default threshold is -2.5 * sigma and 2.5 * sigma which
|
||||
// supports more than 95% region of Gaussian PDF.
|
||||
//
|
||||
// References)
|
||||
// @verbatim
|
||||
// [1] @INPROCEEDINGS{Yang98skin-colormodeling,
|
||||
// author = {Jie Yang and Weier Lu and Alex Waibel},
|
||||
// title = {Skin-color modeling and adaptation},
|
||||
// booktitle = {},
|
||||
// year = {1998},
|
||||
// pages = {687--694}
|
||||
// }
|
||||
// [2] C. Stauffer, and W. E. L. Grimson, “Adaptive
|
||||
// background mixture models for real-time tracking”, In:
|
||||
// Proceedings 1999 IEEE Computer Society Conference
|
||||
// on Computer Vision and Pattern Recognition (Cat. No
|
||||
// PR00149), IEEE Comput. Soc. Part vol. 2, 1999.
|
||||
// @endverbatim
|
||||
*/
|
||||
CVAPI(void) cvSkinColorGauss( const IplImage* _img, IplImage* mask, double factor CV_DEFAULT(2.5) )
|
||||
{
|
||||
double mean[] = { 188.9069, 142.9157, 115.1863 };
|
||||
double sigma[] = { 58.3542, 45.3306, 43.397 };
|
||||
double subdata[3];
|
||||
|
||||
IplImage* img = cvCreateImage( cvGetSize(_img), _img->depth, _img->nChannels );
|
||||
cvCvtColor( _img, img, CV_BGR2RGB );
|
||||
CvMat* mat = cvCreateMat( img->height, img->width, CV_64FC3 );
|
||||
cvConvert( img, mat );
|
||||
|
||||
for( int i = 0; i < mat->rows; i++ )
|
||||
{
|
||||
for( int j = 0; j < mat->cols; j++ )
|
||||
{
|
||||
bool skin;
|
||||
CvScalar data = cvGet2D( mat, i, j );
|
||||
subdata[0] = data.val[0] - mean[0];
|
||||
subdata[1] = data.val[1] - mean[1];
|
||||
subdata[2] = data.val[2] - mean[2];
|
||||
//if( CV_SKINCOLOR_GAUSS_CUBE ) // cube-like judgement
|
||||
//{
|
||||
skin = 1;
|
||||
// 2 * sigma => 95% confidence region, 2.5 gives more
|
||||
skin &= ( - factor *sigma[0] < subdata[0] && subdata[0] < factor *sigma[0] );
|
||||
skin &= ( - factor *sigma[1] < subdata[1] && subdata[1] < factor *sigma[1] );
|
||||
skin &= ( - factor *sigma[2] < subdata[2] && subdata[2] < factor *sigma[2] );
|
||||
//}
|
||||
//else if( CV_SKINCOLOR_GAUSS_ELLIPSOID ) // ellipsoid-like judgement
|
||||
//{
|
||||
// double val = 0;
|
||||
// val += pow( subdata[0] / sigma[0] , 2);
|
||||
// val += pow( subdata[1] / sigma[1] , 2);
|
||||
// val += pow( subdata[2] / sigma[2] , 2);
|
||||
// skin = ( val <= pow( factor , 2 ) );
|
||||
//}
|
||||
//else if( CV_SKINCOLOR_GAUSS_LIKELIHOODRATIO ) // likelihood-ratio test (need data for non-skin gaussain model)
|
||||
//{
|
||||
//}
|
||||
mask->imageData[mask->widthStep * i + j] = skin;
|
||||
}
|
||||
}
|
||||
cvReleaseMat( &mat );
|
||||
cvReleaseImage( &img );
|
||||
}
|
||||
|
||||
|
||||
#endif
|
173
3rdparty/include/opencvx/cvskincolorgmm.h
vendored
Normal file
173
3rdparty/include/opencvx/cvskincolorgmm.h
vendored
Normal file
@ -0,0 +1,173 @@
|
||||
/** @file */
|
||||
/* cvskincolorgmm.h
|
||||
//
|
||||
// Copyright (c) 2008, Naotoshi Seo. All rights reserved.
|
||||
//
|
||||
// The program is free to use for non-commercial academic purposes,
|
||||
// but for course works, you must understand what is going inside to
|
||||
// use. The program can be used, modified, or re-distributed for any
|
||||
// purposes only if you or one of your group understand not only
|
||||
// programming codes but also theory and math behind (if any).
|
||||
// Please contact the authors if you are interested in using the
|
||||
// program without meeting the above conditions.
|
||||
*/
|
||||
#ifndef CV_SKINCOLOR_GMM_INCLUDED
|
||||
#define CV_SKINCOLOR_GMM_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#include "cvxmat.h"
|
||||
#include "cvgmmpdf.h"
|
||||
|
||||
/**
|
||||
// Skin Color Detection with GMM model
|
||||
//
|
||||
// @param img Input image
|
||||
// @param mask Generated mask image. 1 for skin and 0 for others
|
||||
// @param threshold Threshold value for likelihood-ratio test
|
||||
// The preferrable threshold = (number of other pixels / number of skin pixels)
|
||||
// You may guess this value by looking your image.
|
||||
// You may reduce this number when you can allow larger false alaram rate which
|
||||
// results in to reduce reduce miss detection rate.
|
||||
// @param probs The likelihood-ratio valued array rather than mask if you want
|
||||
// @todo Store GMM probabilities as a hash table having 255*255*255 entries.
|
||||
// Then, no more computation is required and the computation finishes immediately.
|
||||
//
|
||||
// References)
|
||||
// @verbatim
|
||||
// @article{606260,
|
||||
// author = {Michael J. Jones and James M. Rehg},
|
||||
// title = {Statistical color models with application to skin detection},
|
||||
// journal = {Int. J. Comput. Vision},
|
||||
// volume = {46},
|
||||
// number = {1},
|
||||
// year = {2002},
|
||||
// issn = {0920-5691},
|
||||
// pages = {81--96},
|
||||
// doi = {http://dx.doi.org/10.1023/A:1013200319198},
|
||||
// publisher = {Kluwer Academic Publishers},
|
||||
// address = {Hingham, MA, USA},
|
||||
// }
|
||||
// @endverbatim
|
||||
*/
|
||||
CVAPI(void) cvSkinColorGmm( const IplImage* _img, IplImage* mask,
|
||||
double threshold CV_DEFAULT(1.0),
|
||||
IplImage* probs CV_DEFAULT(NULL) )
|
||||
{
|
||||
CV_FUNCNAME( "cvSkinColorGmm" );
|
||||
__CV_BEGIN__;
|
||||
const int N = _img->height * _img->width;
|
||||
const int D = 3;
|
||||
const int K = 16;
|
||||
IplImage* img;
|
||||
|
||||
double skin_mean[] = {
|
||||
73.5300, 249.7100, 161.6800, 186.0700, 189.2600, 247.0000, 150.1000, 206.8500, 212.7800, 234.8700, 151.1900, 120.5200, 192.2000, 214.2900, 99.5700, 238.8800,
|
||||
29.9400, 233.9400, 116.2500, 136.6200, 98.3700, 152.2000, 72.6600, 171.0900, 152.8200, 175.4300, 97.7400, 77.5500, 119.6200, 136.0800, 54.3300, 203.0800,
|
||||
17.7600, 217.4900, 96.9500, 114.4000, 51.1800, 90.8400, 37.7600, 156.3400, 120.0400, 138.9400, 74.5900, 59.8200, 82.3200, 87.2400, 38.0600, 176.9100
|
||||
};
|
||||
double skin_cov[] = { // only diagonal components
|
||||
765.4000, 39.9400, 291.0300, 274.9500, 633.1800, 65.2300, 408.6300, 530.0800, 160.5700, 163.8000, 425.4000, 330.4500, 152.7600, 204.9000, 448.1300, 178.3800,
|
||||
121.4400, 154.4400, 60.4800, 64.6000, 222.4000, 691.5300, 200.7700, 155.0800, 84.5200, 121.5700, 73.5600, 70.3400, 92.1400, 140.1700, 90.1800, 156.2700,
|
||||
112.8000, 396.0500, 162.8500, 198.2700, 250.6900, 609.9200, 257.5700, 572.7900, 243.9000, 279.2200, 175.1100, 151.8200, 259.1500, 270.1900, 151.2900, 404.9900
|
||||
};
|
||||
double skin_weight[] = {
|
||||
0.0294, 0.0331, 0.0654, 0.0756, 0.0554, 0.0314, 0.0454, 0.0469, 0.0956, 0.0763, 0.1100, 0.0676, 0.0755, 0.0500, 0.0667, 0.0749
|
||||
};
|
||||
double nonskin_mean[] = {
|
||||
254.3700, 9.3900, 96.5700, 160.4400, 74.9800, 121.8300, 202.1800, 193.0600, 51.8800, 30.8800, 44.9700, 236.0200, 207.8600, 99.8300, 135.0600, 135.9600,
|
||||
254.4100, 8.0900, 96.9500, 162.4900, 63.2300, 60.8800, 154.8800, 201.9300, 57.1400, 26.8400, 85.9600, 236.2700, 191.2000, 148.1100, 131.9200, 103.8900,
|
||||
253.8200, 8.5200, 91.5300, 159.0600, 46.3300, 18.3100, 91.0400, 206.5500, 61.5500, 25.3200, 131.9500, 230.7000, 164.1200, 188.1700, 123.1000, 66.8800
|
||||
};
|
||||
double nonskin_cov[] = { // only diagonal components
|
||||
2.77, 46.84, 280.69, 355.98, 414.84, 2502.2, 957.42, 562.88, 344.11, 222.07, 651.32, 225.03, 494.04, 955.88, 350.35, 806.44,
|
||||
2.81, 33.59, 156.79, 115.89, 245.95, 1383.5, 1766.9, 190.23, 191.77, 118.65, 840.52, 117.29, 237.69, 654.95, 130.3, 642.2,
|
||||
5.46, 32.48, 436.58, 591.24, 361.27, 237.18, 1582.5, 447.28, 433.4, 182.41, 963.67, 331.95, 533.52, 916.7, 388.43, 350.36
|
||||
};
|
||||
double nonskin_weight[] = {
|
||||
0.0637, 0.0516, 0.0864, 0.0636, 0.0747, 0.0365, 0.0349, 0.0649, 0.0656, 0.1189, 0.0362, 0.0849, 0.0368, 0.0389, 0.0943, 0.0477
|
||||
};
|
||||
|
||||
CV_ASSERT( _img->width == mask->width && _img->height == mask->height );
|
||||
CV_ASSERT( _img->nChannels >= 3 && mask->nChannels == 1 );
|
||||
if( probs )
|
||||
{
|
||||
CV_ASSERT( _img->width == probs->width && _img->height == probs->height );
|
||||
CV_ASSERT( probs->nChannels == 1 );
|
||||
}
|
||||
|
||||
img = cvCreateImage( cvGetSize(_img), _img->depth, _img->nChannels );
|
||||
cvCvtColor( _img, img, CV_BGR2RGB );
|
||||
|
||||
// transform to CvMat
|
||||
CvMat SkinMeans = cvMat( D, K, CV_64FC1, skin_mean );
|
||||
CvMat SkinWeights = cvMat( 1, K, CV_64FC1, skin_weight );
|
||||
CvMat **SkinCovs = (CvMat**)cvAlloc( K * sizeof( CvMat* ) );
|
||||
for( int k = 0; k < K; k++ )
|
||||
{
|
||||
SkinCovs[k] = cvCreateMat( D, D, CV_64FC1 );
|
||||
cvZero( SkinCovs[k] );
|
||||
for( int i = 0; i < D; i++ )
|
||||
{
|
||||
cvmSet( SkinCovs[k], i, i, skin_cov[K * i + k] );
|
||||
}
|
||||
}
|
||||
|
||||
// transform to CvMat
|
||||
CvMat NonSkinMeans = cvMat( D, K, CV_64FC1, nonskin_mean );
|
||||
CvMat NonSkinWeights = cvMat( 1, K, CV_64FC1, nonskin_weight );
|
||||
CvMat **NonSkinCovs = (CvMat**)cvAlloc( K * sizeof( CvMat* ) );
|
||||
for( int k = 0; k < K; k++ )
|
||||
{
|
||||
NonSkinCovs[k] = cvCreateMat( D, D, CV_64FC1 );
|
||||
cvZero( NonSkinCovs[k] );
|
||||
for( int i = 0; i < D; i++ )
|
||||
{
|
||||
cvmSet( NonSkinCovs[k], i, i, nonskin_cov[K * i + k] );
|
||||
}
|
||||
}
|
||||
|
||||
// reshape IplImage to D (colors) x N matrix of CV_64FC1
|
||||
CvMat *Mat = cvCreateMat( D, N, CV_64FC1 );
|
||||
CvMat *PreMat, hdr;
|
||||
PreMat = cvCreateMat( img->height, img->width, CV_64FC3 );
|
||||
cvConvert( img, PreMat );
|
||||
cvTranspose( cvReshape( PreMat, &hdr, 1, N ), Mat );
|
||||
cvReleaseMat( &PreMat );
|
||||
|
||||
// GMM PDF
|
||||
CvMat *SkinProbs = cvCreateMat(1, N, CV_64FC1);
|
||||
CvMat *NonSkinProbs = cvCreateMat(1, N, CV_64FC1);
|
||||
|
||||
cvMatGmmPdf( Mat, &SkinMeans, SkinCovs, &SkinWeights, SkinProbs, true);
|
||||
cvMatGmmPdf( Mat, &NonSkinMeans, NonSkinCovs, &NonSkinWeights, NonSkinProbs, true);
|
||||
|
||||
// Likelihood-ratio test
|
||||
CvMat *Mask = cvCreateMat( 1, N, CV_8UC1 );
|
||||
cvDiv( SkinProbs, NonSkinProbs, SkinProbs );
|
||||
cvThreshold( SkinProbs, Mask, threshold, 1, CV_THRESH_BINARY );
|
||||
cvConvert( cvReshape( Mask, &hdr, 1, img->height ), mask );
|
||||
|
||||
if( probs ) cvConvert( cvReshape( SkinProbs, &hdr, 1, img->height ), probs );
|
||||
|
||||
for( int k = 0; k < K; k++ )
|
||||
{
|
||||
cvReleaseMat( &SkinCovs[k] );
|
||||
cvReleaseMat( &NonSkinCovs[k] );
|
||||
}
|
||||
cvFree( &SkinCovs );
|
||||
cvFree( &NonSkinCovs );
|
||||
|
||||
cvReleaseMat( &SkinProbs );
|
||||
cvReleaseMat( &NonSkinProbs );
|
||||
cvReleaseMat( &Mask );
|
||||
cvReleaseImage( &img );
|
||||
|
||||
__CV_END__;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
60
3rdparty/include/opencvx/cvskincolorpeer.h
vendored
Normal file
60
3rdparty/include/opencvx/cvskincolorpeer.h
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
/** @file */
|
||||
/*
|
||||
// Copyright (c) 2008, Naotoshi Seo. All rights reserved.
|
||||
//
|
||||
// The program is free to use for non-commercial academic purposes,
|
||||
// but for course works, you must understand what is going inside to
|
||||
// use. The program can be used, modified, or re-distributed for any
|
||||
// purposes only if you or one of your group understand not only
|
||||
// programming codes but also theory and math behind (if any).
|
||||
// Please contact the authors if you are interested in using the
|
||||
// program without meeting the above conditions.
|
||||
*/
|
||||
#ifndef CV_SKINCOLOR_PEER_INCLUDED
|
||||
#define CV_SKINCOLOR_PEER_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
// Skin Color Detection by Peer, et.al [1]
|
||||
//
|
||||
// @param img Input image
|
||||
// @param mask Generated mask image. 1 for skin and 0 for others
|
||||
//
|
||||
// References)
|
||||
// @verbatim
|
||||
// [1] P. Peer, J. Kovac, J. and F. Solina, ”Human skin colour
|
||||
// clustering for face detection”, In: submitted to EUROCON –
|
||||
// International Conference on Computer as a Tool , 2003.
|
||||
// (R>95)^(G>40)^(B>20)^
|
||||
// (max{R,G,B}-min{R,G,B}>15)^
|
||||
// (|R -G|>15)^(R>G)^(R>B)
|
||||
// @endverbatim
|
||||
*/
|
||||
CVAPI(void) cvSkinColorPeer( const IplImage* img, IplImage* mask )
|
||||
{
|
||||
int x, y;
|
||||
uchar r, g, b;
|
||||
cvSet( mask, cvScalarAll(0) );
|
||||
for( y = 0; y < img->height; y++ )
|
||||
{
|
||||
for( x = 0; x < img->width; x++ )
|
||||
{
|
||||
b = img->imageData[img->widthStep * y + x * 3];
|
||||
g = img->imageData[img->widthStep * y + x * 3 + 1];
|
||||
r = img->imageData[img->widthStep * y + x * 3 + 2];
|
||||
|
||||
if( r > 95 && g > 40 && b > 20 &&
|
||||
MAX( r, MAX( g, b ) ) - MIN( r, MIN( g, b ) ) > 15 &&
|
||||
abs( r - g ) > 15 && r > g && r > b )
|
||||
{
|
||||
mask->imageData[mask->widthStep * y + x] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
68
3rdparty/include/opencvx/cvwaitfps.h
vendored
Normal file
68
3rdparty/include/opencvx/cvwaitfps.h
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_WAITFPS_INCLUDED
|
||||
#define CV_WAITFPS_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
/**
|
||||
* Wait amount of seconds per frame totally.
|
||||
*
|
||||
* If processing time exceeded the seconds per frame,
|
||||
* no wait occurs and negative waiting time is returned.
|
||||
*
|
||||
* Example)
|
||||
* @code
|
||||
* // #include <time.h>
|
||||
* clock_t start = clock();
|
||||
* fps = cvGetCaptureProperty(video, CV_CAP_PROP_FPS);
|
||||
* // process
|
||||
* cvWaitFps( fps, start );
|
||||
* @endcode
|
||||
*
|
||||
* @param fps Frame per second. fps video property
|
||||
* @param start Start time
|
||||
* @return Wait time
|
||||
*/
|
||||
clock_t cvWaitFps( double fps, clock_t start CV_DEFAULT(0) )
|
||||
{
|
||||
clock_t msec_per_frame = (clock_t)( 1.0 / (double) fps * 1000 );
|
||||
clock_t current = clock();
|
||||
clock_t wait_time;
|
||||
if( start == 0 ) {
|
||||
wait_time = msec_per_frame;
|
||||
} else {
|
||||
wait_time = msec_per_frame - (current - start);
|
||||
}
|
||||
//while( clock() - current < wait_time ) {}
|
||||
cvWaitKey( wait_time > 0 ? wait_time : 1 );
|
||||
return wait_time;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
38
3rdparty/include/opencvx/cvxmat.h
vendored
Normal file
38
3rdparty/include/opencvx/cvxmat.h
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_MATEXT_INCLUDED
|
||||
#define CV_MATEXT_INCLUDED
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
|
||||
#include "cvmatelemcn.h"
|
||||
#include "cvprintmat.h"
|
||||
#include "cvsetrow.h"
|
||||
#include "cvsetcol.h"
|
||||
#include "cvcat.h"
|
||||
|
||||
|
||||
#endif
|
36
3rdparty/include/opencvx/cvxmorphological.h
vendored
Normal file
36
3rdparty/include/opencvx/cvxmorphological.h
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_MORPHOLOGICAL_INCLUDED
|
||||
#define CV_MORPHOLOGICAL_INCLUDED
|
||||
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
|
||||
#include "cvopening.h"
|
||||
#include "cvclosing.h"
|
||||
#include "cvsandwichfill.h"
|
||||
|
||||
|
||||
#endif
|
48
3rdparty/include/opencvx/cvxrectangle.h
vendored
Normal file
48
3rdparty/include/opencvx/cvxrectangle.h
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)umd.edu>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_RECTANGLE_INCLUDED
|
||||
#define CV_RECTANGLE_INCLUDED
|
||||
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include "cxcore.h"
|
||||
#include "highgui.h"
|
||||
#include <stdio.h>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
using namespace std;
|
||||
|
||||
#include "cvrect32f.h"
|
||||
#include "cvcreateaffine.h"
|
||||
#include "cvdrawrectangle.h"
|
||||
#include "cvcropimageroi.h"
|
||||
#include "cvpointnorm.h"
|
||||
#include "cvrectpoints.h"
|
||||
#include "cvpointrecttest.h"
|
||||
#include "cvinvaffine.h"
|
||||
#include "cvcreateaffineimage.h"
|
||||
#include "cvputimageroi.h"
|
||||
|
||||
#endif
|
41
3rdparty/include/opencvx/cvxskincolor.h
vendored
Normal file
41
3rdparty/include/opencvx/cvxskincolor.h
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
/** @file */
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef CV_SKINCOLOR_INCLUDED
|
||||
#define CV_SKINCOLOR_INCLUDED
|
||||
|
||||
|
||||
#include "cv.h"
|
||||
#include "cvaux.h"
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <math.h>
|
||||
|
||||
#include "cvskincolorpeer.h"
|
||||
#include "cvskincolorgmm.h"
|
||||
#include "cvskincolorgauss.h"
|
||||
#include "cvskincolorcbcr.h"
|
||||
|
||||
|
||||
#endif
|
202
3rdparty/include/opencvx/mexx.h
vendored
Normal file
202
3rdparty/include/opencvx/mexx.h
vendored
Normal file
@ -0,0 +1,202 @@
|
||||
/** @file
|
||||
* Matlab C Library (MEX) eXtension
|
||||
* verified Matlab 2007b
|
||||
*/
|
||||
/* The MIT License
|
||||
*
|
||||
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#ifndef MXX_INCLUDED
|
||||
#define MXX_INCLUDED
|
||||
|
||||
|
||||
#include "mat.h"
|
||||
#include "matrix.h"
|
||||
|
||||
/**
|
||||
* definitions
|
||||
*/
|
||||
CVAPI(void) mxPrintMatrix(const mxArray* mxarr);
|
||||
CVAPI(void) mxSetCol(mxArray* X, mxArray* X1, int col);
|
||||
CVAPI(void) mxSetRow(mxArray* X, mxArray* X1, int row);
|
||||
mxArray* mxGetCol(mxArray* X, int col);
|
||||
mxArray* mxGetRow(mxArray* X, int row);
|
||||
|
||||
|
||||
/**
|
||||
* Get a pointer to (row,col)
|
||||
*
|
||||
* @param mxArray *X 2-D Array
|
||||
* @param type object type such as double, uint
|
||||
* @param int row
|
||||
* @param int col
|
||||
*/
|
||||
#define MX_ARRAY_ELEM(X, type, row, col) (((type*)mxGetPr(X))[mxGetM(X)*col+row])
|
||||
|
||||
/**
|
||||
* Print mxArray
|
||||
*
|
||||
* Currently support only uint8, float, double
|
||||
* Currently support only upto 3-D.
|
||||
*
|
||||
* @param mxArray* mxarr
|
||||
* @return CVAPI(void)
|
||||
*/
|
||||
CVAPI(void) mxPrintMatrix(const mxArray* mxarr)
|
||||
{
|
||||
int nDim;
|
||||
const mwSize *dims;
|
||||
int row, col, ch, nChannel = 1;
|
||||
mxClassID classid;
|
||||
classid = mxGetClassID(mxarr);
|
||||
nDim = mxGetNumberOfDimensions(mxarr);
|
||||
dims = mxGetDimensions(mxarr);
|
||||
if (nDim >= 3) nChannel = dims[2];
|
||||
|
||||
if (classid == mxUINT8_CLASS) {
|
||||
unsigned char *mxData = (unsigned char*)mxGetData(mxarr);
|
||||
for (ch = 0; ch < nChannel; ch++) {
|
||||
for (row = 0; row < dims[0]; row++) {
|
||||
for (col = 0; col < dims[1]; col++) {
|
||||
printf("%d ", mxData[
|
||||
dims[0] * dims[1] * ch + dims[0] * col + row]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
} else if (classid == mxDOUBLE_CLASS) {
|
||||
double *mxData = (double*)mxGetData(mxarr);
|
||||
for (ch = 0; ch < nChannel; ch++) {
|
||||
for (row = 0; row < dims[0]; row++) {
|
||||
for (col = 0; col < dims[1]; col++) {
|
||||
printf("%lf ", mxData[
|
||||
dims[0] * dims[1] * ch + dims[0] * col + row]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
} else if (classid == mxSINGLE_CLASS) {
|
||||
float *mxData = (float*)mxGetData(mxarr);
|
||||
for (ch = 0; ch < nChannel; ch++) {
|
||||
for (row = 0; row < dims[0]; row++) {
|
||||
for (col = 0; col < dims[1]; col++) {
|
||||
printf("%lf ", mxData[
|
||||
dims[0] * dims[1] * ch + dims[0] * col + row]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a column
|
||||
*
|
||||
* @param mxArray *X 2-D Array
|
||||
* @param int col
|
||||
* @return mxArray*
|
||||
*/
|
||||
CVAPI(void) mxSetCol(mxArray* X, mxArray* X1, int col)
|
||||
{
|
||||
int nRow = mxGetM(X);
|
||||
int nCol = mxGetN(X);
|
||||
int row = 0;
|
||||
double *Xdata, *X1data;
|
||||
Xdata = (double*)mxGetPr(X);
|
||||
X1data = (double*)mxGetPr(X1);
|
||||
for (row = 0; row < nRow; row++) {
|
||||
Xdata[nRow * col + row] = X1data[row];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a row
|
||||
*
|
||||
* @param mxArray *X 2-D Array
|
||||
* @param int col
|
||||
* @return mxArray*
|
||||
*/
|
||||
CVAPI(void) mxSetRow(mxArray* X, mxArray* X1, int row)
|
||||
{
|
||||
int nRow = mxGetM(X);
|
||||
int nCol = mxGetN(X);
|
||||
int col = 0;
|
||||
double *Xdata, *X1data;
|
||||
Xdata = (double*)mxGetPr(X);
|
||||
X1data = (double*)mxGetPr(X1);
|
||||
for (col = 0; col < nCol; col++) {
|
||||
Xdata[nRow * col + row] = X1data[col];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a column
|
||||
*
|
||||
* @param mxArray *X 2-D Array
|
||||
* @param int col
|
||||
* @return mxArray*
|
||||
*/
|
||||
mxArray* mxGetCol(mxArray* X, int col)
|
||||
{
|
||||
int nRow = mxGetM(X);
|
||||
int nCol = mxGetN(X);
|
||||
int row = 0;
|
||||
mxArray *X1;
|
||||
double *Xdata, *X1data;
|
||||
if(col > nCol) return NULL;
|
||||
X1 = mxCreateDoubleMatrix(nRow, 1, mxREAL);
|
||||
Xdata = (double*)mxGetPr(X);
|
||||
X1data = (double*)mxGetPr(X1);
|
||||
for (row = 0; row < nRow; row++) {
|
||||
X1data[row] = Xdata[nRow * col + row];
|
||||
}
|
||||
return X1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a row
|
||||
*
|
||||
* @param mxArray *X 2-D Array
|
||||
* @param int row
|
||||
* @return mxArray*
|
||||
*/
|
||||
mxArray* mxGetRow(mxArray* X, int row)
|
||||
{
|
||||
int nRow = mxGetM(X);
|
||||
int nCol = mxGetN(X);
|
||||
int col = 0;
|
||||
mxArray *X1;
|
||||
double *Xdata, *X1data;
|
||||
if(row > nRow) return NULL;
|
||||
X1 = mxCreateDoubleMatrix(1, nCol, mxREAL);
|
||||
Xdata = (double*)mxGetPr(X);
|
||||
X1data = (double*)mxGetPr(X1);
|
||||
for (col = 0; col < nCol; col++) {
|
||||
X1data[col] = Xdata[nRow * col + row];
|
||||
}
|
||||
return X1;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user