--- /dev/null
+/*M///////////////////////////////////////////////////////////////////////////////////////\r
+//\r
+// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
+//\r
+// By downloading, copying, installing or using the software you agree to this license.\r
+// If you do not agree to this license, do not download, install,\r
+// copy or use the software.\r
+//\r
+//\r
+// Intel License Agreement\r
+// For Open Source Computer Vision Library\r
+//\r
+// Copyright (C) 2000, Intel Corporation, all rights reserved.\r
+// Third party copyrights are property of their respective owners.\r
+//\r
+// Redistribution and use in source and binary forms, with or without modification,\r
+// are permitted provided that the following conditions are met:\r
+//\r
+// * Redistribution's of source code must retain the above copyright notice,\r
+// this list of conditions and the following disclaimer.\r
+//\r
+// * Redistribution's in binary form must reproduce the above copyright notice,\r
+// this list of conditions and the following disclaimer in the documentation\r
+// and/or other materials provided with the distribution.\r
+//\r
+// * The name of Intel Corporation may not be used to endorse or promote products\r
+// derived from this software without specific prior written permission.\r
+//\r
+// This software is provided by the copyright holders and contributors "as is" and\r
+// any express or implied warranties, including, but not limited to, the implied\r
+// warranties of merchantability and fitness for a particular purpose are disclaimed.\r
+// In no event shall the Intel Corporation or contributors be liable for any direct,\r
+// indirect, incidental, special, exemplary, or consequential damages\r
+// (including, but not limited to, procurement of substitute goods or services;\r
+// loss of use, data, or profits; or business interruption) however caused\r
+// and on any theory of liability, whether in contract, strict liability,\r
+// or tort (including negligence or otherwise) arising in any way out of\r
+// the use of this software, even if advised of the possibility of such damage.\r
+//\r
+//M*/\r
+\r
+#include "cxcoretest.h"\r
+\r
+using namespace cv;\r
+\r
+\r
+class CV_PCATest : public CvTest\r
+{\r
+public:\r
+ CV_PCATest() : CvTest( "pca", "PCA funcs" ) {}\r
+protected:\r
+ void run( int);\r
+};\r
+\r
+void CV_PCATest::run( int )\r
+{\r
+ int code = CvTS::OK, err;\r
+ int maxComponents = 1;\r
+ Mat points( 1000, 3, CV_32FC1);\r
+ randn( points, Scalar::all(0.0), Scalar::all(1.0) );\r
+ float mp[] = { 3.0f, 3.0f, 3.0f }, cp[] = { 0.5f, 0.0f, 0.0f,\r
+ 0.0f, 1.0f, 0.0f,\r
+ 0.0f, 0.0f, 0.3f };\r
+ Mat mean( 1, 3, CV_32FC1, mp ),\r
+ cov( 3, 3, CV_32FC1, cp );\r
+ for( int i = 0; i < points.rows; i++ )\r
+ {\r
+ Mat r(1, points.cols, CV_32FC1, points.ptr<float>(i));\r
+ r = r * cov + mean; \r
+ }\r
+\r
+ PCA pca( points, Mat(), CV_PCA_DATA_AS_ROW, maxComponents );\r
+\r
+ // check project\r
+ Mat prjPoints = pca.project( points );\r
+ err = 0;\r
+ for( int i = 0; i < prjPoints.rows; i++ )\r
+ {\r
+ float val = prjPoints.at<float>(i,0);\r
+ if( val > 3.0f || val < -3.0f )\r
+ err++;\r
+ }\r
+ if( (float)err > prjPoints.rows*0.01f )\r
+ {
+ ts->printf( CvTS::LOG, "bad accuracy of project()" );
+ code = CvTS::FAIL_BAD_ACCURACY;
+ }
+
+ // check backProject
+ Mat points1 = pca.backProject( prjPoints );
+ err = 0;
+ for( int i = 0; i < points.rows; i++ )\r {\r if( fabs(points1.at<float>(i,0) - mean.at<float>(0,0)) > 0.05 ||\r fabs(points1.at<float>(i,1) - points.at<float>(i,1)) > 0.02 ||\r fabs(points1.at<float>(i,2) - mean.at<float>(0,2)) > 0.05 )\r err++;\r }\r if( (float)err > prjPoints.rows*0.04f )\r
+ {
+ ts->printf( CvTS::LOG, "bad accuracy of backProject()" );
+ code = CvTS::FAIL_BAD_ACCURACY;
+ }
+
+ ts->set_failed_test_info( code );\r
+}\r
+\r
+CV_PCATest pca_test;
\ No newline at end of file
void defaultDistribs( vector<Mat>& means, vector<Mat>& covs )
{
- float mp0[] = {0.0f, 0.0f}, ep0[] = {0.67f, 0.0f, 0.0f, 0.67f};
- float mp1[] = {5.0f, 0.0f}, ep1[] = {1.0f, 0.0f, 0.0f, 1.0f};
- float mp2[] = {1.0f, 5.0f}, ep2[] = {1.0f, 0.0f, 0.0f, 1.0f};
- Mat m0( 1, 2, CV_32FC1, mp0 ), e0( 2, 2, CV_32FC1, ep0 );
- Mat m1( 1, 2, CV_32FC1, mp1 ), e1( 2, 2, CV_32FC1, ep1 );
- Mat m2( 1, 2, CV_32FC1, mp2 ), e2( 2, 2, CV_32FC1, ep2 );
+ float mp0[] = {0.0f, 0.0f}, cp0[] = {0.67f, 0.0f, 0.0f, 0.67f};
+ float mp1[] = {5.0f, 0.0f}, cp1[] = {1.0f, 0.0f, 0.0f, 1.0f};
+ float mp2[] = {1.0f, 5.0f}, cp2[] = {1.0f, 0.0f, 0.0f, 1.0f};
+ Mat m0( 1, 2, CV_32FC1, mp0 ), c0( 2, 2, CV_32FC1, cp0 );
+ Mat m1( 1, 2, CV_32FC1, mp1 ), c1( 2, 2, CV_32FC1, cp1 );
+ Mat m2( 1, 2, CV_32FC1, mp2 ), c2( 2, 2, CV_32FC1, cp2 );
means.resize(3), covs.resize(3);
- m0.copyTo(means[0]), e0.copyTo(covs[0]);
- m1.copyTo(means[1]), e1.copyTo(covs[1]);
- m2.copyTo(means[2]), e2.copyTo(covs[2]);
+ m0.copyTo(means[0]), c0.copyTo(covs[0]);
+ m1.copyTo(means[1]), c1.copyTo(covs[1]);
+ m2.copyTo(means[2]), c2.copyTo(covs[2]);
}
// generate points sets by normal distributions