npconvert_problem.py
1 | from opencv_svn import cv |
---|---|
2 | import numpy |
3 | |
4 | def testcode(np_convert = False): |
5 | temp = cv.CreateMat(2, 2, cv.CV_8UC1) |
6 | cv.Set(temp, 1)
|
7 | if np_convert:
|
8 | npTemp = numpy.asarray(temp) |
9 | temp = cv.fromarray(npTemp) |
10 | print "before return", repr(temp.tostring()) |
11 | return temp
|
12 | |
13 | def testcode_wrapper(np_convert = False): |
14 | temp = testcode(np_convert = np_convert) |
15 | print "after return", repr(temp.tostring()) |
16 | |
17 | |
18 | if __name__ == "__main__": |
19 | print "cv -> numpy -> cv conversion problem" |
20 | print
|
21 | print "without conversion : GOOD" |
22 | print
|
23 | testcode_wrapper(np_convert = False)
|
24 | print
|
25 | print "with conversion : BAD" |
26 | print
|
27 | testcode_wrapper(np_convert = True)
|
28 |