1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/python
BINARY_OPERATORS={
'+':'cvAdd',
'-':'cvSub',
'/':'cvDiv',
'*':'cvMul',
'^':'cvXor',
'&':'cvAnd',
'|':'cvOr',
}
SCALAR_OPERATORS={
'+':'cvAddS',
'-':'cvSubS',
'&':'cvAndS',
'|':'cvOrS',
'^':'cvXorS',
}
SCALE_OPERATORS={
'*':'val',
'/':'1.0/val'
}
CMP_OPERATORS={
'==':'CV_CMP_EQ',
'!=':'CV_CMP_NE',
'>=':'CV_CMP_GE',
'>':'CV_CMP_GT',
'<=':'CV_CMP_LE',
'<':'CV_CMP_LT',
}
ARR={
'CvMat':'cvCreateMat(self->rows, self->cols, self->type)',
'IplImage':'cvCreateImage(cvGetSize(self), self->depth, self->nChannels)'
}
CMP_ARR={
'CvMat':'cvCreateMat(self->rows, self->cols, CV_8U)',
'IplImage':'cvCreateImage(cvGetSize(self), IPL_DEPTH_8U, 1)'
}
def scalar_scale_operator(arr, op, arg):
print '\t%s * operator %s (double val){' % (arr, op)
print '\t\t%s * res = %s;' % (arr, ARR[arr] )
print '\t\tcvScale(self, res, %s);' % arg
print '\t\treturn res;'
print '\t}'
print '\t%s * operator %s (double val){' % (arr, op)
print '\t\t%s * res = %s;' % (arr, ARR[arr] )
print '\t\tcvScale(self, res, %s);' % arg
print '\t\treturn res;'
print '\t}'
print "/** This file was automatically generated using util/cvarr_operators.py script */"
for arr in ARR:
print '%%extend %s {' % arr
for op in BINARY_OPERATORS:
print '\t%%newobject operator %s;' % (op)
print '\t%s * operator %s (CvArr * src){' % ( arr, op )
print '\t\t%s * res = %s;' % ( arr, ARR[arr] )
print '\t\t%s(self, src, res);' % ( BINARY_OPERATORS[op] )
print '\t\treturn res;'
print '\t}'
print '\t%s * operator %s= (CvArr * src){' % ( arr, op )
print '\t\t%s(self, src, self);' % ( BINARY_OPERATORS[op] )
print '\t\treturn self;'
print '\t}'
for op in SCALAR_OPERATORS:
print '\t%%newobject operator %s;' % (op)
print '\t%s * operator %s (CvScalar val){' % ( arr, op )
print '\t\t%s * res = %s;' % ( arr, ARR[arr] )
print '\t\t%s(self, val, res);' % ( SCALAR_OPERATORS[op] )
print '\t\treturn res;'
print '\t}'
print '\t%s * operator %s= (CvScalar val){' % ( arr, op )
print '\t\t%s(self, val, self);' % ( SCALAR_OPERATORS[op] )
print '\t\treturn self;'
print '\t}'
for op in CMP_OPERATORS:
print '\t%%newobject operator %s;' % (op)
print '\t%s * operator %s (CvArr * src){' % ( arr, op )
print '\t\t%s * res = %s;' % ( arr, CMP_ARR[arr] )
print '\t\tcvCmp(self, src, res, %s);' % ( CMP_OPERATORS[op] )
print '\t\treturn res;'
print '\t}'
print '\t%s * operator %s (double val){' % ( arr, op )
print '\t\t%s * res = %s;' % ( arr, CMP_ARR[arr] )
print '\t\tcvCmpS(self, val, res, %s);' % ( CMP_OPERATORS[op] )
print '\t\treturn res;'
print '\t}'
for op in SCALE_OPERATORS:
print '\t%%newobject operator %s;' % (op)
print '\t%s * operator %s (double val){' % (arr, op)
print '\t\t%s * res = %s;' % (arr, ARR[arr] )
print '\t\tcvScale(self, res, %s);' % SCALE_OPERATORS[op]
print '\t\treturn res;'
print '\t}'
print '\t%s * operator %s= (double val){' % (arr, op)
print '\t\tcvScale(self, self, %s);' % SCALE_OPERATORS[op]
print '\t\treturn self;'
print '\t}'
print '} /* extend %s */\n' % arr