📄 ahistograms.cpp
字号:
/*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 "CVTest.h"
static int foaHistGetQueryValue(void* _type)
{
CvHistType type = (CvHistType)(int)_type;
static int c_dimss;
static int dims;
static int init = 0;
CvHistogram* hist;
int d[CV_HIST_MAX_DIM + 1];
int i, c_dims;
float num;
float* ptr;
int errors = 0;
if( !init )
{
init = 1;
trsiRead( &c_dimss, "6", "Number of dimensions" );
trsiRead( &dims, "10", "Size of every dimension" );
}
for( c_dims = 1; c_dims <= c_dimss; c_dims++ )
{
/* Filling dimension's array */
for( i = 0; i < c_dims; i++ ) d[i] = dims;
/*Creating histogram*/
hist = cvCreateHist( c_dims, d, type );
/*Initializing histogram*/
num = 0;
for( i = 0; i <= CV_HIST_MAX_DIM; i++ ) d[i] = 0;
for( i = 0; i < c_dims; )
{
ptr = cvGetHistValue_nD( hist, d );
*ptr = num;
for( i = 0; d[i]++, d[i] >= dims && i < CV_HIST_MAX_DIM; i++ ) d[i] = 0;
}
/*Checking values*/
num = 0;
for( i = 0; i < c_dims; i++ ) d[i] = 0;
for( i = 0; i < c_dims; )
{
if( cvQueryHistValue_nD( hist, d ) != num )
{
trsWrite( ATS_CON | ATS_LST, "Error in Get/Set nD\n" );
errors++;
}
if( c_dims == 1 && cvQueryHistValue_1D( hist, d[0] ) != num )
{
trsWrite( ATS_CON | ATS_LST, "Error in Query1D/Set nD\n" );
errors++;
}
if( c_dims == 2 && cvQueryHistValue_2D( hist, d[0], d[1] ) != num )
{
trsWrite( ATS_CON | ATS_LST, "Error in Query2D/Set nD\n" );
errors++;
}
if( c_dims == 3 && cvQueryHistValue_3D( hist, d[0], d[1], d[2] ) != num )
{
trsWrite( ATS_CON | ATS_LST, "Error in Query3D/Set nD\n" );
errors++;
}
if( c_dims == 1 && *cvGetHistValue_1D( hist, d[0] ) != num )
{
trsWrite( ATS_CON | ATS_LST, "Error in Get1D/Set nD\n" );
errors++;
}
if( c_dims == 2 && *cvGetHistValue_2D( hist, d[0], d[1] ) != num )
{
trsWrite( ATS_CON | ATS_LST, "Error in Get2D/Set nD\n" );
errors++;
}
if( c_dims == 3 && *cvGetHistValue_3D( hist, d[0], d[1], d[2] ) != num )
{
trsWrite( ATS_CON | ATS_LST, "Error in Get3D/Set nD\n" );
errors++;
}
for( i = 0; d[i]++, d[i] >= dims && i < CV_HIST_MAX_DIM; i++ ) d[i] = 0;
}
cvReleaseHist( &hist );
}
return errors ? trsResult( TRS_FAIL, "Fixed %d errors", errors ) : TRS_OK;
}
static int foaHistMinMaxValue(void* _type)
{
CvHistType type = (CvHistType)(int)_type;
static int c_dimss;
static int dims;
static int init = 0;
CvHistogram* hist;
int d[CV_HIST_MAX_DIM + 1];
int dmax[CV_HIST_MAX_DIM + 1];
int dmin[CV_HIST_MAX_DIM + 1];
int dmaxc[CV_HIST_MAX_DIM + 1];
int dminc[CV_HIST_MAX_DIM + 1];
int i, j, c_dims;
float min_val = 101, max_val = -101, cmin, cmax;
float v;
float* ptr;
int errors = 0;
if( !init )
{
init = 1;
trsiRead( &c_dimss, "6", "Number of dimensions" );
trsiRead( &dims, "10", "Size of every dimension" );
}
for( c_dims = 1; c_dims <= c_dimss; c_dims++ )
{
min_val = 101;
max_val = -101;
trsWrite(ATS_CON | ATS_LST, "Dimension %d\n", c_dims);
/* Filling dimension's array */
for( i = 0; i < c_dims; i++ ) d[i] = dims;
/*Creating histogram*/
hist = cvCreateHist( c_dims, d, type );
/*Initializing histogram*/
for( i = 0; i <= CV_HIST_MAX_DIM; i++ ) d[i] = 0;
for( i = 0; i < c_dims; )
{
ptr = cvGetHistValue_nD( hist, d );
do{
v = (float)atsInitRandom( -100, 100 );
}while( v == min_val || v == max_val );
if( v > max_val )
{
max_val = v;
for( j = 0; j < c_dims; j++ ) dmax[j] = d[j];
}
if( v < min_val )
{
min_val = v;
for( j = 0; j < c_dims; j++ ) dmin[j] = d[j];
}
*ptr = v;
for( i = 0; d[i]++, d[i] >= dims && i < CV_HIST_MAX_DIM; i++ ) d[i] = 0;
}
/*Checking values*/
cvGetMinMaxHistValue( hist, &cmin, &cmax, dminc, dmaxc );
if( cmin != min_val )
{
trsWrite( ATS_LST | ATS_CON, "Wrong minimum value: act %f exp %f\n", cmin, min_val );
errors++;
}
if( cmax != max_val )
{
trsWrite( ATS_LST | ATS_CON, "Wrong maximum value: act %f exp %f\n", cmax, max_val );
errors++;
}
if( min_val != cvQueryHistValue_nD(hist, dminc) )
{
trsWrite( ATS_LST | ATS_CON, "Wrong minimum pointer: act exp \n" );
for( i = 0; i < c_dims; i++ )
trsWrite( ATS_LST | ATS_CON, "%d %d\n", dminc[i], dmin[i] );
errors++;
}
if( max_val != cvQueryHistValue_nD(hist, dmaxc) )
{
trsWrite( ATS_LST | ATS_CON, "Wrong maximum value: act exp \n" );
for( i = 0; i < c_dims; i++ )
trsWrite( ATS_LST | ATS_CON, "%d %d\n", dmaxc[i], dmax[i] );
errors++;
}
cvReleaseHist( &hist );
}
/*assert(!errors);*/
return errors ? trsResult( TRS_FAIL, "Fixed %d errors", errors ) : TRS_OK;
}
static int foaNormalizeHist(void* _type)
{
CvHistType type = (CvHistType)(int)_type;
static int c_dimss;
static int dims;
static int init = 0;
static float thresh;
CvHistogram* hist1;
CvHistogram* hist2;
int d[CV_HIST_MAX_DIM + 1];
int i, j, count, c_dims;
float sum, v;
int errors = 0;
if( !init )
{
init = 1;
trsiRead( &c_dimss, "6", "Number of dimensions" );
trsiRead( &dims, "10", "Size of every dimension" );
trssRead( &thresh, "0.000001", "Max error value" );
}
for( c_dims = 1; c_dims <= c_dimss; c_dims++ )
{
count = 0;
sum = 0;
/* Filling dimension's array */
for( i = 0; i <= CV_HIST_MAX_DIM; i++ ) d[i] = dims;
/*Creating histogram*/
hist1 = cvCreateHist( c_dims, d, type );
hist2 = cvCreateHist( c_dims, d, type );
/*Initializing histogram*/
for( i = 0; i < c_dims; i++ ) d[i] = 0;
for( i = 0; i < c_dims; )
{
v = (float)atsInitRandom( 0, 100 );
*cvGetHistValue_nD( hist1, d ) = v;
*cvGetHistValue_nD( hist2, d ) = v;
count++;
sum += v;
for( i = 0; d[i]++, d[i] >= dims && i < CV_HIST_MAX_DIM; i++ ) d[i] = 0;
}
/*Checking values*/
cvNormalizeHist( hist1, 1 );
for( i = 0; i < c_dims; i++ ) d[i] = 0;
for( i = 0; i < c_dims; )
{
if( fabs( cvQueryHistValue_nD( hist1, d ) - cvQueryHistValue_nD( hist2, d ) / sum ) >
thresh )
{
trsWrite( ATS_CON | ATS_LST, "Error: act %f exp %f address ",
cvQueryHistValue_nD( hist1, d ), cvQueryHistValue_nD( hist2, d ) / sum );
for( j = 0; j < c_dims; j++ ) trsWrite(ATS_CON | ATS_LST, "%d ", d[j] );
trsWrite(ATS_CON | ATS_LST, "\n");
errors++;
}
for( i = 0; d[i]++, d[i] >= dims && i < CV_HIST_MAX_DIM; i++ ) d[i] = 0;
}
cvReleaseHist( &hist1 );
cvReleaseHist( &hist2 );
}
return errors ? trsResult( TRS_FAIL, "Fixed %d errors", errors ) : TRS_OK;
}
static int foaThreshHist(void* _type)
{
CvHistType type = (CvHistType)(int)_type;
static int c_dimss;
static int dims;
static int init = 0;
static float thresh;
CvHistogram* hist1;
CvHistogram* hist2;
int d[CV_HIST_MAX_DIM + 1];
int i, j, count, c_dims;
float sum, v;
int errors = 0;
if( !init )
{
init = 1;
trsiRead( &c_dimss, "1", "Number of dimensions" );
trsiRead( &dims, "10", "Size of every dimension" );
trssRead( &thresh, "50", "Threshold value" );
}
for( c_dims = 1; c_dims <= c_dimss; c_dims++ )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -