Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
54c07ba0
O
Opencv
项目概览
Greenplum
/
Opencv
大约 1 年 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
54c07ba0
编写于
2月 04, 2016
作者:
V
Vladislav Sovrasov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add 2 new tests, bugfixed in old tests
上级
86868176
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
428 addition
and
7 deletion
+428
-7
modules/python/test/test_camshift.py
modules/python/test/test_camshift.py
+112
-0
modules/python/test/test_facedetect.py
modules/python/test/test_facedetect.py
+2
-2
modules/python/test/test_letter_recog.py
modules/python/test/test_letter_recog.py
+167
-0
modules/python/test/test_peopledetect.py
modules/python/test/test_peopledetect.py
+73
-0
modules/python/test/tst_scene_render.py
modules/python/test/tst_scene_render.py
+67
-0
samples/python/letter_recog.py
samples/python/letter_recog.py
+7
-5
未找到文件。
modules/python/test/test_camshift.py
0 → 100644
浏览文件 @
54c07ba0
#!/usr/bin/env python
'''
Camshift tracker
================
This is a demo that shows mean-shift based tracking
You select a color objects such as your face and it tracks it.
This reads from video camera (0 by default, or the camera number the user enters)
http://www.robinhewitt.com/research/track/camshift.html
'''
# Python 2/3 compatibility
from
__future__
import
print_function
import
sys
PY3
=
sys
.
version_info
[
0
]
==
3
if
PY3
:
xrange
=
range
import
numpy
as
np
import
cv2
from
tst_scene_render
import
TestSceneRender
def
intersectionRate
(
s1
,
s2
):
x1
,
y1
,
x2
,
y2
=
s1
s1
=
[[
x1
,
y1
],
[
x2
,
y1
],
[
x2
,
y2
],
[
x1
,
y2
]
]
x1
,
y1
,
x2
,
y2
=
s2
s2
=
[[
x1
,
y1
],
[
x2
,
y1
],
[
x2
,
y2
],
[
x1
,
y2
]
]
area
,
intersection
=
cv2
.
intersectConvexConvex
(
np
.
array
(
s1
),
np
.
array
(
s2
))
return
2
*
area
/
(
cv2
.
contourArea
(
np
.
array
(
s1
))
+
cv2
.
contourArea
(
np
.
array
(
s2
)))
from
tests_common
import
NewOpenCVTests
class
camshift_test
(
NewOpenCVTests
):
frame
=
None
selection
=
None
drag_start
=
None
show_backproj
=
False
track_window
=
None
render
=
None
def
prepareRender
(
self
):
cv2
.
namedWindow
(
'camshift'
)
self
.
render
=
TestSceneRender
(
self
.
get_sample
(
'samples/data/pca_test1.jpg'
))
def
runTracker
(
self
):
framesCounter
=
0
self
.
selection
=
True
xmin
,
ymin
,
xmax
,
ymax
=
self
.
render
.
getCurrentRect
()
self
.
track_window
=
(
xmin
,
ymin
,
xmax
-
xmin
,
ymax
-
ymin
)
while
True
:
framesCounter
+=
1
self
.
frame
=
self
.
render
.
getNextFrame
()
vis
=
self
.
frame
.
copy
()
hsv
=
cv2
.
cvtColor
(
self
.
frame
,
cv2
.
COLOR_BGR2HSV
)
mask
=
cv2
.
inRange
(
hsv
,
np
.
array
((
0.
,
60.
,
32.
)),
np
.
array
((
180.
,
255.
,
255.
)))
if
self
.
selection
:
x0
,
y0
,
x1
,
y1
=
self
.
render
.
getCurrentRect
()
+
50
x0
-=
100
y0
-=
100
hsv_roi
=
hsv
[
y0
:
y1
,
x0
:
x1
]
mask_roi
=
mask
[
y0
:
y1
,
x0
:
x1
]
hist
=
cv2
.
calcHist
(
[
hsv_roi
],
[
0
],
mask_roi
,
[
16
],
[
0
,
180
]
)
cv2
.
normalize
(
hist
,
hist
,
0
,
255
,
cv2
.
NORM_MINMAX
)
self
.
hist
=
hist
.
reshape
(
-
1
)
vis_roi
=
vis
[
y0
:
y1
,
x0
:
x1
]
cv2
.
bitwise_not
(
vis_roi
,
vis_roi
)
vis
[
mask
==
0
]
=
0
self
.
selection
=
False
if
self
.
track_window
and
self
.
track_window
[
2
]
>
0
and
self
.
track_window
[
3
]
>
0
:
self
.
selection
=
None
prob
=
cv2
.
calcBackProject
([
hsv
],
[
0
],
self
.
hist
,
[
0
,
180
],
1
)
prob
&=
mask
term_crit
=
(
cv2
.
TERM_CRITERIA_EPS
|
cv2
.
TERM_CRITERIA_COUNT
,
10
,
1
)
track_box
,
self
.
track_window
=
cv2
.
CamShift
(
prob
,
self
.
track_window
,
term_crit
)
if
self
.
show_backproj
:
vis
[:]
=
prob
[...,
np
.
newaxis
]
cv2
.
rectangle
(
vis
,
(
self
.
track_window
[
0
],
self
.
track_window
[
1
]),
(
self
.
track_window
[
0
]
+
self
.
track_window
[
2
],
self
.
track_window
[
1
]
+
self
.
track_window
[
3
]),
(
0
,
255
,
0
),
2
)
trackingRect
=
np
.
array
(
self
.
track_window
)
trackingRect
[
2
]
+=
trackingRect
[
0
]
trackingRect
[
3
]
+=
trackingRect
[
1
]
print
(
intersectionRate
((
self
.
render
.
getCurrentRect
()),
trackingRect
))
self
.
assertGreater
(
intersectionRate
((
self
.
render
.
getCurrentRect
()),
trackingRect
),
0.5
)
if
framesCounter
>
300
:
break
def
test_camshift
(
self
):
self
.
prepareRender
()
self
.
runTracker
()
\ No newline at end of file
modules/python/test/test_facedetect.py
浏览文件 @
54c07ba0
...
@@ -93,9 +93,9 @@ class facedetect_test(NewOpenCVTests):
...
@@ -93,9 +93,9 @@ class facedetect_test(NewOpenCVTests):
faces_matches
+=
1
faces_matches
+=
1
#check eyes
#check eyes
if
len
(
eyes
[
i
])
==
2
:
if
len
(
eyes
[
i
])
==
2
:
if
intersectionRate
(
eyes
[
i
][
0
],
testFaces
[
j
][
1
])
>
eps
and
intersectionRate
(
eyes
[
i
][
1
]
,
testFaces
[
j
][
2
])
:
if
intersectionRate
(
eyes
[
i
][
0
],
testFaces
[
j
][
1
])
>
eps
and
intersectionRate
(
eyes
[
i
][
1
]
,
testFaces
[
j
][
2
])
>
eps
:
eyes_matches
+=
1
eyes_matches
+=
1
elif
intersectionRate
(
eyes
[
i
][
1
],
testFaces
[
j
][
1
])
>
eps
and
intersectionRate
(
eyes
[
i
][
0
],
testFaces
[
j
][
2
]):
elif
intersectionRate
(
eyes
[
i
][
1
],
testFaces
[
j
][
1
])
>
eps
and
intersectionRate
(
eyes
[
i
][
0
],
testFaces
[
j
][
2
])
>
eps
:
eyes_matches
+=
1
eyes_matches
+=
1
self
.
assertEqual
(
faces_matches
,
2
)
self
.
assertEqual
(
faces_matches
,
2
)
...
...
modules/python/test/test_letter_recog.py
0 → 100644
浏览文件 @
54c07ba0
#!/usr/bin/env python
'''
The sample demonstrates how to train Random Trees classifier
(or Boosting classifier, or MLP, or Knearest, or Support Vector Machines) using the provided dataset.
We use the sample database letter-recognition.data
from UCI Repository, here is the link:
Newman, D.J. & Hettich, S. & Blake, C.L. & Merz, C.J. (1998).
UCI Repository of machine learning databases
[http://www.ics.uci.edu/~mlearn/MLRepository.html].
Irvine, CA: University of California, Department of Information and Computer Science.
The dataset consists of 20000 feature vectors along with the
responses - capital latin letters A..Z.
The first 10000 samples are used for training
and the remaining 10000 - to test the classifier.
======================================================
Models: RTrees, KNearest, Boost, SVM, MLP
'''
# Python 2/3 compatibility
from
__future__
import
print_function
import
numpy
as
np
import
cv2
def
load_base
(
fn
):
a
=
np
.
loadtxt
(
fn
,
np
.
float32
,
delimiter
=
','
,
converters
=
{
0
:
lambda
ch
:
ord
(
ch
)
-
ord
(
'A'
)
})
samples
,
responses
=
a
[:,
1
:],
a
[:,
0
]
return
samples
,
responses
class
LetterStatModel
(
object
):
class_n
=
26
train_ratio
=
0.5
def
load
(
self
,
fn
):
self
.
model
.
load
(
fn
)
def
save
(
self
,
fn
):
self
.
model
.
save
(
fn
)
def
unroll_samples
(
self
,
samples
):
sample_n
,
var_n
=
samples
.
shape
new_samples
=
np
.
zeros
((
sample_n
*
self
.
class_n
,
var_n
+
1
),
np
.
float32
)
new_samples
[:,:
-
1
]
=
np
.
repeat
(
samples
,
self
.
class_n
,
axis
=
0
)
new_samples
[:,
-
1
]
=
np
.
tile
(
np
.
arange
(
self
.
class_n
),
sample_n
)
return
new_samples
def
unroll_responses
(
self
,
responses
):
sample_n
=
len
(
responses
)
new_responses
=
np
.
zeros
(
sample_n
*
self
.
class_n
,
np
.
int32
)
resp_idx
=
np
.
int32
(
responses
+
np
.
arange
(
sample_n
)
*
self
.
class_n
)
new_responses
[
resp_idx
]
=
1
return
new_responses
class
RTrees
(
LetterStatModel
):
def
__init__
(
self
):
self
.
model
=
cv2
.
ml
.
RTrees_create
()
def
train
(
self
,
samples
,
responses
):
sample_n
,
var_n
=
samples
.
shape
self
.
model
.
setMaxDepth
(
20
)
self
.
model
.
train
(
samples
,
cv2
.
ml
.
ROW_SAMPLE
,
responses
.
astype
(
int
))
def
predict
(
self
,
samples
):
ret
,
resp
=
self
.
model
.
predict
(
samples
)
return
resp
.
ravel
()
class
KNearest
(
LetterStatModel
):
def
__init__
(
self
):
self
.
model
=
cv2
.
ml
.
KNearest_create
()
def
train
(
self
,
samples
,
responses
):
self
.
model
.
train
(
samples
,
cv2
.
ml
.
ROW_SAMPLE
,
responses
)
def
predict
(
self
,
samples
):
retval
,
results
,
neigh_resp
,
dists
=
self
.
model
.
findNearest
(
samples
,
k
=
10
)
return
results
.
ravel
()
class
Boost
(
LetterStatModel
):
def
__init__
(
self
):
self
.
model
=
cv2
.
ml
.
Boost_create
()
def
train
(
self
,
samples
,
responses
):
sample_n
,
var_n
=
samples
.
shape
new_samples
=
self
.
unroll_samples
(
samples
)
new_responses
=
self
.
unroll_responses
(
responses
)
var_types
=
np
.
array
([
cv2
.
ml
.
VAR_NUMERICAL
]
*
var_n
+
[
cv2
.
ml
.
VAR_CATEGORICAL
,
cv2
.
ml
.
VAR_CATEGORICAL
],
np
.
uint8
)
self
.
model
.
setWeakCount
(
15
)
self
.
model
.
setMaxDepth
(
10
)
self
.
model
.
train
(
cv2
.
ml
.
TrainData_create
(
new_samples
,
cv2
.
ml
.
ROW_SAMPLE
,
new_responses
.
astype
(
int
),
varType
=
var_types
))
def
predict
(
self
,
samples
):
new_samples
=
self
.
unroll_samples
(
samples
)
ret
,
resp
=
self
.
model
.
predict
(
new_samples
)
return
resp
.
ravel
().
reshape
(
-
1
,
self
.
class_n
).
argmax
(
1
)
class
SVM
(
LetterStatModel
):
def
__init__
(
self
):
self
.
model
=
cv2
.
ml
.
SVM_create
()
def
train
(
self
,
samples
,
responses
):
self
.
model
.
setType
(
cv2
.
ml
.
SVM_C_SVC
)
self
.
model
.
setC
(
1
)
self
.
model
.
setKernel
(
cv2
.
ml
.
SVM_RBF
)
self
.
model
.
setGamma
(.
1
)
self
.
model
.
train
(
samples
,
cv2
.
ml
.
ROW_SAMPLE
,
responses
.
astype
(
int
))
def
predict
(
self
,
samples
):
ret
,
resp
=
self
.
model
.
predict
(
samples
)
return
resp
.
ravel
()
class
MLP
(
LetterStatModel
):
def
__init__
(
self
):
self
.
model
=
cv2
.
ml
.
ANN_MLP_create
()
def
train
(
self
,
samples
,
responses
):
sample_n
,
var_n
=
samples
.
shape
new_responses
=
self
.
unroll_responses
(
responses
).
reshape
(
-
1
,
self
.
class_n
)
layer_sizes
=
np
.
int32
([
var_n
,
100
,
100
,
self
.
class_n
])
self
.
model
.
setLayerSizes
(
layer_sizes
)
self
.
model
.
setTrainMethod
(
cv2
.
ml
.
ANN_MLP_BACKPROP
)
self
.
model
.
setBackpropMomentumScale
(
0
)
self
.
model
.
setBackpropWeightScale
(
0.001
)
self
.
model
.
setTermCriteria
((
cv2
.
TERM_CRITERIA_COUNT
,
20
,
0.01
))
self
.
model
.
setActivationFunction
(
cv2
.
ml
.
ANN_MLP_SIGMOID_SYM
,
2
,
1
)
self
.
model
.
train
(
samples
,
cv2
.
ml
.
ROW_SAMPLE
,
np
.
float32
(
new_responses
))
def
predict
(
self
,
samples
):
ret
,
resp
=
self
.
model
.
predict
(
samples
)
return
resp
.
argmax
(
-
1
)
from
tests_common
import
NewOpenCVTests
class
letter_recog_test
(
NewOpenCVTests
):
def
test_letter_recog
(
self
):
eps
=
0.01
models
=
[
RTrees
,
KNearest
,
Boost
,
SVM
,
MLP
]
models
=
dict
(
[(
cls
.
__name__
.
lower
(),
cls
)
for
cls
in
models
]
)
testErrors
=
{
RTrees
:
(
98.930000
,
92.390000
),
KNearest
:
(
94.960000
,
92.010000
),
Boost
:
(
85.970000
,
74.920000
),
SVM
:
(
99.780000
,
95.680000
),
MLP
:
(
90.060000
,
87.410000
)}
for
model
in
models
:
Model
=
models
[
model
]
classifier
=
Model
()
samples
,
responses
=
load_base
(
self
.
repoPath
+
'/samples/data/letter-recognition.data'
)
train_n
=
int
(
len
(
samples
)
*
classifier
.
train_ratio
)
classifier
.
train
(
samples
[:
train_n
],
responses
[:
train_n
])
train_rate
=
np
.
mean
(
classifier
.
predict
(
samples
[:
train_n
])
==
responses
[:
train_n
].
astype
(
int
))
test_rate
=
np
.
mean
(
classifier
.
predict
(
samples
[
train_n
:])
==
responses
[
train_n
:].
astype
(
int
))
self
.
assertLess
(
train_rate
-
testErrors
[
Model
][
0
],
eps
)
self
.
assertLess
(
test_rate
-
testErrors
[
Model
][
1
],
eps
)
\ No newline at end of file
modules/python/test/test_peopledetect.py
0 → 100644
浏览文件 @
54c07ba0
#!/usr/bin/env python
'''
example to detect upright people in images using HOG features
'''
# Python 2/3 compatibility
from
__future__
import
print_function
import
numpy
as
np
import
cv2
def
inside
(
r
,
q
):
rx
,
ry
,
rw
,
rh
=
r
qx
,
qy
,
qw
,
qh
=
q
return
rx
>
qx
and
ry
>
qy
and
rx
+
rw
<
qx
+
qw
and
ry
+
rh
<
qy
+
qh
def
intersectionRate
(
s1
,
s2
):
x1
,
y1
,
x2
,
y2
=
s1
s1
=
[[
x1
,
y1
],
[
x2
,
y1
],
[
x2
,
y2
],
[
x1
,
y2
]
]
x1
,
y1
,
x2
,
y2
=
s2
s2
=
[[
x1
,
y1
],
[
x2
,
y1
],
[
x2
,
y2
],
[
x1
,
y2
]
]
area
,
intersection
=
cv2
.
intersectConvexConvex
(
np
.
array
(
s1
),
np
.
array
(
s2
))
return
2
*
area
/
(
cv2
.
contourArea
(
np
.
array
(
s1
))
+
cv2
.
contourArea
(
np
.
array
(
s2
)))
from
tests_common
import
NewOpenCVTests
class
peopledetect_test
(
NewOpenCVTests
):
def
test_peopledetect
(
self
):
hog
=
cv2
.
HOGDescriptor
()
hog
.
setSVMDetector
(
cv2
.
HOGDescriptor_getDefaultPeopleDetector
()
)
dirPath
=
'samples/data/'
samples
=
[
'basketball1.png'
,
'basketball2.png'
]
testPeople
=
[
[[
23
,
76
,
164
,
477
],
[
440
,
22
,
637
,
478
]],
[[
23
,
76
,
164
,
477
],
[
440
,
22
,
637
,
478
]]
]
eps
=
0.5
for
sample
in
samples
:
img
=
self
.
get_sample
(
dirPath
+
sample
,
0
)
found
,
w
=
hog
.
detectMultiScale
(
img
,
winStride
=
(
8
,
8
),
padding
=
(
32
,
32
),
scale
=
1.05
)
found_filtered
=
[]
for
ri
,
r
in
enumerate
(
found
):
for
qi
,
q
in
enumerate
(
found
):
if
ri
!=
qi
and
inside
(
r
,
q
):
break
else
:
found_filtered
.
append
(
r
)
matches
=
0
for
i
in
range
(
len
(
found_filtered
)):
for
j
in
range
(
len
(
testPeople
)):
found_rect
=
(
found_filtered
[
i
][
0
],
found_filtered
[
i
][
1
],
found_filtered
[
i
][
0
]
+
found_filtered
[
i
][
2
],
found_filtered
[
i
][
1
]
+
found_filtered
[
i
][
3
])
if
intersectionRate
(
found_rect
,
testPeople
[
j
][
0
])
>
eps
or
intersectionRate
(
found_rect
,
testPeople
[
j
][
1
])
>
eps
:
matches
+=
1
self
.
assertGreater
(
matches
,
0
)
\ No newline at end of file
modules/python/test/tst_scene_render.py
0 → 100644
浏览文件 @
54c07ba0
#!/usr/bin/env python
# Python 2/3 compatibility
from
__future__
import
print_function
import
numpy
as
np
from
numpy
import
pi
,
sin
,
cos
import
cv2
defaultSize
=
512
class
TestSceneRender
():
def
__init__
(
self
,
bgImg
=
None
,
**
params
):
self
.
time
=
0.0
self
.
timeStep
=
1.0
/
30.0
if
bgImg
!=
None
:
self
.
sceneBg
=
bgImg
.
copy
()
else
:
self
.
sceneBg
=
np
.
zeros
((
defaultSize
,
defaultSize
,
3
),
np
.
uint8
)
self
.
w
=
self
.
sceneBg
.
shape
[
0
]
self
.
h
=
self
.
sceneBg
.
shape
[
1
]
self
.
initialRect
=
np
.
array
([
(
self
.
h
/
2
,
self
.
w
/
2
),
(
self
.
h
/
2
,
self
.
w
/
2
+
self
.
w
/
10
),
(
self
.
h
/
2
+
self
.
h
/
10
,
self
.
w
/
2
+
self
.
w
/
10
),
(
self
.
h
/
2
+
self
.
h
/
10
,
self
.
w
/
2
)])
self
.
currentRect
=
self
.
initialRect
def
setInitialRect
(
self
,
rect
):
self
.
initialRect
=
rect
def
getCurrentRect
(
self
):
x0
,
y0
=
self
.
currentRect
[
0
]
x1
,
y1
=
self
.
currentRect
[
2
]
return
np
.
array
([
x0
,
y0
,
x1
,
y1
])
def
getNextFrame
(
self
):
self
.
time
+=
self
.
timeStep
img
=
self
.
sceneBg
.
copy
()
self
.
currentRect
=
self
.
initialRect
+
np
.
int
(
30
*
cos
(
self
.
time
)
+
50
*
sin
(
self
.
time
/
3
))
cv2
.
fillConvexPoly
(
img
,
self
.
currentRect
,
(
0
,
0
,
255
))
return
img
def
resetTime
(
self
):
self
.
time
=
0.0
if
__name__
==
'__main__'
:
backGr
=
cv2
.
imread
(
'../../../samples/data/lena.jpg'
)
render
=
TestSceneRender
(
backGr
)
while
True
:
img
=
render
.
getNextFrame
()
cv2
.
imshow
(
'img'
,
img
)
ch
=
0xFF
&
cv2
.
waitKey
(
3
)
if
ch
==
27
:
break
cv2
.
destroyAllWindows
()
\ No newline at end of file
samples/python/letter_recog.py
浏览文件 @
54c07ba0
...
@@ -95,7 +95,8 @@ class Boost(LetterStatModel):
...
@@ -95,7 +95,8 @@ class Boost(LetterStatModel):
new_responses
=
self
.
unroll_responses
(
responses
)
new_responses
=
self
.
unroll_responses
(
responses
)
var_types
=
np
.
array
([
cv2
.
ml
.
VAR_NUMERICAL
]
*
var_n
+
[
cv2
.
ml
.
VAR_CATEGORICAL
,
cv2
.
ml
.
VAR_CATEGORICAL
],
np
.
uint8
)
var_types
=
np
.
array
([
cv2
.
ml
.
VAR_NUMERICAL
]
*
var_n
+
[
cv2
.
ml
.
VAR_CATEGORICAL
,
cv2
.
ml
.
VAR_CATEGORICAL
],
np
.
uint8
)
self
.
model
.
setMaxDepth
(
5
)
self
.
model
.
setWeakCount
(
15
)
self
.
model
.
setMaxDepth
(
10
)
self
.
model
.
train
(
cv2
.
ml
.
TrainData_create
(
new_samples
,
cv2
.
ml
.
ROW_SAMPLE
,
new_responses
.
astype
(
int
),
varType
=
var_types
))
self
.
model
.
train
(
cv2
.
ml
.
TrainData_create
(
new_samples
,
cv2
.
ml
.
ROW_SAMPLE
,
new_responses
.
astype
(
int
),
varType
=
var_types
))
def
predict
(
self
,
samples
):
def
predict
(
self
,
samples
):
...
@@ -112,7 +113,8 @@ class SVM(LetterStatModel):
...
@@ -112,7 +113,8 @@ class SVM(LetterStatModel):
def
train
(
self
,
samples
,
responses
):
def
train
(
self
,
samples
,
responses
):
self
.
model
.
setType
(
cv2
.
ml
.
SVM_C_SVC
)
self
.
model
.
setType
(
cv2
.
ml
.
SVM_C_SVC
)
self
.
model
.
setC
(
1
)
self
.
model
.
setC
(
1
)
self
.
model
.
setKernel
(
cv2
.
ml
.
SVM_LINEAR
)
self
.
model
.
setKernel
(
cv2
.
ml
.
SVM_RBF
)
self
.
model
.
setGamma
(.
1
)
self
.
model
.
train
(
samples
,
cv2
.
ml
.
ROW_SAMPLE
,
responses
.
astype
(
int
))
self
.
model
.
train
(
samples
,
cv2
.
ml
.
ROW_SAMPLE
,
responses
.
astype
(
int
))
def
predict
(
self
,
samples
):
def
predict
(
self
,
samples
):
...
@@ -131,10 +133,10 @@ class MLP(LetterStatModel):
...
@@ -131,10 +133,10 @@ class MLP(LetterStatModel):
self
.
model
.
setLayerSizes
(
layer_sizes
)
self
.
model
.
setLayerSizes
(
layer_sizes
)
self
.
model
.
setTrainMethod
(
cv2
.
ml
.
ANN_MLP_BACKPROP
)
self
.
model
.
setTrainMethod
(
cv2
.
ml
.
ANN_MLP_BACKPROP
)
self
.
model
.
setBackpropMomentumScale
(
0
)
self
.
model
.
setBackpropMomentumScale
(
0
.0
)
self
.
model
.
setBackpropWeightScale
(
0.001
)
self
.
model
.
setBackpropWeightScale
(
0.001
)
self
.
model
.
setTermCriteria
((
cv2
.
TERM_CRITERIA_COUNT
,
30
0
,
0.01
))
self
.
model
.
setTermCriteria
((
cv2
.
TERM_CRITERIA_COUNT
,
2
0
,
0.01
))
self
.
model
.
setActivationFunction
(
cv2
.
ml
.
ANN_MLP_SIGMOID_SYM
)
self
.
model
.
setActivationFunction
(
cv2
.
ml
.
ANN_MLP_SIGMOID_SYM
,
2
,
1
)
self
.
model
.
train
(
samples
,
cv2
.
ml
.
ROW_SAMPLE
,
np
.
float32
(
new_responses
))
self
.
model
.
train
(
samples
,
cv2
.
ml
.
ROW_SAMPLE
,
np
.
float32
(
new_responses
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录