]> rtime.felk.cvut.cz Git - opencv.git/blob - opencv/tests/cxts/cxts.h
97e48ec4e550c0db8a9dc25c8f0de7cc53b8831d
[opencv.git] / opencv / tests / cxts / cxts.h
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 #ifndef __CXTS_H__
43 #define __CXTS_H__
44
45 #include "cxcore.h"
46 #include "cxmisc.h"
47 #include <assert.h>
48 #include <limits.h>
49 #include <setjmp.h>
50 #include <stdarg.h>
51 #include <stdio.h>
52 #include <string.h>
53 #include <time.h>
54
55 #if _MSC_VER >= 1200
56 #pragma warning( disable: 4710 )
57 #endif
58
59 #define CV_TS_VERSION "CxTest 0.1"
60
61 #define __BEGIN__ __CV_BEGIN__
62 #define __END__  __CV_END__
63 #define EXIT __CV_EXIT__
64
65 // Helper class for growing vector (to avoid dependency from STL)
66 template < typename T > class CvTestVec
67 {
68 public:
69     CvTestVec() { _max_size = _size = 0; _buf = 0; }
70     ~CvTestVec() { delete[] _buf; }
71     T& operator []( int i ) { assert( (unsigned)i < (unsigned)_size ); return _buf[i]; }
72     T at( int i ) { assert( (unsigned)i < (unsigned)_size ); return _buf[i]; }
73     T pop() { assert( _size > 0 ); return _buf[--_size]; }
74     void push( const T& elem )
75     {
76         if( _size >= _max_size )
77         {
78             int i, _new_size = _max_size < 16 ? 16 : _max_size*3/2;
79             T* temp = new T[_new_size];
80             for( i = 0; i < _size; i++ )
81                 temp[i] = _buf[i];
82             delete[] _buf;
83             _max_size = _new_size;
84             _buf = temp;
85         }
86         _buf[_size++] = elem;
87     }
88
89     int size() { return _size; }
90     T* data() { return _buf; }
91     void clear() { _size = 0; }
92
93 protected:
94     T* _buf;
95     int _size, _max_size;
96 };
97
98 /*****************************************************************************************\
99 *                                    Base class for tests                                 *
100 \*****************************************************************************************/
101
102 class CvTest;
103 class CvTS;
104
105 class CV_EXPORTS CvTest
106 {
107 public:
108     // constructor(s) and destructor
109     CvTest( const char* test_name, const char* test_funcs, const char* test_descr = "" );
110     virtual ~CvTest();
111
112     virtual int init( CvTS* system );
113
114     // writes default parameters to file storage
115     virtual int write_defaults(CvTS* ts);
116
117     // the main procedure of the test
118     virtual void run( int start_from );
119
120     // the wrapper for run that cares of exceptions
121     virtual void safe_run( int start_from );
122
123     const char* get_name() const { return name; }
124     const char* get_func_list() const { return tested_functions; }
125     const char* get_description() const { return description; }
126     const char* get_group_name( char* buffer ) const;
127     CvTest* get_next() { return next; }
128     static CvTest* get_first_test();
129     static const char* get_parent_name( const char* name, char* buffer );
130
131     // returns true if and only if the different test cases do not depend on each other
132     // (so that test system could get right to a problematic test case)
133     virtual bool can_do_fast_forward();
134
135     // deallocates all the memory.
136     // called by init() (before initialization) and by the destructor
137     virtual void clear();
138
139     // returns the testing modes supported by the particular test
140     int get_support_testing_modes();
141
142     enum { TIMING_EXTRA_PARAMS=5 };
143
144 protected:
145     static CvTest* first;
146     static CvTest* last;
147     static int test_count;
148     CvTest* next;
149
150     const char** default_timing_param_names; // the names of timing parameters to write
151     const CvFileNode* timing_param_names; // and the read param names
152     const CvFileNode** timing_param_current; // the current tuple of timing parameters
153     const CvFileNode** timing_param_seqs; // the array of parameter sequences
154     int* timing_param_idxs; // the array of indices
155     int timing_param_count; // the number of parameters in the tuple
156     int support_testing_modes;
157
158     int test_case_count; // the total number of test cases
159
160     // called from write_defaults
161     virtual int write_default_params(CvFileStorage* fs);
162
163     // read test params
164     virtual int read_params( CvFileStorage* fs );
165
166     // returns the number of tests or -1 if it is unknown a-priori
167     virtual int get_test_case_count();
168
169     // prepares data for the next test case. rng seed is updated by the function
170     virtual int prepare_test_case( int test_case_idx );
171
172     // checks if the test output is valid and accurate
173     virtual int validate_test_results( int test_case_idx );
174
175     // calls the tested function. the method is called from run_test_case()
176     virtual void run_func(); // runs tested func(s)
177
178     // prints results of timing test
179     virtual void print_time( int test_case_idx, double time_usecs, double time_cpu_clocks );
180
181     // updates progress bar
182     virtual int update_progress( int progress, int test_case_idx, int count, double dt );
183
184     // finds test parameter
185     const CvFileNode* find_param( CvFileStorage* fs, const char* param_name );
186
187     // writes parameters
188     void write_param( CvFileStorage* fs, const char* paramname, int val );
189     void write_param( CvFileStorage* fs, const char* paramname, double val );
190     void write_param( CvFileStorage* fs, const char* paramname, const char* val );
191     void write_string_list( CvFileStorage* fs, const char* paramname, const char** val, int count=-1 );
192     void write_int_list( CvFileStorage* fs, const char* paramname, const int* val,
193                          int count, int stop_value=INT_MIN );
194     void write_real_list( CvFileStorage* fs, const char* paramname, const double* val,
195                           int count, double stop_value=DBL_MIN );
196     void start_write_param( CvFileStorage* fs );
197
198     // returns the specified parameter from the current parameter tuple
199     const CvFileNode* find_timing_param( const char* paramname );
200
201     // gets the next tuple of timing parameters
202     int get_next_timing_param_tuple();
203
204     // name of the test (it is possible to locate a test by its name)
205     const char* name;
206
207     // comma-separated list of functions that are invoked
208     // (and, thus, tested explicitly or implicitly) by the test
209     // methods of classes can be grouped using {}.
210     // a few examples:
211     //    "cvCanny, cvAdd, cvSub, cvMul"
212     //    "CvImage::{Create, CopyOf}, cvMatMulAdd, CvCalibFilter::{PushFrame, SetCameraCount}"
213     const char* tested_functions;
214
215     // description of the test
216     const char* description;
217
218     // pointer to the system that includes the test
219     CvTS* ts;
220
221     int hdr_state;
222 };
223
224
225 /*****************************************************************************************\
226 *                               Information about a failed test                           *
227 \*****************************************************************************************/
228
229 typedef struct CvTestInfo
230 {
231     // pointer to the test
232     CvTest* test;
233
234     // failure code (CV_FAIL*)
235     int code;
236
237     // seed value right before the data for the failed test case is prepared.
238     uint64 rng_seed;
239     
240     // seed value right before running the test
241     uint64 rng_seed0;
242
243     // index of test case, can be then passed to CvTest::proceed_to_test_case()
244     int test_case_idx;
245
246     // index of the corrupted or leaked block
247     int alloc_index;
248
249     // index of the first block in the group
250     // (used to adjust alloc_index when some test/test cases are skipped).
251     int base_alloc_index;
252 }
253 CvTestInfo;
254
255 /*****************************************************************************************\
256 *                                 Base Class for test system                              *
257 \*****************************************************************************************/
258
259 class CvTestMemoryManager;
260
261 typedef CvTestVec<int> CvTestIntVec;
262 typedef CvTestVec<void*> CvTestPtrVec;
263 typedef CvTestVec<CvTestInfo> CvTestInfoVec;
264
265 class CV_EXPORTS CvTS
266 {
267 public:
268
269     // constructor(s) and destructor
270     CvTS();
271     virtual ~CvTS();
272
273     enum
274     {
275         NUL=0,
276         SUMMARY_IDX=0,
277         SUMMARY=1 << SUMMARY_IDX,
278         LOG_IDX=1,
279         LOG=1 << LOG_IDX,
280         CSV_IDX=2,
281         CSV=1 << CSV_IDX,
282         CONSOLE_IDX=3,
283         CONSOLE=1 << CONSOLE_IDX,
284         MAX_IDX=4
285     };
286
287     // low-level printing functions that are used by individual tests and by the system itself
288     virtual void printf( int streams, const char* fmt, ... );
289     virtual void vprintf( int streams, const char* fmt, va_list arglist );
290
291     // runs the tests (the whole set or some selected tests)
292     virtual int run( int argc, char** argv );
293
294     // updates the context: current test, test case, rng state
295     virtual void update_context( CvTest* test, int test_case_idx, bool update_ts_context );
296
297     const CvTestInfo* get_current_test_info() { return &current_test_info; }
298
299     // sets information about a failed test
300     virtual void set_failed_test_info( int fail_code, int alloc_index = -1 );
301
302     // types of tests
303     enum
304     {
305         CORRECTNESS_CHECK_MODE = 1,
306         TIMING_MODE = 2
307     };
308
309     // the modes of timing tests:
310     enum { AVG_TIME = 1, MIN_TIME = 2 };
311
312     // test error codes
313     enum
314     {
315         // everything is Ok
316         OK=0,
317
318         // generic error: stub value to be used
319         // temporarily if the error's cause is unknown
320         FAIL_GENERIC=-1,
321
322         // the test is missing some essential data to proceed further
323         FAIL_MISSING_TEST_DATA=-2,
324
325         // the tested function raised an error via cxcore error handler
326         FAIL_ERROR_IN_CALLED_FUNC=-3,
327
328         // an exception has been raised;
329         // for memory and arithmetic exception
330         // there are two specialized codes (see below...)
331         FAIL_EXCEPTION=-4,
332
333         // a memory exception
334         // (access violation, access to missed page, stack overflow etc.)
335         FAIL_MEMORY_EXCEPTION=-5,
336
337         // arithmetic exception (overflow, division by zero etc.)
338         FAIL_ARITHM_EXCEPTION=-6,
339
340         // the tested function corrupted memory (no exception have been raised)
341         FAIL_MEMORY_CORRUPTION_BEGIN=-7,
342         FAIL_MEMORY_CORRUPTION_END=-8,
343
344         // the tested function (or test ifself) do not deallocate some memory
345         FAIL_MEMORY_LEAK=-9,
346
347         // the tested function returned invalid object, e.g. matrix, containing NaNs,
348         // structure with NULL or out-of-range fields (while it should not)
349         FAIL_INVALID_OUTPUT=-10,
350
351         // the tested function returned valid object, but it does not match to
352         // the original (or produced by the test) object
353         FAIL_MISMATCH=-11,
354
355         // the tested function returned valid object (a single number or numerical array),
356         // but it differs too much from the original (or produced by the test) object
357         FAIL_BAD_ACCURACY=-12,
358
359         // the tested function hung. Sometimes, can be determined by unexpectedly long
360         // processing time (in this case there should be possibility to interrupt such a function
361         FAIL_HANG=-13,
362
363         // unexpected responce on passing bad arguments to the tested function
364         // (the function crashed, proceed succesfully (while it should not), or returned
365         // error code that is different from what is expected)
366         FAIL_BAD_ARG_CHECK=-14,
367
368         // the test data (in whole or for the particular test case) is invalid
369         FAIL_INVALID_TEST_DATA=-15,
370
371         // the test has been skipped because it is not in the selected subset of the tests to run,
372         // because it has been run already within the same run with the same parameters, or because
373         // of some other reason and this is not considered as an error.
374         // Normally CvTS::run() (or overrided method in the derived class) takes care of what
375         // needs to be run, so this code should not occur.
376         SKIPPED=1
377     };
378
379     // get file storage
380     CvFileStorage* get_file_storage() { return fs; }
381
382     // get RNG to generate random input data for a test
383     CvRNG* get_rng() { return &rng; }
384
385     // returns the current error code
386     int get_err_code() { return current_test_info.code; }
387
388     // retrieves the first registered test
389     CvTest* get_first_test() { return CvTest::get_first_test(); }
390
391     // retrieves one of global options of the test system
392     int is_debug_mode() { return params.debug_mode; }
393
394     // returns the current testing mode
395     int get_testing_mode()  { return params.test_mode; }
396
397     // returns the current timing mode
398     int get_timing_mode() { return params.timing_mode; }
399
400     // returns the test extensivity scale
401     double get_test_case_count_scale() { return params.test_case_count_scale; }
402
403     int find_written_param( CvTest* test, const char* paramname,
404                             int valtype, const void* val );
405
406     const char* get_data_path() { return params.data_path ? params.data_path : ""; }
407
408 protected:
409     // deallocates memory buffers and closes all the streams;
410     // called by init() and from destructor. It does not remove any tests!!!
411     virtual void clear();
412
413     // retrieves information about the test libraries (names, versions, build dates etc.)
414     virtual const char* get_libs_info( const char** loaded_ipp_modules );
415
416     // returns textual description of failure code
417     virtual const char* str_from_code( int code );
418
419     // prints header of summary of test suite run.
420     // It goes before the results of individual tests and contains information about tested libraries
421     // (as reported by get_libs_info()), information about test environment (CPU, test machine name),
422     // date and time etc.
423     virtual void print_summary_header( int streams );
424
425     // prints tailer of summary of test suite run.
426     // it goes after the results of individual tests and contains the number of
427     // failed tests, total running time, exit code (whether the system has been crashed,
428     // interrupted by the user etc.), names of files with additional information etc.
429     virtual void print_summary_tailer( int streams );
430
431     // reads common parameters of the test system; called from init()
432     virtual int read_params( CvFileStorage* fs );
433
434     // checks, whether the test needs to be run (1) or not (0); called from run()
435     virtual int filter( CvTest* test );
436
437     // makes base name of output files
438     virtual void make_output_stream_base_name( const char* config_name );
439
440     // forms default test configuration file that can be
441     // customized further
442     virtual void write_default_params( CvFileStorage* fs );
443
444     // enables/disables the specific output stream[s]
445     virtual void enable_output_streams( int streams, int flag );
446
447     // sets memory and exception handlers
448     virtual void set_handlers( bool on );
449
450     // changes the path to test data files
451     virtual void set_data_path( const char* data_path );
452
453     // prints the information about command-line parameters
454     virtual void print_help();
455     
456     // changes the text color in console
457     virtual void set_color(int color);
458
459     // a sequence of tests to run
460     CvTestPtrVec* selected_tests;
461
462     // a sequence of written test params
463     CvTestPtrVec* written_params;
464
465     // a sequence of failed tests
466     CvTestInfoVec* failed_tests;
467
468     // base name for output streams
469     char* ostrm_base_name;
470     const char* ostrm_suffixes[MAX_IDX];
471
472     // parameters that can be read from file storage
473     CvFileStorage* fs;
474
475     enum { CHOOSE_TESTS = 0, CHOOSE_FUNCTIONS = 1 };
476
477     // common parameters:
478     struct
479     {
480         // if non-zero, the tests are run in unprotected mode to debug possible crashes,
481         // otherwise the system tries to catch the exceptions and continue with other tests
482         int debug_mode;
483
484         // if non-zero, the header is not print
485         bool skip_header;
486
487         // if non-zero, the system includes only failed tests into summary
488         bool print_only_failed;
489
490         // rerun failed tests in debug mode
491         bool rerun_failed;
492
493         // if non-zero, the failed tests are rerun immediately
494         bool rerun_immediately;
495
496         // choose_tests or choose_functions;
497         int  test_filter_mode;
498
499         // correctness or performance [or bad-arg, stress etc.]
500         int  test_mode;
501
502         // timing mode
503         int  timing_mode;
504
505         // pattern for choosing tests
506         const char* test_filter_pattern;
507
508         // RNG seed, passed to and updated by every test executed.
509         uint64 rng_seed;
510
511         // relative or absolute path of directory containing subfolders with test data
512         const char* resource_path;
513
514         // whether to use IPP, MKL etc. or not
515         int use_optimized;
516
517         // extensivity of the tests, scale factor for test_case_count
518         double test_case_count_scale;
519
520         // the path to data files used by tests
521         char* data_path;
522         
523         // whether the output to console should be colored
524         int color_terminal;
525     }
526     params;
527
528     // these are allocated within a test to try keep them valid in case of stack corruption
529     CvRNG rng;
530
531     // test system start time
532     time_t start_time;
533
534     // test system version (=CV_TS_VERSION by default)
535     const char* version;
536
537     // name of config file
538     const char* config_name;
539
540     // information about the current test
541     CvTestInfo current_test_info;
542
543     // memory manager used to detect memory corruptions and leaks
544     CvTestMemoryManager* memory_manager;
545
546     // output streams
547     struct StreamInfo
548     {
549         FILE* f;
550         //const char* filename;
551         int default_handle; // for stderr
552         int enable;
553     };
554
555     StreamInfo output_streams[MAX_IDX];
556     int ostream_testname_mask;
557     char* logbuf;
558     size_t logbufsize;
559     size_t logbufpos;
560 };
561
562
563 /*****************************************************************************************\
564 *            Subclass of CvTest for testing functions that process dense arrays           *
565 \*****************************************************************************************/
566
567 class CV_EXPORTS CvArrTest : public CvTest
568 {
569 public:
570     // constructor(s) and destructor
571     CvArrTest( const char* test_name, const char* test_funcs, const char* test_descr = "" );
572     virtual ~CvArrTest();
573
574     virtual int write_default_params( CvFileStorage* fs );
575     virtual void clear();
576
577 protected:
578
579     virtual int read_params( CvFileStorage* fs );
580     virtual int prepare_test_case( int test_case_idx );
581     virtual int validate_test_results( int test_case_idx );
582
583     virtual void prepare_to_validation( int test_case_idx );
584     virtual void get_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types );
585     virtual void get_timing_test_array_types_and_sizes( int test_case_idx, CvSize** sizes, int** types,
586                                                         CvSize** whole_sizes, bool *are_images );
587     virtual void fill_array( int test_case_idx, int i, int j, CvMat* arr );
588     virtual void get_minmax_bounds( int i, int j, int type, CvScalar* low, CvScalar* high );
589     virtual double get_success_error_level( int test_case_idx, int i, int j );
590     virtual void print_time( int test_case_idx, double time_usecs, double time_cpu_clocks );
591     virtual void print_timing_params( int test_case_idx, char* ptr, int params_left=TIMING_EXTRA_PARAMS );
592
593     bool cvmat_allowed;
594     bool iplimage_allowed;
595     bool optional_mask;
596     bool element_wise_relative_error;
597
598     int min_log_array_size;
599     int max_log_array_size;
600
601     int max_arr; // = MAX_ARR by default, the number of different types of arrays
602     int max_hdr; // size of header buffer
603     enum { INPUT, INPUT_OUTPUT, OUTPUT, REF_INPUT_OUTPUT, REF_OUTPUT, TEMP, MASK, MAX_ARR };
604
605     const CvSize* size_list;
606     const CvSize* whole_size_list;
607     const int* depth_list;
608     const int* cn_list;
609
610     CvTestPtrVec* test_array;
611     CvMat* test_mat[MAX_ARR];
612     CvMat* hdr;
613     float buf[4];
614 };
615
616
617 class CV_EXPORTS CvBadArgTest : public CvTest
618 {
619 public:
620     // constructor(s) and destructor
621     CvBadArgTest( const char* test_name, const char* test_funcs, const char* test_descr = "" );
622     virtual ~CvBadArgTest();
623
624 protected:
625     virtual int run_test_case( int expected_code, const char* descr );
626     virtual void run_func(void) = 0;
627     int test_case_idx;
628     int progress;
629     double t, freq;   
630
631     template<class F>
632     int run_test_case( int expected_code, const char* descr, F f)
633     {
634         double new_t = (double)cv::getTickCount(), dt;
635         if( test_case_idx < 0 )
636         {
637             test_case_idx = 0;
638             progress = 0;
639             dt = 0;
640         }
641         else
642         {
643             dt = (new_t - t)/(freq*1000);
644             t = new_t;
645         }
646         progress = update_progress(progress, test_case_idx, 0, dt);
647         
648         int errcount = 0;
649         bool thrown = false;
650         if(!descr)
651             descr = "";
652
653         try
654         {
655             f();
656         }
657         catch(const cv::Exception& e)
658         {
659             thrown = true;
660             if( e.code != expected_code )
661             {
662                 ts->printf(CvTS::LOG, "%s (test case #%d): the error code %d is different from the expected %d\n",
663                     descr, test_case_idx, e.code, expected_code);
664                 errcount = 1;
665             }
666         }
667         catch(...)
668         {
669             thrown = true;
670             ts->printf(CvTS::LOG, "%s  (test case #%d): unknown exception was thrown (the function has likely crashed)\n",
671                        descr, test_case_idx);
672             errcount = 1;
673         }
674         if(!thrown)
675         {
676             ts->printf(CvTS::LOG, "%s  (test case #%d): no expected exception was thrown\n",
677                        descr, test_case_idx);
678             errcount = 1;
679         }
680         test_case_idx++;
681         
682         return errcount;
683     }
684 };
685
686 /****************************************************************************************\
687 *                                 Utility Functions                                      *
688 \****************************************************************************************/
689
690 CV_EXPORTS const char* cvTsGetTypeName( int type );
691 CV_EXPORTS int cvTsTypeByName( const char* type_name );
692
693 inline  int cvTsClipInt( int val, int min_val, int max_val )
694 {
695     if( val < min_val )
696         val = min_val;
697     if( val > max_val )
698         val = max_val;
699     return val;
700 }
701
702 // return min & max values for given type, e.g. for CV_8S ~  -128 and 127, respectively.
703 CV_EXPORTS double cvTsMinVal( int type );
704 CV_EXPORTS double cvTsMaxVal( int type );
705
706 // returns c-norm of the array
707 CV_EXPORTS double cvTsMaxVal( const CvMat* arr );
708
709 inline CvMat* cvTsGetMat( const CvMat* arr, CvMat* stub, int* coi=0 )
710 {
711     return cvGetMat( arr, stub, coi );
712 }
713
714 // fills array with random numbers
715 CV_EXPORTS void cvTsRandUni( CvRNG* rng, CvMat* a, CvScalar param1, CvScalar param2 );
716
717 inline  unsigned cvTsRandInt( CvRNG* rng )
718 {
719     uint64 temp = *rng;
720     temp = (uint64)(unsigned)temp*1554115554 + (temp >> 32);
721     *rng = temp;
722     return (unsigned)temp;
723 }
724
725 inline  double cvTsRandReal( CvRNG* rng )
726 {
727     return cvTsRandInt( rng ) * 2.3283064365386962890625e-10 /* 2^-32 */;
728 }
729
730 // fills c with zeros
731 CV_EXPORTS void cvTsZero( CvMat* c, const CvMat* mask=0 );
732
733 // initializes scaled identity matrix
734 CV_EXPORTS void cvTsSetIdentity( CvMat* c, CvScalar diag_value );
735
736 // copies a to b (whole matrix or only the selected region)
737 CV_EXPORTS void cvTsCopy( const CvMat* a, CvMat* b, const CvMat* mask=0 );
738
739 // converts one array to another
740 CV_EXPORTS void  cvTsConvert( const CvMat* src, CvMat* dst );
741
742 // working with multi-channel arrays
743 CV_EXPORTS void cvTsExtract( const CvMat* a, CvMat* plane, int coi );
744 CV_EXPORTS void cvTsInsert( const CvMat* plane, CvMat* a, int coi );
745
746 // c = alpha*a + beta*b + gamma
747 CV_EXPORTS void cvTsAdd( const CvMat* a, CvScalar alpha, const CvMat* b, CvScalar beta,
748                     CvScalar gamma, CvMat* c, int calc_abs );
749
750 // c = a*b*alpha
751 CV_EXPORTS void cvTsMul( const CvMat* _a, const CvMat* _b, CvScalar alpha, CvMat* _c );
752
753 // c = a*alpha/b
754 CV_EXPORTS void cvTsDiv( const CvMat* _a, const CvMat* _b, CvScalar alpha, CvMat* _c );
755
756 enum { CV_TS_MIN = 0, CV_TS_MAX = 1 };
757
758 // min/max
759 CV_EXPORTS void cvTsMinMax( const CvMat* _a, const CvMat* _b, CvMat* _c, int op_type );
760 CV_EXPORTS void cvTsMinMaxS( const CvMat* _a, double scalar, CvMat* _c, int op_type );
761
762 // checks that the array does not have NaNs and/or Infs and all the elements are
763 // within [min_val,max_val). idx is the index of the first "bad" element.
764 CV_EXPORTS int cvTsCheck( const CvMat* data, double min_val, double max_val, CvPoint* idx );
765
766 // compares two arrays. max_diff is the maximum actual difference,
767 // success_err_level is maximum allowed difference, idx is the index of the first
768 // element for which difference is >success_err_level
769 // (or index of element with the maximum difference)
770 CV_EXPORTS int cvTsCmpEps( const CvMat* data, const CvMat* etalon, double* max_diff,
771                       double success_err_level, CvPoint* idx,
772                       bool element_wise_relative_error );
773
774 // a wrapper for the previous function. in case of error prints the message to log file.
775 CV_EXPORTS int cvTsCmpEps2( CvTS* ts, const CvArr* _a, const CvArr* _b, double success_err_level,
776                             bool element_wise_relative_error, const char* desc );
777
778 CV_EXPORTS int cvTsCmpEps2_64f( CvTS* ts, const double* val, const double* ref_val, int len,
779                                 double eps, const char* param_name );
780
781 // compares two arrays. the result is 8s image that takes values -1, 0, 1
782 CV_EXPORTS void cvTsCmp( const CvMat* a, const CvMat* b, CvMat* result, int cmp_op );
783
784 // compares array and a scalar.
785 CV_EXPORTS void cvTsCmpS( const CvMat* a, double fval, CvMat* result, int cmp_op );
786
787 // retrieves C, L1 or L2 norm of array or its region
788 CV_EXPORTS double cvTsNorm( const CvMat* _arr, const CvMat* _mask, int norm_type, int coi );
789
790 // retrieves mean, standard deviation and the number of nonzero mask pixels
791 CV_EXPORTS int cvTsMeanStdDevNonZero( const CvMat* _arr, const CvMat* _mask,
792                            CvScalar* _mean, CvScalar* _stddev, int coi );
793
794 // retrieves global extremums and their positions
795 CV_EXPORTS void cvTsMinMaxLoc( const CvMat* _arr, const CvMat* _mask,
796                     double* _minval, double* _maxval,
797                     CvPoint* _minidx, CvPoint* _maxidx, int coi );
798
799 enum { CV_TS_LOGIC_AND = 0, CV_TS_LOGIC_OR = 1, CV_TS_LOGIC_XOR = 2, CV_TS_LOGIC_NOT = 3 };
800
801 CV_EXPORTS void cvTsLogic( const CvMat* a, const CvMat* b, CvMat* c, int logic_op );
802 CV_EXPORTS void cvTsLogicS( const CvMat* a, CvScalar s, CvMat* c, int logic_op );
803
804 enum { CV_TS_GEMM_A_T = 1, CV_TS_GEMM_B_T = 2, CV_TS_GEMM_C_T = 4 };
805
806 CV_EXPORTS void cvTsGEMM( const CvMat* a, const CvMat* b, double alpha,
807                      const CvMat* c, double beta, CvMat* d, int flags );
808
809 CV_EXPORTS void cvTsConvolve2D( const CvMat* a, CvMat* b, const CvMat* kernel, CvPoint anchor );
810 // op_type == CV_TS_MIN/CV_TS_MAX
811 CV_EXPORTS void cvTsMinMaxFilter( const CvMat* a, CvMat* b,
812                                   const IplConvKernel* element, int op_type );
813
814 enum { CV_TS_BORDER_REPLICATE=0, CV_TS_BORDER_REFLECT=1, CV_TS_BORDER_FILL=2 };
815
816 CV_EXPORTS void cvTsPrepareToFilter( const CvMat* a, CvMat* b, CvPoint ofs,
817                                      int border_mode = CV_TS_BORDER_REPLICATE,
818                                      CvScalar fill_val=cvScalarAll(0));
819
820 CV_EXPORTS double cvTsCrossCorr( const CvMat* a, const CvMat* b );
821
822 CV_EXPORTS CvMat* cvTsSelect( const CvMat* a, CvMat* header, CvRect rect );
823
824 CV_EXPORTS CvMat* cvTsTranspose( const CvMat* a, CvMat* b );
825 CV_EXPORTS void cvTsFlip( const CvMat* a, CvMat* b, int flip_type );
826
827 CV_EXPORTS void cvTsTransform( const CvMat* a, CvMat* b, const CvMat* transmat, const CvMat* shift );
828
829 // modifies values that are close to zero
830 CV_EXPORTS void  cvTsPatchZeros( CvMat* mat, double level );
831
832 #endif/*__CXTS_H__*/
833