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