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
a4a2659d
Commit
a4a2659d
authored
May 27, 2015
by
Joe Minichino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed digits.py sample to work with opencv 3
parent
565d3dde
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
10 deletions
+15
-10
digits.py
samples/python2/digits.py
+15
-10
No files found.
samples/python2/digits.py
View file @
a4a2659d
...
...
@@ -74,30 +74,35 @@ class StatModel(object):
class
KNearest
(
StatModel
):
def
__init__
(
self
,
k
=
3
):
self
.
k
=
k
self
.
model
=
cv2
.
KNearest
()
self
.
model
=
cv2
.
ml
.
KNearest_create
()
def
train
(
self
,
samples
,
responses
):
self
.
model
=
cv2
.
KNearest
()
self
.
model
.
train
(
samples
,
responses
)
self
.
model
=
cv2
.
ml
.
KNearest_create
()
self
.
model
.
train
(
samples
,
cv2
.
ml
.
ROW_SAMPLE
,
responses
)
def
predict
(
self
,
samples
):
retval
,
results
,
neigh_resp
,
dists
=
self
.
model
.
find
_n
earest
(
samples
,
self
.
k
)
retval
,
results
,
neigh_resp
,
dists
=
self
.
model
.
find
N
earest
(
samples
,
self
.
k
)
return
results
.
ravel
()
class
SVM
(
StatModel
):
def
__init__
(
self
,
C
=
1
,
gamma
=
0.5
):
self
.
params
=
dict
(
kernel_type
=
cv2
.
SVM_RBF
,
svm_type
=
cv2
.
SVM_C_SVC
,
self
.
params
=
dict
(
kernel_type
=
cv2
.
ml
.
SVM_RBF
,
svm_type
=
cv2
.
ml
.
SVM_C_SVC
,
C
=
C
,
gamma
=
gamma
)
self
.
model
=
cv2
.
SVM
()
self
.
model
=
cv2
.
ml
.
SVM_create
()
def
train
(
self
,
samples
,
responses
):
self
.
model
=
cv2
.
SVM
()
self
.
model
.
train
(
samples
,
responses
,
params
=
self
.
params
)
self
.
model
=
cv2
.
ml
.
SVM_create
()
""" original code """
#self.model.train(samples, responses, params = self.params)
""" but it's either this """
self
.
model
.
train
(
samples
,
cv2
.
ml
.
ROW_SAMPLE
,
responses
)
""" or this """
#self.model.train(samples, params = self.params)
def
predict
(
self
,
samples
):
return
self
.
model
.
predict
_all
(
samples
)
.
ravel
()
return
self
.
model
.
predict
(
samples
)[
1
][
0
]
.
ravel
()
def
evaluate_model
(
model
,
digits
,
samples
,
labels
):
...
...
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