Skip to content

Commit 19c0016

Browse files
committed
Move ml to opencv_contrib
1 parent f63396a commit 19c0016

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+22183
-0
lines changed

modules/ml/CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set(the_description "Machine Learning")
2+
3+
ocv_add_module(ml opencv_core WRAP java objc python)
4+
ocv_glob_module_sources()
5+
ocv_module_include_directories()
6+
ocv_create_module()
7+
8+
ocv_add_accuracy_tests()
9+
ocv_add_perf_tests()
10+
ocv_add_samples(opencv_imgproc opencv_imgcodecs opencv_objdetect opencv_videoio opencv_video)

modules/ml/doc/ml_intro.markdown

+481
Large diffs are not rendered by default.
92 KB
Loading

modules/ml/doc/pics/mlp.png

11.1 KB
Loading

modules/ml/doc/pics/neuron_model.png

9.77 KB
Loading
6.98 KB
Loading

modules/ml/include/opencv2/ml.hpp

+1,956
Large diffs are not rendered by default.

modules/ml/include/opencv2/ml/ml.hpp

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*M///////////////////////////////////////////////////////////////////////////////////////
2+
//
3+
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4+
//
5+
// By downloading, copying, installing or using the software you agree to this license.
6+
// If you do not agree to this license, do not download, install,
7+
// copy or use the software.
8+
//
9+
//
10+
// License Agreement
11+
// For Open Source Computer Vision Library
12+
//
13+
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14+
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15+
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
16+
// Third party copyrights are property of their respective owners.
17+
//
18+
// Redistribution and use in source and binary forms, with or without modification,
19+
// are permitted provided that the following conditions are met:
20+
//
21+
// * Redistribution's of source code must retain the above copyright notice,
22+
// this list of conditions and the following disclaimer.
23+
//
24+
// * Redistribution's in binary form must reproduce the above copyright notice,
25+
// this list of conditions and the following disclaimer in the documentation
26+
// and/or other materials provided with the distribution.
27+
//
28+
// * The name of the copyright holders may not be used to endorse or promote products
29+
// derived from this software without specific prior written permission.
30+
//
31+
// This software is provided by the copyright holders and contributors "as is" and
32+
// any express or implied warranties, including, but not limited to, the implied
33+
// warranties of merchantability and fitness for a particular purpose are disclaimed.
34+
// In no event shall the Intel Corporation or contributors be liable for any direct,
35+
// indirect, incidental, special, exemplary, or consequential damages
36+
// (including, but not limited to, procurement of substitute goods or services;
37+
// loss of use, data, or profits; or business interruption) however caused
38+
// and on any theory of liability, whether in contract, strict liability,
39+
// or tort (including negligence or otherwise) arising in any way out of
40+
// the use of this software, even if advised of the possibility of such damage.
41+
//
42+
//M*/
43+
44+
#ifdef __OPENCV_BUILD
45+
#error this is a compatibility header which should not be used inside the OpenCV library
46+
#endif
47+
48+
#include "opencv2/ml.hpp"
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#ifndef OPENCV_ML_INL_HPP
6+
#define OPENCV_ML_INL_HPP
7+
8+
namespace cv { namespace ml {
9+
10+
// declared in ml.hpp
11+
template<class SimulatedAnnealingSolverSystem>
12+
int simulatedAnnealingSolver(SimulatedAnnealingSolverSystem& solverSystem,
13+
double initialTemperature, double finalTemperature, double coolingRatio,
14+
size_t iterationsPerStep,
15+
CV_OUT double* lastTemperature,
16+
cv::RNG& rngEnergy
17+
)
18+
{
19+
CV_Assert(finalTemperature > 0);
20+
CV_Assert(initialTemperature > finalTemperature);
21+
CV_Assert(iterationsPerStep > 0);
22+
CV_Assert(coolingRatio < 1.0f);
23+
double Ti = initialTemperature;
24+
double previousEnergy = solverSystem.energy();
25+
int exchange = 0;
26+
while (Ti > finalTemperature)
27+
{
28+
for (size_t i = 0; i < iterationsPerStep; i++)
29+
{
30+
solverSystem.changeState();
31+
double newEnergy = solverSystem.energy();
32+
if (newEnergy < previousEnergy)
33+
{
34+
previousEnergy = newEnergy;
35+
exchange++;
36+
}
37+
else
38+
{
39+
double r = rngEnergy.uniform(0.0, 1.0);
40+
if (r < std::exp(-(newEnergy - previousEnergy) / Ti))
41+
{
42+
previousEnergy = newEnergy;
43+
exchange++;
44+
}
45+
else
46+
{
47+
solverSystem.reverseState();
48+
}
49+
}
50+
}
51+
Ti *= coolingRatio;
52+
}
53+
if (lastTemperature)
54+
*lastTemperature = Ti;
55+
return exchange;
56+
}
57+
58+
}} //namespace
59+
60+
#endif // OPENCV_ML_INL_HPP

modules/ml/misc/java/test/MLTest.java

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.opencv.test.ml;
2+
3+
import org.opencv.ml.Ml;
4+
import org.opencv.ml.SVM;
5+
import org.opencv.core.Mat;
6+
import org.opencv.core.MatOfFloat;
7+
import org.opencv.core.MatOfInt;
8+
import org.opencv.core.CvType;
9+
import org.opencv.test.OpenCVTestCase;
10+
import org.opencv.test.OpenCVTestRunner;
11+
12+
public class MLTest extends OpenCVTestCase {
13+
14+
public void testSaveLoad() {
15+
Mat samples = new MatOfFloat(new float[] {
16+
5.1f, 3.5f, 1.4f, 0.2f,
17+
4.9f, 3.0f, 1.4f, 0.2f,
18+
4.7f, 3.2f, 1.3f, 0.2f,
19+
4.6f, 3.1f, 1.5f, 0.2f,
20+
5.0f, 3.6f, 1.4f, 0.2f,
21+
7.0f, 3.2f, 4.7f, 1.4f,
22+
6.4f, 3.2f, 4.5f, 1.5f,
23+
6.9f, 3.1f, 4.9f, 1.5f,
24+
5.5f, 2.3f, 4.0f, 1.3f,
25+
6.5f, 2.8f, 4.6f, 1.5f
26+
}).reshape(1, 10);
27+
Mat responses = new MatOfInt(new int[] {
28+
0, 0, 0, 0, 0, 1, 1, 1, 1, 1
29+
}).reshape(1, 10);
30+
SVM saved = SVM.create();
31+
assertFalse(saved.isTrained());
32+
33+
saved.train(samples, Ml.ROW_SAMPLE, responses);
34+
assertTrue(saved.isTrained());
35+
36+
String filename = OpenCVTestRunner.getTempFileName("yml");
37+
saved.save(filename);
38+
SVM loaded = SVM.load(filename);
39+
assertTrue(loaded.isTrained());
40+
}
41+
42+
}

modules/ml/misc/objc/gen_dict.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"enum_fix" : {
3+
"EM" : { "Types": "EMTypes" },
4+
"SVM" : { "Types": "SVMTypes" },
5+
"KNearest" : { "Types": "KNearestTypes" },
6+
"DTrees" : { "Flags": "DTreeFlags" },
7+
"StatModel" : { "Flags": "StatModelFlags" }
8+
}
9+
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
template<>
2+
bool pyopencv_to(PyObject *obj, CvTermCriteria& dst, const ArgInfo& info)
3+
{
4+
CV_UNUSED(info);
5+
if(!obj)
6+
return true;
7+
return PyArg_ParseTuple(obj, "iid", &dst.type, &dst.max_iter, &dst.epsilon) > 0;
8+
}
9+
10+
template<>
11+
bool pyopencv_to(PyObject* obj, CvSlice& r, const ArgInfo& info)
12+
{
13+
CV_UNUSED(info);
14+
if(!obj || obj == Py_None)
15+
return true;
16+
if(PyObject_Size(obj) == 0)
17+
{
18+
r = CV_WHOLE_SEQ;
19+
return true;
20+
}
21+
return PyArg_ParseTuple(obj, "ii", &r.start_index, &r.end_index) > 0;
22+
}

0 commit comments

Comments
 (0)