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
621e3eae
Commit
621e3eae
authored
Apr 15, 2019
by
LaurentBerger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Ptr KNearest::load and python binding
parent
c9a76ede
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
0 deletions
+32
-0
ml.hpp
modules/ml/include/opencv2/ml.hpp
+8
-0
test_knearest.py
modules/ml/misc/python/test/test_knearest.py
+13
-0
knearest.cpp
modules/ml/src/knearest.cpp
+11
-0
No files found.
modules/ml/include/opencv2/ml.hpp
View file @
621e3eae
...
...
@@ -505,6 +505,14 @@ public:
The static method creates empty %KNearest classifier. It should be then trained using StatModel::train method.
*/
CV_WRAP
static
Ptr
<
KNearest
>
create
();
/** @brief Loads and creates a serialized knearest from a file
*
* Use KNearest::save to serialize and store an KNearest to disk.
* Load the KNearest from this file again, by calling this function with the path to the file.
*
* @param filepath path to serialized KNearest
*/
CV_WRAP
static
Ptr
<
KNearest
>
load
(
const
String
&
filepath
);
};
/****************************************************************************************\
...
...
modules/ml/misc/python/test/test_knearest.py
0 → 100644
View file @
621e3eae
#!/usr/bin/env python
import
cv2
as
cv
from
tests_common
import
NewOpenCVTests
class
knearest_test
(
NewOpenCVTests
):
def
test_load
(
self
):
k_nearest
=
cv
.
ml
.
KNearest_load
(
self
.
find_file
(
"ml/opencv_ml_knn.xml"
))
self
.
assertFalse
(
k_nearest
.
empty
())
self
.
assertTrue
(
k_nearest
.
isTrained
())
if
__name__
==
'__main__'
:
NewOpenCVTests
.
bootstrap
()
modules/ml/src/knearest.cpp
View file @
621e3eae
...
...
@@ -515,6 +515,17 @@ Ptr<KNearest> KNearest::create()
return
makePtr
<
KNearestImpl
>
();
}
Ptr
<
KNearest
>
KNearest
::
load
(
const
String
&
filepath
)
{
FileStorage
fs
;
fs
.
open
(
filepath
,
FileStorage
::
READ
);
Ptr
<
KNearest
>
knearest
=
makePtr
<
KNearestImpl
>
();
((
KNearestImpl
*
)
knearest
.
get
())
->
read
(
fs
.
getFirstTopLevelNode
());
return
knearest
;
}
}
}
...
...
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