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
f139a0bd
Commit
f139a0bd
authored
Sep 06, 2019
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15461 from alalek:imgproc_connectedcomponents_allocation
parents
fafada28
e7b6753a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
11 deletions
+8
-11
connectedcomponents.cpp
modules/imgproc/src/connectedcomponents.cpp
+8
-11
No files found.
modules/imgproc/src/connectedcomponents.cpp
View file @
f139a0bd
...
...
@@ -2543,10 +2543,10 @@ namespace cv{
//Array used to store info and labeled pixel by each thread.
//Different threads affect different memory location of chunksSizeAndLabels
const
int
chunksSizeAndLabelsSize
=
h
+
1
;
int
*
chunksSizeAndLabels
=
(
int
*
)
cv
::
fastMalloc
(
chunksSizeAndLabelsSize
*
sizeof
(
int
)
);
cv
::
AutoBuffer
<
int
,
0
>
chunksSizeAndLabels
(
chunksSizeAndLabelsSize
);
//Tree of labels
LabelT
*
P
=
(
LabelT
*
)
cv
::
fastMalloc
(
Plength
*
sizeof
(
LabelT
)
);
cv
::
AutoBuffer
<
LabelT
,
0
>
P
(
Plength
);
//First label is for background
P
[
0
]
=
0
;
...
...
@@ -2555,30 +2555,27 @@ namespace cv{
//First scan, each thread works with chunk of img.rows/nThreads rows
//e.g. 300 rows, 4 threads -> each chunks is composed of 75 rows
cv
::
parallel_for_
(
range
,
FirstScan
(
img
,
imgLabels
,
P
,
chunksSizeAndLabels
),
nParallelStripes
);
cv
::
parallel_for_
(
range
,
FirstScan
(
img
,
imgLabels
,
P
.
data
(),
chunksSizeAndLabels
.
data
()
),
nParallelStripes
);
//merge labels of different chunks
mergeLabels
(
img
,
imgLabels
,
P
,
chunksSizeAndLabels
);
mergeLabels
(
img
,
imgLabels
,
P
.
data
(),
chunksSizeAndLabels
.
data
()
);
LabelT
nLabels
=
1
;
for
(
int
i
=
0
;
i
<
h
;
i
=
chunksSizeAndLabels
[
i
]){
CV_Assert
(
i
+
1
<
chunksSizeAndLabelsSize
);
flattenL
(
P
,
LabelT
((
i
+
1
)
/
2
)
*
LabelT
((
w
+
1
)
/
2
)
+
1
,
chunksSizeAndLabels
[
i
+
1
],
nLabels
);
flattenL
(
P
.
data
()
,
LabelT
((
i
+
1
)
/
2
)
*
LabelT
((
w
+
1
)
/
2
)
+
1
,
chunksSizeAndLabels
[
i
+
1
],
nLabels
);
}
//Array for statistics data
StatsOp
*
sopArray
=
new
StatsOp
[
h
]
;
cv
::
AutoBuffer
<
StatsOp
,
0
>
sopArray
(
h
)
;
sop
.
init
(
nLabels
);
//Second scan
cv
::
parallel_for_
(
range
,
SecondScan
(
img
,
imgLabels
,
P
,
sop
,
sopArray
,
nLabels
),
nParallelStripes
);
cv
::
parallel_for_
(
range
,
SecondScan
(
img
,
imgLabels
,
P
.
data
(),
sop
,
sopArray
.
data
()
,
nLabels
),
nParallelStripes
);
StatsOp
::
mergeStats
(
imgLabels
,
sopArray
,
sop
,
nLabels
);
StatsOp
::
mergeStats
(
imgLabels
,
sopArray
.
data
()
,
sop
,
nLabels
);
sop
.
finish
();
delete
[]
sopArray
;
cv
::
fastFree
(
chunksSizeAndLabels
);
cv
::
fastFree
(
P
);
return
nLabels
;
}
};
//End struct LabelingGranaParallel
...
...
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