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
3a53e726
Commit
3a53e726
authored
May 07, 2015
by
laurentBerger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
example BLOB_MSER and fixed bug in blobdetector
parent
171b58e2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
39 deletions
+30
-39
blobdetector.cpp
modules/features2d/src/blobdetector.cpp
+2
-2
BLOB_MSER.cpp
samples/cpp/BLOB_MSER.cpp
+28
-37
No files found.
modules/features2d/src/blobdetector.cpp
View file @
3a53e726
...
@@ -266,6 +266,8 @@ void SimpleBlobDetectorImpl::findBlobs(InputArray _image, InputArray _binaryImag
...
@@ -266,6 +266,8 @@ void SimpleBlobDetectorImpl::findBlobs(InputArray _image, InputArray _binaryImag
continue
;
continue
;
}
}
if
(
moms
.
m00
==
0.0
)
continue
;
center
.
location
=
Point2d
(
moms
.
m10
/
moms
.
m00
,
moms
.
m01
/
moms
.
m00
);
center
.
location
=
Point2d
(
moms
.
m10
/
moms
.
m00
,
moms
.
m01
/
moms
.
m00
);
if
(
params
.
filterByColor
)
if
(
params
.
filterByColor
)
...
@@ -286,8 +288,6 @@ void SimpleBlobDetectorImpl::findBlobs(InputArray _image, InputArray _binaryImag
...
@@ -286,8 +288,6 @@ void SimpleBlobDetectorImpl::findBlobs(InputArray _image, InputArray _binaryImag
center
.
radius
=
(
dists
[(
dists
.
size
()
-
1
)
/
2
]
+
dists
[
dists
.
size
()
/
2
])
/
2.
;
center
.
radius
=
(
dists
[(
dists
.
size
()
-
1
)
/
2
]
+
dists
[
dists
.
size
()
/
2
])
/
2.
;
}
}
if
(
moms
.
m00
==
0.0
)
continue
;
centers
.
push_back
(
center
);
centers
.
push_back
(
center
);
...
...
samples/cpp/BLOB_MSER.cpp
View file @
3a53e726
...
@@ -110,13 +110,12 @@ int main(int argc, char *argv[])
...
@@ -110,13 +110,12 @@ int main(int argc, char *argv[])
help
();
help
();
return
(
0
);
return
(
0
);
}
}
Mat
img
Orig
=
imread
(
fileName
[
0
],
IMREAD_UNCHANGED
),
img
;
Mat
img
=
imread
(
fileName
[
0
],
IMREAD_GRAYSCALE
)
;
if
(
img
Orig
.
rows
*
imgOri
g
.
cols
<=
0
)
if
(
img
.
rows
*
im
g
.
cols
<=
0
)
{
{
cout
<<
"Image "
<<
fileName
[
0
]
<<
" is empty or cannot be found
\n
"
;
cout
<<
"Image "
<<
fileName
[
0
]
<<
" is empty or cannot be found
\n
"
;
return
(
0
);
return
(
0
);
}
}
GaussianBlur
(
imgOrig
,
img
,
Size
(
11
,
11
),
0.1
,
0.1
);
SimpleBlobDetector
::
Params
pDefaultBLOB
;
SimpleBlobDetector
::
Params
pDefaultBLOB
;
MSERParams
pDefaultMSER
;
MSERParams
pDefaultMSER
;
...
@@ -154,15 +153,23 @@ int main(int argc, char *argv[])
...
@@ -154,15 +153,23 @@ int main(int argc, char *argv[])
for
(
int
i
=
0
;
i
<
65536
;
i
++
)
for
(
int
i
=
0
;
i
<
65536
;
i
++
)
palette
.
push_back
(
Vec3b
(
rand
(),
rand
(),
rand
()));
palette
.
push_back
(
Vec3b
(
rand
(),
rand
(),
rand
()));
help
();
help
();
typeDesc
.
push_back
(
"MSER"
);
typeDesc
.
push_back
(
"MSER"
);
pMSER
.
push_back
(
pDefaultMSER
);
pMSER
.
push_back
(
pDefaultMSER
);
pMSER
.
back
().
minArea
=
1
;
pMSER
.
back
().
delta
=
0
;
pMSER
.
back
().
maxArea
=
img
.
rows
*
img
.
cols
;
pMSER
.
back
().
minArea
=
25
;
pMSER
.
back
().
maxArea
=
80000
;
pMSER
.
back
().
maxVariation
=
0.5
;
pMSER
.
back
().
minDiversity
=
0.8
;
// variation de taille entre deux seuillages ?
pMSER
.
back
().
areaThreshold
=
200
;
pMSER
.
back
().
maxEvolution
=
1.01
;
pMSER
.
back
().
minMargin
=
0.003
;
pMSER
.
back
().
edgeBlurSize
=
5
;
typeDesc
.
push_back
(
"BLOB"
);
typeDesc
.
push_back
(
"BLOB"
);
pBLOB
.
push_back
(
pDefaultBLOB
);
pBLOB
.
push_back
(
pDefaultBLOB
);
pBLOB
.
back
().
filterByColor
=
true
;
pBLOB
.
back
().
filterByColor
=
true
;
pBLOB
.
back
().
blobColor
=
255
;
pBLOB
.
back
().
blobColor
=
0
;
// This descriptor are going to be detect and compute 4 BLOBS with 4 differents params
// This descriptor are going to be detect and compute 4 BLOBS with 4 differents params
// Param for first BLOB detector we want all
// Param for first BLOB detector we want all
typeDesc
.
push_back
(
"BLOB"
);
// see http://docs.opencv.org/trunk/d0/d7a/classcv_1_1SimpleBlobDetector.html
typeDesc
.
push_back
(
"BLOB"
);
// see http://docs.opencv.org/trunk/d0/d7a/classcv_1_1SimpleBlobDetector.html
...
@@ -211,28 +218,20 @@ int main(int argc, char *argv[])
...
@@ -211,28 +218,20 @@ int main(int argc, char *argv[])
itBLOB
++
;
itBLOB
++
;
}
}
if
(
*
itDesc
==
"MSER"
){
if
(
*
itDesc
==
"MSER"
){
b
=
MSER
::
create
(
itMSER
->
delta
,
itMSER
->
minArea
,
itMSER
->
maxArea
,
itMSER
->
maxVariation
,
itMSER
->
minDiversity
,
itMSER
->
maxEvolution
,
b
=
MSER
::
create
(
itMSER
->
delta
,
itMSER
->
minArea
,
itMSER
->
maxArea
,
itMSER
->
maxVariation
,
itMSER
->
minDiversity
,
itMSER
->
maxEvolution
,
itMSER
->
areaThreshold
,
itMSER
->
minMargin
,
itMSER
->
edgeBlurSize
);
itMSER
->
areaThreshold
,
itMSER
->
minMargin
,
itMSER
->
edgeBlurSize
);
b
.
dynamicCast
<
MSER
>
()
->
setPass2Only
(
true
);
//b = MSER::create();
}
}
try
{
try
{
// We can detect keypoint with detect method
// We can detect keypoint with detect method
vector
<
KeyPoint
>
keyImg
;
vector
<
KeyPoint
>
keyImg
;
vector
<
Rect
>
zone
;
vector
<
Rect
>
zone
;
vector
<
vector
<
Point
>>
region
;
vector
<
vector
<
Point
>>
region
;
Mat
desc
,
result
;
Mat
desc
,
result
(
img
.
rows
,
img
.
cols
,
CV_8UC3
)
;
int
nb
=
img
.
channels
();
int
nb
=
img
.
channels
();
if
(
img
.
channels
()
==
3
)
{
img
.
copyTo
(
result
);
}
else
{
vector
<
Mat
>
plan
;
plan
.
push_back
(
img
);
plan
.
push_back
(
img
);
plan
.
push_back
(
img
);
merge
(
plan
,
result
);
}
if
(
b
.
dynamicCast
<
SimpleBlobDetector
>
()
!=
NULL
)
if
(
b
.
dynamicCast
<
SimpleBlobDetector
>
()
!=
NULL
)
{
{
Ptr
<
SimpleBlobDetector
>
sbd
=
b
.
dynamicCast
<
SimpleBlobDetector
>
();
Ptr
<
SimpleBlobDetector
>
sbd
=
b
.
dynamicCast
<
SimpleBlobDetector
>
();
...
@@ -245,32 +244,24 @@ int main(int argc, char *argv[])
...
@@ -245,32 +244,24 @@ int main(int argc, char *argv[])
if
(
b
.
dynamicCast
<
MSER
>
()
!=
NULL
)
if
(
b
.
dynamicCast
<
MSER
>
()
!=
NULL
)
{
{
Ptr
<
MSER
>
sbd
=
b
.
dynamicCast
<
MSER
>
();
Ptr
<
MSER
>
sbd
=
b
.
dynamicCast
<
MSER
>
();
sbd
->
detectRegions
(
img
,
region
,
zone
);
sbd
->
detectRegions
(
img
,
region
,
zone
);
int
i
=
0
;
int
i
=
0
;
for
(
vector
<
Rect
>::
iterator
r
=
zone
.
begin
();
r
!=
zone
.
end
();
r
++
,
i
++
)
for
(
vector
<
Rect
>::
iterator
r
=
zone
.
begin
();
r
!=
zone
.
end
();
r
++
,
i
++
)
{
{
rectangle
(
result
,
*
r
,
palette
[
i
%
65536
],
2
);
// we draw a white rectangle which include all region pixels
rectangle
(
result
,
*
r
,
Vec3b
(
255
,
255
,
255
),
2
);
}
}
i
=
0
;
i
=
0
;
for
(
vector
<
vector
<
Point
>>::
iterator
itr
=
region
.
begin
();
itr
!=
region
.
end
();
itr
++
,
i
++
)
for
(
vector
<
vector
<
Point
>>::
iterator
itr
=
region
.
begin
();
itr
!=
region
.
end
();
itr
++
,
i
++
)
{
{
for
(
vector
<
Point
>::
iterator
itp
=
region
[
i
].
begin
();
itp
!=
region
[
i
].
end
();
itp
++
)
for
(
vector
<
Point
>::
iterator
itp
=
region
[
i
].
begin
();
itp
!=
region
[
i
].
end
();
itp
++
)
{
result
.
at
<
Vec3b
>
(
itp
->
y
,
itp
->
x
)
=
Vec3b
(
0
,
0
,
0
);
}
}
i
=
0
;
for
(
vector
<
vector
<
Point
>>::
iterator
itr
=
region
.
begin
();
itr
!=
region
.
end
();
itr
++
,
i
++
)
{
{
for
(
vector
<
Point
>::
iterator
itp
=
region
[
i
].
begin
();
itp
!=
region
[
i
].
end
();
itp
++
)
// all pixels belonging to region are red
{
result
.
at
<
Vec3b
>
(
itp
->
y
,
itp
->
x
)
=
Vec3b
(
0
,
0
,
128
);
result
.
at
<
Vec3b
>
(
itp
->
y
,
itp
->
x
)
=
Vec3b
(
0
,
255
,
255
);
}
}
}
}
}
}
namedWindow
(
*
itDesc
+
label
,
WINDOW_AUTOSIZE
);
namedWindow
(
*
itDesc
+
label
,
WINDOW_AUTOSIZE
);
imshow
(
*
itDesc
+
label
,
result
);
imshow
(
*
itDesc
+
label
,
result
);
imshow
(
"Original"
,
img
);
imshow
(
"Original"
,
img
);
...
...
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