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
51f7a3ca
Commit
51f7a3ca
authored
Jul 25, 2012
by
marina.kolpakova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed #2190
parent
1b7ad93d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
5 deletions
+5
-5
introduction_to_svm.cpp
...orial_code/ml/introduction_to_svm/introduction_to_svm.cpp
+5
-5
No files found.
samples/cpp/tutorial_code/ml/introduction_to_svm/introduction_to_svm.cpp
View file @
51f7a3ca
...
@@ -12,10 +12,10 @@ int main()
...
@@ -12,10 +12,10 @@ int main()
// Set up training data
// Set up training data
float
labels
[
4
]
=
{
1.0
,
-
1.0
,
-
1.0
,
-
1.0
};
float
labels
[
4
]
=
{
1.0
,
-
1.0
,
-
1.0
,
-
1.0
};
Mat
labelsMat
(
3
,
1
,
CV_32FC1
,
labels
);
Mat
labelsMat
(
4
,
1
,
CV_32FC1
,
labels
);
float
trainingData
[
4
][
2
]
=
{
{
501
,
10
},
{
255
,
10
},
{
501
,
255
},
{
10
,
501
}
};
float
trainingData
[
4
][
2
]
=
{
{
501
,
10
},
{
255
,
10
},
{
501
,
255
},
{
10
,
501
}
};
Mat
trainingDataMat
(
3
,
2
,
CV_32FC1
,
trainingData
);
Mat
trainingDataMat
(
4
,
2
,
CV_32FC1
,
trainingData
);
// Set up SVM's parameters
// Set up SVM's parameters
CvSVMParams
params
;
CvSVMParams
params
;
...
@@ -26,7 +26,7 @@ int main()
...
@@ -26,7 +26,7 @@ int main()
// Train the SVM
// Train the SVM
CvSVM
SVM
;
CvSVM
SVM
;
SVM
.
train
(
trainingDataMat
,
labelsMat
,
Mat
(),
Mat
(),
params
);
SVM
.
train
(
trainingDataMat
,
labelsMat
,
Mat
(),
Mat
(),
params
);
Vec3b
green
(
0
,
255
,
0
),
blue
(
255
,
0
,
0
);
Vec3b
green
(
0
,
255
,
0
),
blue
(
255
,
0
,
0
);
// Show the decision regions given by the SVM
// Show the decision regions given by the SVM
for
(
int
i
=
0
;
i
<
image
.
rows
;
++
i
)
for
(
int
i
=
0
;
i
<
image
.
rows
;
++
i
)
...
@@ -37,7 +37,7 @@ int main()
...
@@ -37,7 +37,7 @@ int main()
if
(
response
==
1
)
if
(
response
==
1
)
image
.
at
<
Vec3b
>
(
j
,
i
)
=
green
;
image
.
at
<
Vec3b
>
(
j
,
i
)
=
green
;
else
if
(
response
==
-
1
)
else
if
(
response
==
-
1
)
image
.
at
<
Vec3b
>
(
j
,
i
)
=
blue
;
image
.
at
<
Vec3b
>
(
j
,
i
)
=
blue
;
}
}
...
@@ -60,7 +60,7 @@ int main()
...
@@ -60,7 +60,7 @@ int main()
circle
(
image
,
Point
(
(
int
)
v
[
0
],
(
int
)
v
[
1
]),
6
,
Scalar
(
128
,
128
,
128
),
thickness
,
lineType
);
circle
(
image
,
Point
(
(
int
)
v
[
0
],
(
int
)
v
[
1
]),
6
,
Scalar
(
128
,
128
,
128
),
thickness
,
lineType
);
}
}
imwrite
(
"result.png"
,
image
);
// save the image
imwrite
(
"result.png"
,
image
);
// save the image
imshow
(
"SVM Simple Example"
,
image
);
// show it to the user
imshow
(
"SVM Simple Example"
,
image
);
// show it to the user
waitKey
(
0
);
waitKey
(
0
);
...
...
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