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
cd981f4d
Commit
cd981f4d
authored
Apr 26, 2011
by
Maria Dimashova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
started to integrate DOT detector
parent
0a8c7d27
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
240 additions
and
0 deletions
+240
-0
objdetect.hpp
modules/objdetect/include/opencv2/objdetect/objdetect.hpp
+106
-0
dotdetector.cpp
modules/objdetect/src/dotdetector.cpp
+0
-0
dot.cpp
samples/cpp/dot.cpp
+134
-0
No files found.
modules/objdetect/include/opencv2/objdetect/objdetect.hpp
View file @
cd981f4d
...
...
@@ -426,6 +426,8 @@ protected:
Ptr
<
CvHaarClassifierCascade
>
oldCascade
;
};
void
CV_EXPORTS_W
groupRectangles
(
vector
<
Rect
>&
rectList
,
int
groupThreshold
,
double
eps
,
vector
<
int
>*
weights
,
vector
<
double
>*
levelWeights
);
//////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector //////////////
struct
CV_EXPORTS_W
HOGDescriptor
...
...
@@ -574,6 +576,110 @@ protected:
FernClassifier
fernClassifier
;
};
/****************************************************************************************\
* Dominant Orientation Templates *
\****************************************************************************************/
class
CV_EXPORTS
DOTDetector
{
public
:
struct
TrainParams
{
enum
{
BIN_COUNT
=
7
};
static
double
BIN_RANGE
()
{
return
180.0
/
BIN_COUNT
;
}
TrainParams
();
TrainParams
(
const
Size
&
winSize
,
int
regionSize
=
7
,
int
minMagnitude
=
60
,
int
maxStrongestCount
=
7
,
int
maxNonzeroBits
=
6
,
float
minRatio
=
0.85
f
);
void
read
(
FileNode
&
fn
);
void
write
(
FileStorage
&
fs
)
const
;
void
asserts
()
const
;
Size
winSize
;
int
regionSize
;
int
minMagnitude
;
int
maxStrongestCount
;
int
maxNonzeroBits
;
float
minRatio
;
};
struct
DetectParams
{
DetectParams
();
DetectParams
(
float
minRatio
,
int
minRegionSize
,
int
maxRegionSize
,
int
regionSizeStep
,
bool
isGroup
,
int
groupThreshold
,
double
groupEps
);
void
asserts
(
float
minTrainRatio
=
1.
f
)
const
;
float
minRatio
;
int
minRegionSize
;
int
maxRegionSize
;
int
regionSizeStep
;
bool
isGroup
;
int
groupThreshold
;
double
groupEps
;
};
struct
DOTTemplate
{
DOTTemplate
();
DOTTemplate
(
const
cv
::
Mat
&
quantizedImage
,
int
classID
,
const
cv
::
Mat
&
maskedImage
=
cv
::
Mat
(),
const
cv
::
Mat
&
gradientMask
=
cv
::
Mat
()
);
void
addClassID
(
int
classID
,
const
cv
::
Mat
&
maskedImage
=
cv
::
Mat
(),
const
cv
::
Mat
&
gradientMask
=
cv
::
Mat
()
);
static
float
computeTexturelessRatio
(
const
cv
::
Mat
&
quantizedImage
);
void
read
(
FileNode
&
fn
);
void
write
(
FileStorage
&
fs
)
const
;
cv
::
Mat
quantizedImage
;
std
::
vector
<
int
>
classIDs
;
float
texturelessRatio
;
std
::
vector
<
cv
::
Mat
>
maskedImages
;
std
::
vector
<
cv
::
Mat
>
gradientMasks
;
};
DOTDetector
();
DOTDetector
(
const
std
::
string
&
filename
);
// load from xml-file
virtual
~
DOTDetector
();
void
clear
();
void
read
(
FileNode
&
fn
);
void
write
(
FileStorage
&
fs
)
const
;
void
load
(
const
std
::
string
&
filename
);
void
save
(
const
std
::
string
&
filename
)
const
;
void
train
(
const
string
&
baseDirName
,
const
TrainParams
&
trainParams
=
TrainParams
(),
bool
isAddImageAndGradientMask
=
false
);
void
detectMultiScale
(
const
Mat
&
image
,
vector
<
vector
<
Rect
>
>&
rects
,
const
DetectParams
&
detectParams
=
DetectParams
(),
vector
<
vector
<
float
>
>*
ratios
=
0
,
vector
<
vector
<
int
>
>*
trainTemplateIndices
=
0
)
const
;
const
vector
<
DOTTemplate
>&
getDOTTemplates
()
const
;
const
vector
<
string
>&
getClassNames
()
const
;
static
void
groupRectanglesList
(
std
::
vector
<
std
::
vector
<
cv
::
Rect
>
>&
rectList
,
int
groupThreshold
,
double
eps
);
protected
:
void
detectQuantized
(
const
Mat
&
queryQuantizedImage
,
float
minRatio
,
vector
<
vector
<
Rect
>
>&
rects
,
vector
<
vector
<
float
>
>&
ratios
,
vector
<
vector
<
int
>
>&
trainTemlateIdxs
)
const
;
TrainParams
trainParams
;
bool
isAddImageAndGradientMask
;
std
::
vector
<
std
::
string
>
classNames
;
std
::
vector
<
DOTTemplate
>
dotTemplates
;
};
}
/****************************************************************************************\
...
...
modules/objdetect/src/dotdetector.cpp
0 → 100644
View file @
cd981f4d
This diff is collapsed.
Click to expand it.
samples/cpp/dot.cpp
0 → 100644
View file @
cd981f4d
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <iostream>
#include <fstream>
using
namespace
cv
;
using
namespace
std
;
#define SHOW_ALL_RECTS_BY_ONE 1
static
void
fillColors
(
vector
<
Scalar
>&
colors
)
{
cv
::
RNG
rng
=
theRNG
();
for
(
size_t
ci
=
0
;
ci
<
colors
.
size
();
ci
++
)
colors
[
ci
]
=
Scalar
(
rng
(
256
),
rng
(
256
),
rng
(
256
)
);
}
static
void
readTestImageNames
(
const
string
&
descrFilename
,
vector
<
string
>&
names
)
{
names
.
clear
();
ifstream
file
(
descrFilename
.
c_str
()
);
if
(
!
file
.
is_open
()
)
return
;
while
(
!
file
.
eof
()
)
{
string
str
;
getline
(
file
,
str
);
if
(
str
.
empty
()
)
break
;
if
(
str
[
0
]
==
'#'
)
continue
;
// comment
names
.
push_back
(
str
);
}
file
.
close
();
}
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
!=
1
&&
argc
!=
3
)
{
cout
<<
"Format: base; "
<<
endl
<<
"or without arguments to use default data"
<<
endl
;
return
-
1
;
}
string
baseDirName
,
testDirName
;
if
(
argc
==
1
)
{
baseDirName
=
"../MultiScaleDOT/Data/train/"
;
testDirName
=
"../MultiScaleDOT/Data/test/"
;
}
else
{
baseDirName
=
argv
[
1
];
testDirName
=
argv
[
2
];
baseDirName
+=
(
*
(
baseDirName
.
end
()
-
1
)
==
'/'
?
""
:
"/"
);
testDirName
+=
(
*
(
testDirName
.
end
()
-
1
)
==
'/'
?
""
:
"/"
);
}
DOTDetector
::
TrainParams
trainParams
;
trainParams
.
winSize
=
Size
(
84
,
84
);
trainParams
.
regionSize
=
7
;
trainParams
.
minMagnitude
=
60
;
// we ignore pixels with magnitude less then minMagnitude
trainParams
.
maxStrongestCount
=
7
;
// we find such count of strongest gradients for each region
trainParams
.
maxNonzeroBits
=
6
;
// we filter very textured regions (that have more then maxUnzeroBits count of 1s (ones) in the template)
trainParams
.
minRatio
=
0.85
f
;
// 1. Train detector
DOTDetector
dotDetector
;
dotDetector
.
train
(
baseDirName
,
trainParams
,
true
);
const
vector
<
string
>&
classNames
=
dotDetector
.
getClassNames
();
const
vector
<
DOTDetector
::
DOTTemplate
>&
dotTemplates
=
dotDetector
.
getDOTTemplates
();
vector
<
Scalar
>
colors
(
classNames
.
size
()
);
fillColors
(
colors
);
cout
<<
"Templates count "
<<
dotTemplates
.
size
()
<<
endl
;
vector
<
string
>
testFilenames
;
readTestImageNames
(
testDirName
+
"images.txt"
,
testFilenames
);
if
(
testFilenames
.
empty
()
)
{
cout
<<
"Can not read no one test images"
<<
endl
;
return
-
1
;
}
// 2. Detect objects
DOTDetector
::
DetectParams
detectParams
;
detectParams
.
minRatio
=
0.8
f
;
detectParams
.
minRegionSize
=
5
;
detectParams
.
maxRegionSize
=
11
;
#if SHOW_ALL_RECTS_BY_ONE
detectParams
.
isGroup
=
false
;
#endif
for
(
size_t
imgIdx
=
0
;
imgIdx
<
testFilenames
.
size
();
imgIdx
++
)
{
string
curFilename
=
testDirName
+
testFilenames
[
imgIdx
];
cout
<<
curFilename
<<
endl
;
Mat
queryImage
=
imread
(
curFilename
,
0
);
if
(
queryImage
.
empty
()
)
continue
;
cout
<<
"Detection start ..."
<<
endl
;
vector
<
vector
<
Rect
>
>
rects
;
vector
<
vector
<
float
>
>
ratios
;
vector
<
vector
<
int
>
>
trainTemlateIdxs
;
dotDetector
.
detectMultiScale
(
queryImage
,
rects
,
detectParams
,
&
ratios
,
&
trainTemlateIdxs
);
cout
<<
"end"
<<
endl
;
Mat
draw
;
cvtColor
(
queryImage
,
draw
,
CV_GRAY2BGR
);
#if SHOW_ALL_RECTS_BY_ONE
DOTDetector
::
groupRectanglesList
(
rects
,
3
,
0.2
);
#endif
const
int
textStep
=
25
;
for
(
size_t
ci
=
0
;
ci
<
classNames
.
size
();
ci
++
)
{
putText
(
draw
,
classNames
[
ci
],
Point
(
textStep
,
textStep
*
(
1
+
ci
)),
1
,
2
,
colors
[
ci
],
3
);
for
(
size_t
ri
=
0
;
ri
<
rects
[
ci
].
size
();
ri
++
)
{
rectangle
(
draw
,
rects
[
ci
][
ri
],
colors
[
ci
],
3
);
}
}
Mat
scaledDraw
;
cv
::
resize
(
draw
,
scaledDraw
,
Size
(
640
,
480
)
);
imshow
(
"detection result"
,
scaledDraw
);
cv
::
waitKey
();
}
}
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