Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
6dc7ae0f
Commit
6dc7ae0f
authored
Jun 06, 2011
by
Alexander Mordvintsev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added some constants to python cv2 api
parent
cd2f3786
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
20 deletions
+21
-20
cv2.cpp
modules/python/src2/cv2.cpp
+8
-0
browse.py
samples/python2/browse.py
+6
-6
gaussian_mix.py
samples/python2/gaussian_mix.py
+2
-2
letter_recog.py
samples/python2/letter_recog.py
+5
-12
No files found.
modules/python/src2/cv2.cpp
View file @
6dc7ae0f
...
...
@@ -856,6 +856,14 @@ void initcv2()
PUBLISH
(
GC_INIT_WITH_MASK
);
PUBLISH
(
GC_EVAL
);
PUBLISH
(
CV_ROW_SAMPLE
);
PUBLISH
(
CV_VAR_NUMERICAL
);
PUBLISH
(
CV_VAR_ORDERED
);
PUBLISH
(
CV_VAR_CATEGORICAL
);
PUBLISH
(
CV_AA
);
#include "pyopencv_generated_const_reg.h"
}
samples/python2/browse.py
View file @
6dc7ae0f
...
...
@@ -16,14 +16,14 @@ if len(sys.argv) > 1:
img
=
cv2
.
imread
(
fn
)
else
:
sz
=
4096
print
'generating
%
dx
%
d pr
e
cudural image ...'
%
(
sz
,
sz
)
print
'generating
%
dx
%
d pr
o
cudural image ...'
%
(
sz
,
sz
)
img
=
np
.
zeros
((
sz
,
sz
),
np
.
uint8
)
track
=
np
.
cumsum
(
np
.
random
.
rand
(
10
00000
,
2
)
-
0.5
,
axis
=
0
)
track
=
np
.
int32
(
track
*
2
0
+
(
sz
/
2
,
sz
/
2
))
track
=
np
.
cumsum
(
np
.
random
.
rand
(
5
00000
,
2
)
-
0.5
,
axis
=
0
)
track
=
np
.
int32
(
track
*
1
0
+
(
sz
/
2
,
sz
/
2
))
cv2
.
polylines
(
img
,
[
track
],
0
,
255
,
1
,
cv
.
CV_AA
)
small
=
img
for
i
in
xrange
(
4
):
for
i
in
xrange
(
3
):
small
=
cv2
.
pyrDown
(
small
)
def
onmouse
(
event
,
x
,
y
,
flags
,
param
):
...
...
@@ -33,6 +33,6 @@ def onmouse(event, x, y, flags, param):
zoom
=
cv2
.
getRectSubPix
(
img
,
(
800
,
600
),
(
x
+
0.5
,
y
+
0.5
))
cv2
.
imshow
(
'zoom'
,
zoom
)
cv2
.
imshow
(
'
small
'
,
small
)
cv
.
SetMouseCallback
(
'
small
'
,
onmouse
,
None
)
cv2
.
imshow
(
'
preview
'
,
small
)
cv
.
SetMouseCallback
(
'
preview
'
,
onmouse
,
None
)
cv2
.
waitKey
()
samples/python2/gaussian_mix.py
View file @
6dc7ae0f
import
numpy
as
np
from
numpy
import
random
import
cv2
,
cv
import
cv2
def
make_gaussians
(
cluster_n
,
img_size
):
...
...
@@ -22,7 +22,7 @@ def draw_gaussain(img, mean, cov, color):
w
,
u
,
vt
=
cv2
.
SVDecomp
(
cov
)
ang
=
np
.
rad2deg
(
np
.
arctan2
(
u
[
1
,
0
],
u
[
0
,
0
])
)
s1
,
s2
=
np
.
sqrt
(
w
)
*
3.0
cv2
.
ellipse
(
img
,
(
x
,
y
),
(
s1
,
s2
),
ang
,
0
,
360
,
color
,
1
,
cv
.
CV_AA
)
cv2
.
ellipse
(
img
,
(
x
,
y
),
(
s1
,
s2
),
ang
,
0
,
360
,
color
,
1
,
cv
2
.
CV_AA
)
if
__name__
==
'__main__'
:
...
...
samples/python2/letter_recog.py
View file @
6dc7ae0f
...
...
@@ -6,13 +6,6 @@ def load_base(fn):
samples
,
responses
=
a
[:,
1
:],
a
[:,
0
]
return
samples
,
responses
# TODO move these to cv2
CV_ROW_SAMPLE
=
1
CV_VAR_NUMERICAL
=
0
CV_VAR_ORDERED
=
0
CV_VAR_CATEGORICAL
=
1
class
LetterStatModel
(
object
):
train_ratio
=
0.5
def
load
(
self
,
fn
):
...
...
@@ -26,10 +19,10 @@ class RTrees(LetterStatModel):
def
train
(
self
,
samples
,
responses
):
sample_n
,
var_n
=
samples
.
shape
var_types
=
np
.
array
([
CV_VAR_NUMERICAL
]
*
var_n
+
[
CV_VAR_CATEGORICAL
],
np
.
uint8
)
var_types
=
np
.
array
([
cv2
.
CV_VAR_NUMERICAL
]
*
var_n
+
[
cv2
.
CV_VAR_CATEGORICAL
],
np
.
uint8
)
#CvRTParams(10,10,0,false,15,0,true,4,100,0.01f,CV_TERMCRIT_ITER));
params
=
dict
(
max_depth
=
10
)
self
.
model
.
train
(
samples
,
CV_ROW_SAMPLE
,
responses
,
varType
=
var_types
,
params
=
params
)
self
.
model
.
train
(
samples
,
cv2
.
CV_ROW_SAMPLE
,
responses
,
varType
=
var_types
,
params
=
params
)
def
predict
(
self
,
samples
):
return
np
.
float32
(
[
self
.
model
.
predict
(
s
)
for
s
in
samples
]
)
...
...
@@ -56,10 +49,10 @@ class Boost(LetterStatModel):
sample_n
,
var_n
=
samples
.
shape
new_samples
=
self
.
unroll_samples
(
samples
)
new_responses
=
self
.
unroll_responses
(
responses
)
var_types
=
np
.
array
([
CV_VAR_NUMERICAL
]
*
var_n
+
[
CV_VAR_CATEGORICAL
,
CV_VAR_CATEGORICAL
],
np
.
uint8
)
var_types
=
np
.
array
([
cv2
.
CV_VAR_NUMERICAL
]
*
var_n
+
[
cv2
.
CV_VAR_CATEGORICAL
,
cv2
.
CV_VAR_CATEGORICAL
],
np
.
uint8
)
#CvBoostParams(CvBoost::REAL, 100, 0.95, 5, false, 0 )
params
=
dict
(
max_depth
=
5
)
#, use_surrogates=False)
self
.
model
.
train
(
new_samples
,
CV_ROW_SAMPLE
,
new_responses
,
varType
=
var_types
,
params
=
params
)
self
.
model
.
train
(
new_samples
,
cv2
.
CV_ROW_SAMPLE
,
new_responses
,
varType
=
var_types
,
params
=
params
)
def
predict
(
self
,
samples
):
new_samples
=
self
.
unroll_samples
(
samples
)
...
...
@@ -105,7 +98,7 @@ if __name__ == '__main__':
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'-model'
,
default
=
'rtrees'
,
choices
=
models
.
keys
())
parser
.
add_argument
(
'-data'
,
nargs
=
1
,
default
=
'letter-recognition.data'
)
parser
.
add_argument
(
'-data'
,
nargs
=
1
,
default
=
'
../cpp/
letter-recognition.data'
)
parser
.
add_argument
(
'-load'
,
nargs
=
1
)
parser
.
add_argument
(
'-save'
,
nargs
=
1
)
args
=
parser
.
parse_args
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment