cveigenobjectswrap.cpp.svn-base
来自「非结构化路识别」· SVN-BASE 代码 · 共 732 行 · 第 1/3 页
SVN-BASE
732 行
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "_cv.h"
/*--------------------------------------------------------------------------------------*/
/*F///////////////////////////////////////////////////////////////////////////////////////
// Name: cvCalcCovarMatrixEx
// Purpose: The function calculates a covariance matrix for a group of input objects
// (images, vectors, etc.).
// Context:
// Parameters: nObjects - number of source objects
// input - pointer either to array of input objects
// or to read callback function (depending on ioFlags)
// ioFlags - input/output flags (see Notes to
// cvCalcEigenObjects function)
// ioBufSize - input/output buffer size
// userData - pointer to the structure which contains all necessary
// data for the callback functions
// avg - averaged object
// covarMatrix - covariance matrix (output parameter; must be allocated
// before call)
//
// Notes: See Notes to cvCalcEigenObjects function
//F*/
CV_IMPL void
cvCalcCovarMatrixEx( int nObjects,
void* input,
int ioFlags,
int ioBufSize,
uchar* buffer,
void* userData,
IplImage* avg,
float* covarMatrix )
{
float *avg_data;
int avg_step = 0;
CvSize avg_size;
int i;
CV_FUNCNAME( "cvCalcCovarMatrixEx" );
__BEGIN__;
CV_CALL( CV_CHECK_IMAGE( avg ));
cvGetImageRawData( avg, (uchar **) & avg_data, &avg_step, &avg_size );
if( avg->depth != IPL_DEPTH_32F )
CV_ERROR( CV_BadDepth, icvUnsupportedFormat );
if( avg->nChannels != 1 )
CV_ERROR( CV_BadNumChannels, icvUnsupportedFormat );
if( ioFlags == CV_EIGOBJ_NO_CALLBACK )
{
IplImage **images = (IplImage **) (((CvInput *) & input)->data);
uchar **objects = (uchar **) icvAlloc( sizeof( uchar * ) * nObjects );
int img_step = 0, old_step = 0;
CvSize img_size = avg_size, old_size = avg_size;
if( objects == NULL )
CV_ERROR( CV_StsBadArg, "Insufficient memory" );
for( i = 0; i < nObjects; i++ )
{
IplImage *img = images[i];
uchar *img_data;
CV_CALL( CV_CHECK_IMAGE( img ));
cvGetImageRawData( img, &img_data, &img_step, &img_size );
if( img->depth != IPL_DEPTH_8U )
CV_ERROR( CV_BadDepth, icvUnsupportedFormat );
if( img_size != avg_size || img_size != old_size )
CV_ERROR( CV_StsBadArg, "Different sizes of objects" );
if( img->nChannels != 1 )
CV_ERROR( CV_BadNumChannels, icvUnsupportedFormat );
if( i > 0 && img_step != old_step )
CV_ERROR( CV_StsBadArg, "Different steps of objects" );
old_step = img_step;
old_size = img_size;
objects[i] = img_data;
}
CV_CALL( icvCalcCovarMatrixEx_8u32fR( nObjects,
(void*) objects,
img_step,
CV_EIGOBJ_NO_CALLBACK,
0,
NULL,
NULL,
avg_data,
avg_step,
avg_size,
covarMatrix ));
icvFree( (void**) &objects );
}
else
{
CV_CALL( icvCalcCovarMatrixEx_8u32fR( nObjects,
input,
avg_step / 4,
ioFlags,
ioBufSize,
buffer,
userData,
avg_data,
avg_step,
avg_size,
covarMatrix ));
}
__CLEANUP__;
__END__;
}
/*F///////////////////////////////////////////////////////////////////////////////////////
// Name: cvCalcEigenObjects
// Purpose: The function calculates an orthonormal eigen basis and a mean (averaged)
// object for a group of input objects (images, vectors, etc.).
// Context:
// Parameters: nObjects - number of source objects
// input - pointer either to array of input objects
// or to read callback function (depending on ioFlags)
// output - pointer either to output eigen objects
// or to write callback function (depending on ioFlags)
// ioFlags - input/output flags (see Notes)
// ioBufSize - input/output buffer size
// userData - pointer to the structure which contains all necessary
// data for the callback functions
// calcLimit - determines the calculation finish conditions
// avg - averaged object (has the same size as ROI)
// eigVals - pointer to corresponding eigen values (array of <nObjects>
// elements in descending order)
//
// Notes: 1. input/output data (that is, input objects and eigen ones) may either
// be allocated in the RAM or be read from/written to the HDD (or any
// other device) by read/write callback functions. It depends on the
// value of ioFlags paramater, which may be the following:
// CV_EIGOBJ_NO_CALLBACK, or 0;
// CV_EIGOBJ_INPUT_CALLBACK;
// CV_EIGOBJ_OUTPUT_CALLBACK;
// CV_EIGOBJ_BOTH_CALLBACK, or
// CV_EIGOBJ_INPUT_CALLBACK | CV_EIGOBJ_OUTPUT_CALLBACK.
// The callback functions as well as the user data structure must be
// developed by the user.
//
// 2. If ioBufSize = 0, or it's too large, the function dermines buffer size
// itself.
//
// 3. Depending on calcLimit parameter, calculations are finished either if
// eigenfaces number comes up to certain value or the relation of the
// current eigenvalue and the largest one comes down to certain value
// (or any of the above conditions takes place). The calcLimit->type value
// must be CV_TERMCRIT_NUMB, CV_TERMCRIT_EPS or
// CV_TERMCRIT_NUMB | CV_TERMCRIT_EPS. The function returns the real
// values calcLimit->maxIter and calcLimit->epsilon.
//
// 4. eigVals may be equal to NULL (if you don't need eigen values in further).
//
//F*/
CV_IMPL void
cvCalcEigenObjects( int nObjects,
void* input,
void* output,
int ioFlags,
int ioBufSize,
void* userData,
CvTermCriteria* calcLimit,
IplImage* avg,
float* eigVals )
{
float *avg_data;
int avg_step = 0;
CvSize avg_size;
int i;
int nEigens = nObjects - 1;
CV_FUNCNAME( "cvCalcEigenObjects" );
__BEGIN__;
CV_CALL( CV_CHECK_IMAGE( avg ));
cvGetImageRawData( avg, (uchar **) & avg_data, &avg_step, &avg_size );
if( avg->depth != IPL_DEPTH_32F )
CV_ERROR( CV_BadDepth, icvUnsupportedFormat );
if( avg->nChannels != 1 )
CV_ERROR( CV_BadNumChannels, icvUnsupportedFormat );
if( nEigens > calcLimit->maxIter && calcLimit->type != CV_TERMCRIT_EPS )
nEigens = calcLimit->maxIter;
switch (ioFlags)
{
case CV_EIGOBJ_NO_CALLBACK:
{
IplImage **objects = (IplImage **) (((CvInput *) & input)->data);
IplImage **eigens = (IplImage **) (((CvInput *) & output)->data);
uchar **objs = (uchar **) icvAlloc( sizeof( uchar * ) * nObjects );
float **eigs = (float **) icvAlloc( sizeof( float * ) * nEigens );
int obj_step = 0, old_step = 0;
int eig_step = 0, oldeig_step = 0;
CvSize obj_size = avg_size, old_size = avg_size,
eig_size = avg_size, oldeig_size = avg_size;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?