Update to 2.0.0 tree from current Fremantle build
[opencv] / tests / swig_python / cmp_tests.py
1 #!/usr/bin/env python
2 import unittest
3 import cvtestutils
4 from cv import *
5
6 class cmp_test(unittest.TestCase):
7     def setUp(self):
8         self.w=17
9         self.h=17
10         self.x0 = cvCreateMat(self.w,self.h,CV_32F)
11         self.x1 = cvCreateMat(self.w,self.h,CV_32F)
12         cvSet(self.x0, cvScalarAll(0.0))
13         cvSet(self.x1, cvScalarAll(1.0))
14     def check_format(self, y):
15         assert( y.rows == self.h )
16         assert( y.cols == self.w )
17         assert( CV_MAT_DEPTH(y.type)==CV_8U )
18     def check_allzero(self, y):
19         assert( cvCountNonZero(y)==0 )
20     def check_all255(self, y):
21         nonzero=cvCountNonZero(y)
22         assert( nonzero==self.w*self.h )
23         sum = cvSum(y)[0]
24         assert( sum == self.w*self.h*255 )
25
26     def test_CvMat_gt(self):
27         y=self.x1>0
28         self.check_format( y )
29         self.check_all255( y )
30         y=self.x0>0
31         self.check_format( y )
32         self.check_allzero( y )
33
34     def test_CvMat_gte(self):
35         y=self.x1>=0
36         self.check_format( y )
37         self.check_all255( y )
38         y=self.x0>=0
39         self.check_format( y )
40         self.check_all255( y )
41
42     def test_CvMat_lt(self):
43         y=self.x1<1
44         self.check_format( y )
45         self.check_allzero( y )
46         y=self.x0<1
47         self.check_format( y )
48         self.check_all255( y )
49
50     def test_CvMat_lte(self):
51         y=self.x1<=1
52         self.check_format( y )
53         self.check_all255( y )
54         y=self.x0<=1
55         self.check_format( y )
56
57 def suite():
58     return unittest.TestLoader().loadTestsFromTestCase(cmp_test)
59
60 if __name__ == '__main__':
61     unittest.TextTestRunner(verbosity=2).run(suite())