Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
4cc458eb
O
Opencv
项目概览
Greenplum
/
Opencv
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
4cc458eb
编写于
1月 13, 2020
作者:
A
Alexander Alekhin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16335 from berak:fix_ml_python_digits_samples_3.4
上级
38e6d668
a718f2e6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
12 deletion
+22
-12
samples/python/digits.py
samples/python/digits.py
+13
-7
samples/python/digits_video.py
samples/python/digits_video.py
+9
-5
未找到文件。
samples/python/digits.py
浏览文件 @
4cc458eb
...
@@ -70,13 +70,8 @@ def deskew(img):
...
@@ -70,13 +70,8 @@ def deskew(img):
img
=
cv
.
warpAffine
(
img
,
M
,
(
SZ
,
SZ
),
flags
=
cv
.
WARP_INVERSE_MAP
|
cv
.
INTER_LINEAR
)
img
=
cv
.
warpAffine
(
img
,
M
,
(
SZ
,
SZ
),
flags
=
cv
.
WARP_INVERSE_MAP
|
cv
.
INTER_LINEAR
)
return
img
return
img
class
StatModel
(
object
):
def
load
(
self
,
fn
):
self
.
model
.
load
(
fn
)
# Known bug: https://github.com/opencv/opencv/issues/4969
def
save
(
self
,
fn
):
self
.
model
.
save
(
fn
)
class
KNearest
(
StatModel
):
class
KNearest
(
object
):
def
__init__
(
self
,
k
=
3
):
def
__init__
(
self
,
k
=
3
):
self
.
k
=
k
self
.
k
=
k
self
.
model
=
cv
.
ml
.
KNearest_create
()
self
.
model
=
cv
.
ml
.
KNearest_create
()
...
@@ -88,7 +83,13 @@ class KNearest(StatModel):
...
@@ -88,7 +83,13 @@ class KNearest(StatModel):
_retval
,
results
,
_neigh_resp
,
_dists
=
self
.
model
.
findNearest
(
samples
,
self
.
k
)
_retval
,
results
,
_neigh_resp
,
_dists
=
self
.
model
.
findNearest
(
samples
,
self
.
k
)
return
results
.
ravel
()
return
results
.
ravel
()
class
SVM
(
StatModel
):
def
load
(
self
,
fn
):
self
.
model
=
cv
.
ml
.
KNearest_load
(
fn
)
def
save
(
self
,
fn
):
self
.
model
.
save
(
fn
)
class
SVM
(
object
):
def
__init__
(
self
,
C
=
1
,
gamma
=
0.5
):
def
__init__
(
self
,
C
=
1
,
gamma
=
0.5
):
self
.
model
=
cv
.
ml
.
SVM_create
()
self
.
model
=
cv
.
ml
.
SVM_create
()
self
.
model
.
setGamma
(
gamma
)
self
.
model
.
setGamma
(
gamma
)
...
@@ -102,6 +103,11 @@ class SVM(StatModel):
...
@@ -102,6 +103,11 @@ class SVM(StatModel):
def
predict
(
self
,
samples
):
def
predict
(
self
,
samples
):
return
self
.
model
.
predict
(
samples
)[
1
].
ravel
()
return
self
.
model
.
predict
(
samples
)[
1
].
ravel
()
def
load
(
self
,
fn
):
self
.
model
=
cv
.
ml
.
SVM_load
(
fn
)
def
save
(
self
,
fn
):
self
.
model
.
save
(
fn
)
def
evaluate_model
(
model
,
digits
,
samples
,
labels
):
def
evaluate_model
(
model
,
digits
,
samples
,
labels
):
resp
=
model
.
predict
(
samples
)
resp
=
model
.
predict
(
samples
)
...
...
samples/python/digits_video.py
浏览文件 @
4cc458eb
#!/usr/bin/env python
#!/usr/bin/env python
'''
Digit recognition from video.
Run digits.py before, to train and save the SVM.
Usage:
digits_video.py [{camera_id|video_file}]
'''
# Python 2/3 compatibility
# Python 2/3 compatibility
from
__future__
import
print_function
from
__future__
import
print_function
...
@@ -28,11 +36,7 @@ def main():
...
@@ -28,11 +36,7 @@ def main():
print
(
'"%s" not found, run digits.py first'
%
classifier_fn
)
print
(
'"%s" not found, run digits.py first'
%
classifier_fn
)
return
return
if
True
:
model
=
cv
.
ml
.
SVM_load
(
classifier_fn
)
model
=
cv
.
ml
.
SVM_load
(
classifier_fn
)
else
:
model
=
cv
.
ml
.
SVM_create
()
model
.
load_
(
classifier_fn
)
#Known bug: https://github.com/opencv/opencv/issues/4969
while
True
:
while
True
:
_ret
,
frame
=
cap
.
read
()
_ret
,
frame
=
cap
.
read
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录