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
bbdf14b9
Commit
bbdf14b9
authored
Oct 05, 2011
by
Maria Dimashova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added overlapThreshold param to sample
parent
630288fd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
8 deletions
+32
-8
latentsvm_multidetect.cpp
samples/cpp/latentsvm_multidetect.cpp
+32
-8
No files found.
samples/cpp/latentsvm_multidetect.cpp
View file @
bbdf14b9
...
@@ -23,11 +23,12 @@ using namespace cv;
...
@@ -23,11 +23,12 @@ using namespace cv;
void
help
()
void
help
()
{
{
cout
<<
"This program demonstrated the use of the latentSVM detector."
<<
endl
<<
cout
<<
"This program demonstrated the use of the latentSVM detector."
<<
endl
<<
"It reads in a trained object models and then uses them to detect the object
in an images
"
<<
endl
<<
"It reads in a trained object models and then uses them to detect the object
s in an images.
"
<<
endl
<<
endl
<<
endl
<<
"Call:"
<<
endl
<<
"Call:"
<<
endl
<<
"./latentsvm_multidetect <images_folder> <models_folder> [<threads_number>]"
<<
endl
<<
"./latentsvm_multidetect <imagesFolder> <modelsFolder> [<overlapThreshold>][<threadsNumber>]"
<<
endl
<<
"Example of models_folder is opencv_extra/testdata/cv/latentsvmdetector/models_VOC2007"
<<
endl
<<
"<overlapThreshold> - threshold for the non-maximum suppression algorithm."
<<
endl
<<
"Example of <modelsFolder> is opencv_extra/testdata/cv/latentsvmdetector/models_VOC2007"
<<
endl
<<
endl
<<
endl
<<
"Keys:"
<<
endl
<<
"Keys:"
<<
endl
<<
"'n' - to go to the next image;"
<<
endl
<<
"'n' - to go to the next image;"
<<
endl
<<
...
@@ -35,13 +36,13 @@ void help()
...
@@ -35,13 +36,13 @@ void help()
endl
;
endl
;
}
}
void
detectAndDrawObjects
(
Mat
&
image
,
LatentSvmDetector
&
detector
,
const
vector
<
Scalar
>&
colors
,
int
numThreads
)
void
detectAndDrawObjects
(
Mat
&
image
,
LatentSvmDetector
&
detector
,
const
vector
<
Scalar
>&
colors
,
float
overlapThreshold
,
int
numThreads
)
{
{
vector
<
LatentSvmDetector
::
ObjectDetection
>
detections
;
vector
<
LatentSvmDetector
::
ObjectDetection
>
detections
;
TickMeter
tm
;
TickMeter
tm
;
tm
.
start
();
tm
.
start
();
detector
.
detect
(
image
,
detections
,
0.5
f
,
numThreads
);
detector
.
detect
(
image
,
detections
,
overlapThreshold
,
numThreads
);
tm
.
stop
();
tm
.
stop
();
cout
<<
"Detection time = "
<<
tm
.
getTimeSec
()
<<
" sec"
<<
endl
;
cout
<<
"Detection time = "
<<
tm
.
getTimeSec
()
<<
" sec"
<<
endl
;
...
@@ -53,7 +54,12 @@ void detectAndDrawObjects( Mat& image, LatentSvmDetector& detector, const vector
...
@@ -53,7 +54,12 @@ void detectAndDrawObjects( Mat& image, LatentSvmDetector& detector, const vector
{
{
const
LatentSvmDetector
::
ObjectDetection
&
od
=
detections
[
i
];
const
LatentSvmDetector
::
ObjectDetection
&
od
=
detections
[
i
];
rectangle
(
image
,
od
.
rect
,
colors
[
od
.
classID
],
2
);
rectangle
(
image
,
od
.
rect
,
colors
[
od
.
classID
],
2
);
putText
(
image
,
classNames
[
od
.
classID
],
Point
(
od
.
rect
.
x
+
2
,
od
.
rect
.
y
+
9
),
FONT_HERSHEY_SIMPLEX
,
0.35
,
colors
[
od
.
classID
],
1
);
}
// put text over the all rectangles
for
(
size_t
i
=
0
;
i
<
detections
.
size
();
i
++
)
{
const
LatentSvmDetector
::
ObjectDetection
&
od
=
detections
[
i
];
putText
(
image
,
classNames
[
od
.
classID
],
Point
(
od
.
rect
.
x
+
4
,
od
.
rect
.
y
+
13
),
FONT_HERSHEY_SIMPLEX
,
0.55
,
colors
[
od
.
classID
],
2
);
}
}
}
}
...
@@ -107,12 +113,20 @@ int main(int argc, char* argv[])
...
@@ -107,12 +113,20 @@ int main(int argc, char* argv[])
help
();
help
();
string
images_folder
,
models_folder
;
string
images_folder
,
models_folder
;
float
overlapThreshold
=
0.2
;
int
numThreads
=
-
1
;
int
numThreads
=
-
1
;
if
(
argc
>
2
)
if
(
argc
>
2
)
{
{
images_folder
=
argv
[
1
];
images_folder
=
argv
[
1
];
models_folder
=
argv
[
2
];
models_folder
=
argv
[
2
];
if
(
argc
>
3
)
numThreads
=
atoi
(
argv
[
3
]);
if
(
argc
>
3
)
overlapThreshold
=
atof
(
argv
[
3
]);
if
(
overlapThreshold
<
0
||
overlapThreshold
>
1
)
{
cout
<<
"overlapThreshold must be in interval (0,1)."
<<
endl
;
exit
(
-
1
);
}
if
(
argc
>
4
)
numThreads
=
atoi
(
argv
[
4
]);
}
}
vector
<
string
>
images_filenames
,
models_filenames
;
vector
<
string
>
images_filenames
,
models_filenames
;
...
@@ -126,6 +140,16 @@ int main(int argc, char* argv[])
...
@@ -126,6 +140,16 @@ int main(int argc, char* argv[])
exit
(
-
1
);
exit
(
-
1
);
}
}
const
vector
<
string
>&
classNames
=
detector
.
getClassNames
();
cout
<<
"Loaded "
<<
classNames
.
size
()
<<
" models:"
<<
endl
;
for
(
size_t
i
=
0
;
i
<
classNames
.
size
();
i
++
)
{
cout
<<
i
<<
") "
<<
classNames
[
i
]
<<
"; "
;
}
cout
<<
endl
;
cout
<<
"overlapThreshold = "
<<
overlapThreshold
<<
endl
;
vector
<
Scalar
>
colors
(
detector
.
getClassNames
().
size
()
);
vector
<
Scalar
>
colors
(
detector
.
getClassNames
().
size
()
);
fillRngColors
(
colors
);
fillRngColors
(
colors
);
...
@@ -135,7 +159,7 @@ int main(int argc, char* argv[])
...
@@ -135,7 +159,7 @@ int main(int argc, char* argv[])
if
(
image
.
empty
()
)
continue
;
if
(
image
.
empty
()
)
continue
;
cout
<<
"Process image "
<<
images_filenames
[
i
]
<<
endl
;
cout
<<
"Process image "
<<
images_filenames
[
i
]
<<
endl
;
detectAndDrawObjects
(
image
,
detector
,
colors
,
numThreads
);
detectAndDrawObjects
(
image
,
detector
,
colors
,
overlapThreshold
,
numThreads
);
imshow
(
"result"
,
image
);
imshow
(
"result"
,
image
);
...
...
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