Home | History | Annotate | Download | only in test
      1 /*M///////////////////////////////////////////////////////////////////////////////////////
      2 //
      3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
      4 //
      5 //  By downloading, copying, installing or using the software you agree to this license.
      6 //  If you do not agree to this license, do not download, install,
      7 //  copy or use the software.
      8 //
      9 //
     10 //                        Intel License Agreement
     11 //                For Open Source Computer Vision Library
     12 //
     13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
     14 // Third party copyrights are property of their respective owners.
     15 //
     16 // Redistribution and use in source and binary forms, with or without modification,
     17 // are permitted provided that the following conditions are met:
     18 //
     19 //   * Redistribution's of source code must retain the above copyright notice,
     20 //     this list of conditions and the following disclaimer.
     21 //
     22 //   * Redistribution's in binary form must reproduce the above copyright notice,
     23 //     this list of conditions and the following disclaimer in the documentation
     24 //     and/or other materials provided with the distribution.
     25 //
     26 //   * The name of Intel Corporation may not be used to endorse or promote products
     27 //     derived from this software without specific prior written permission.
     28 //
     29 // This software is provided by the copyright holders and contributors "as is" and
     30 // any express or implied warranties, including, but not limited to, the implied
     31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
     32 // In no event shall the Intel Corporation or contributors be liable for any direct,
     33 // indirect, incidental, special, exemplary, or consequential damages
     34 // (including, but not limited to, procurement of substitute goods or services;
     35 // loss of use, data, or profits; or business interruption) however caused
     36 // and on any theory of liability, whether in contract, strict liability,
     37 // or tort (including negligence or otherwise) arising in any way out of
     38 // the use of this software, even if advised of the possibility of such damage.
     39 //
     40 //M*/
     41 
     42 #include "test_precomp.hpp"
     43 
     44 #if 0
     45 #include "_modelest.h"
     46 
     47 using namespace std;
     48 using namespace cv;
     49 
     50 class BareModelEstimator : public CvModelEstimator2
     51 {
     52 public:
     53     BareModelEstimator(int modelPoints, CvSize modelSize, int maxBasicSolutions);
     54 
     55     virtual int runKernel( const CvMat*, const CvMat*, CvMat* );
     56     virtual void computeReprojError( const CvMat*, const CvMat*,
     57                                      const CvMat*, CvMat* );
     58 
     59     bool checkSubsetPublic( const CvMat* ms1, int count, bool checkPartialSubset );
     60 };
     61 
     62 BareModelEstimator::BareModelEstimator(int _modelPoints, CvSize _modelSize, int _maxBasicSolutions)
     63     :CvModelEstimator2(_modelPoints, _modelSize, _maxBasicSolutions)
     64 {
     65 }
     66 
     67 int BareModelEstimator::runKernel( const CvMat*, const CvMat*, CvMat* )
     68 {
     69     return 0;
     70 }
     71 
     72 void BareModelEstimator::computeReprojError( const CvMat*, const CvMat*,
     73                                              const CvMat*, CvMat* )
     74 {
     75 }
     76 
     77 bool BareModelEstimator::checkSubsetPublic( const CvMat* ms1, int count, bool checkPartialSubset )
     78 {
     79     checkPartialSubsets = checkPartialSubset;
     80     return checkSubset(ms1, count);
     81 }
     82 
     83 class CV_ModelEstimator2_Test : public cvtest::ArrayTest
     84 {
     85 public:
     86     CV_ModelEstimator2_Test();
     87 
     88 protected:
     89     void get_test_array_types_and_sizes( int test_case_idx, vector<vector<Size> >& sizes, vector<vector<int> >& types );
     90     void fill_array( int test_case_idx, int i, int j, Mat& arr );
     91     double get_success_error_level( int test_case_idx, int i, int j );
     92     void run_func();
     93     void prepare_to_validation( int test_case_idx );
     94 
     95     bool checkPartialSubsets;
     96     int usedPointsCount;
     97 
     98     bool checkSubsetResult;
     99     int generalPositionsCount;
    100     int maxPointsCount;
    101 };
    102 
    103 CV_ModelEstimator2_Test::CV_ModelEstimator2_Test()
    104 {
    105     generalPositionsCount = get_test_case_count() / 2;
    106     maxPointsCount = 100;
    107 
    108     test_array[INPUT].push_back(NULL);
    109     test_array[OUTPUT].push_back(NULL);
    110     test_array[REF_OUTPUT].push_back(NULL);
    111 }
    112 
    113 void CV_ModelEstimator2_Test::get_test_array_types_and_sizes( int /*test_case_idx*/,
    114                                                               vector<vector<Size> > &sizes, vector<vector<int> > &types )
    115 {
    116     RNG &rng = ts->get_rng();
    117     checkPartialSubsets = (cvtest::randInt(rng) % 2 == 0);
    118 
    119     int pointsCount = cvtest::randInt(rng) % maxPointsCount;
    120     usedPointsCount = pointsCount == 0 ? 0 : cvtest::randInt(rng) % pointsCount;
    121 
    122     sizes[INPUT][0] = cvSize(1, pointsCount);
    123     types[INPUT][0] = CV_64FC2;
    124 
    125     sizes[OUTPUT][0] = sizes[REF_OUTPUT][0] = cvSize(1, 1);
    126     types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_8UC1;
    127 }
    128 
    129 void CV_ModelEstimator2_Test::fill_array( int test_case_idx, int i, int j, Mat& arr )
    130 {
    131     if( i != INPUT )
    132     {
    133         cvtest::ArrayTest::fill_array( test_case_idx, i, j, arr );
    134         return;
    135     }
    136 
    137     if (test_case_idx < generalPositionsCount)
    138     {
    139         //generate points in a general position (i.e. no three points can lie on the same line.)
    140 
    141         bool isGeneralPosition;
    142         do
    143         {
    144             ArrayTest::fill_array(test_case_idx, i, j, arr);
    145 
    146             //a simple check that the position is general:
    147             //  for each line check that all other points don't belong to it
    148             isGeneralPosition = true;
    149             for (int startPointIndex = 0; startPointIndex < usedPointsCount && isGeneralPosition; startPointIndex++)
    150             {
    151                 for (int endPointIndex = startPointIndex + 1; endPointIndex < usedPointsCount && isGeneralPosition; endPointIndex++)
    152                 {
    153 
    154                     for (int testPointIndex = 0; testPointIndex < usedPointsCount && isGeneralPosition; testPointIndex++)
    155                     {
    156                         if (testPointIndex == startPointIndex || testPointIndex == endPointIndex)
    157                         {
    158                             continue;
    159                         }
    160 
    161                         CV_Assert(arr.type() == CV_64FC2);
    162                         Point2d tangentVector_1 = arr.at<Point2d>(endPointIndex) - arr.at<Point2d>(startPointIndex);
    163                         Point2d tangentVector_2 = arr.at<Point2d>(testPointIndex) - arr.at<Point2d>(startPointIndex);
    164 
    165                         const float eps = 1e-4f;
    166                         //TODO: perhaps it is better to normalize the cross product by norms of the tangent vectors
    167                         if (fabs(tangentVector_1.cross(tangentVector_2)) < eps)
    168                         {
    169                             isGeneralPosition = false;
    170                         }
    171                     }
    172                 }
    173             }
    174         }
    175         while(!isGeneralPosition);
    176     }
    177     else
    178     {
    179         //create points in a degenerate position (there are at least 3 points belonging to the same line)
    180 
    181         ArrayTest::fill_array(test_case_idx, i, j, arr);
    182         if (usedPointsCount <= 2)
    183         {
    184             return;
    185         }
    186 
    187         RNG &rng = ts->get_rng();
    188         int startPointIndex, endPointIndex, modifiedPointIndex;
    189         do
    190         {
    191             startPointIndex = cvtest::randInt(rng) % usedPointsCount;
    192             endPointIndex = cvtest::randInt(rng) % usedPointsCount;
    193             modifiedPointIndex = checkPartialSubsets ? usedPointsCount - 1 : cvtest::randInt(rng) % usedPointsCount;
    194         }
    195         while (startPointIndex == endPointIndex || startPointIndex == modifiedPointIndex || endPointIndex == modifiedPointIndex);
    196 
    197         double startWeight = cvtest::randReal(rng);
    198         CV_Assert(arr.type() == CV_64FC2);
    199         arr.at<Point2d>(modifiedPointIndex) = startWeight * arr.at<Point2d>(startPointIndex) + (1.0 - startWeight) * arr.at<Point2d>(endPointIndex);
    200     }
    201 }
    202 
    203 
    204 double CV_ModelEstimator2_Test::get_success_error_level( int /*test_case_idx*/, int /*i*/, int /*j*/ )
    205 {
    206     return 0;
    207 }
    208 
    209 void CV_ModelEstimator2_Test::prepare_to_validation( int test_case_idx )
    210 {
    211     test_mat[OUTPUT][0].at<uchar>(0) = checkSubsetResult;
    212     test_mat[REF_OUTPUT][0].at<uchar>(0) = test_case_idx < generalPositionsCount || usedPointsCount <= 2;
    213 }
    214 
    215 void CV_ModelEstimator2_Test::run_func()
    216 {
    217     //make the input continuous
    218     Mat input = test_mat[INPUT][0].clone();
    219     CvMat _input = input;
    220 
    221     RNG &rng = ts->get_rng();
    222     int modelPoints = cvtest::randInt(rng);
    223     CvSize modelSize = cvSize(2, modelPoints);
    224     int maxBasicSolutions = cvtest::randInt(rng);
    225     BareModelEstimator modelEstimator(modelPoints, modelSize, maxBasicSolutions);
    226     checkSubsetResult = modelEstimator.checkSubsetPublic(&_input, usedPointsCount, checkPartialSubsets);
    227 }
    228 
    229 TEST(Calib3d_ModelEstimator2, accuracy) { CV_ModelEstimator2_Test test; test.safe_run(); }
    230 
    231 #endif
    232