ee067b2a1c8714aafe624fd86de91cf4365bdeff
[opencv] / tests / swig_python / moments_tests.py
1 #!/usr/bin/env python
2 import cvtestutils
3 import unittest
4 from cv import *
5
6 class moments_test(unittest.TestCase):
7     def setUp(self):
8         # create an image
9         img = cvCreateMat(100,100,CV_8U);
10
11         cvZero( img )
12         # draw a rectangle in the middle
13         cvRectangle( img, cvPoint( 25, 25 ), cvPoint( 75, 75 ), CV_RGB(255,255,255), -1 );
14         
15         self.img = img
16
17         # create the storage area
18         self.storage = cvCreateMemStorage (0)
19
20         # find the contours
21         nb_contours, self.contours = cvFindContours (img,
22             self.storage,
23             sizeof_CvContour,
24             CV_RETR_LIST,
25             CV_CHAIN_APPROX_SIMPLE,
26             cvPoint (0,0))
27
28     def test_cvMoments_CvMat( self ):
29         m = CvMoments()
30         cvMoments( self.img, m, 1 )
31     def test_cvMoments_CvSeq( self ):
32         m = CvMoments()
33         # Now test with CvSeq
34         for contour in self.contours.hrange():
35             cvMoments( contour, m, 1 )
36
37 def suite():
38     return unittest.TestLoader().loadTestsFromTestCase(moments_test)
39
40 if __name__ == '__main__':
41     unittest.TextTestRunner(verbosity=2).run(suite())