Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
51433a93
O
Opencv
项目概览
Greenplum
/
Opencv
大约 1 年 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
51433a93
编写于
8月 06, 2012
作者:
M
marina.kolpakova
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
C.C. Labeling: added stream support
上级
35062105
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
32 addition
and
34 deletion
+32
-34
modules/gpu/include/opencv2/gpu/gpu.hpp
modules/gpu/include/opencv2/gpu/gpu.hpp
+1
-1
modules/gpu/src/cuda/ccomponetns.cu
modules/gpu/src/cuda/ccomponetns.cu
+12
-10
modules/gpu/src/graphcuts.cpp
modules/gpu/src/graphcuts.cpp
+19
-6
modules/gpu/test/test_labeling.cpp
modules/gpu/test/test_labeling.cpp
+0
-17
未找到文件。
modules/gpu/include/opencv2/gpu/gpu.hpp
浏览文件 @
51433a93
...
...
@@ -918,7 +918,7 @@ CV_EXPORTS void graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTra
GpuMat
&
buf
,
Stream
&
stream
=
Stream
::
Null
());
//! performs connected componnents labeling.
CV_EXPORTS
void
labelComponents
(
const
GpuMat
&
image
,
GpuMat
&
mask
,
GpuMat
&
components
,
const
cv
::
Scalar
&
lo
,
const
cv
::
Scalar
&
hi
);
CV_EXPORTS
void
labelComponents
(
const
GpuMat
&
image
,
GpuMat
&
mask
,
GpuMat
&
components
,
const
cv
::
Scalar
&
lo
,
const
cv
::
Scalar
&
hi
,
Stream
&
stream
=
Stream
::
Null
()
);
////////////////////////////////// Histograms //////////////////////////////////
...
...
modules/gpu/src/cuda/ccomponetns.cu
浏览文件 @
51433a93
...
...
@@ -83,7 +83,7 @@ namespace cv { namespace gpu { namespace device
};
template
<
typename
F
>
__global__
void
computeCo
mponents
(
const
DevMem2D
image
,
DevMem2D
components
,
F
connected
)
__global__
void
computeCo
nnectivity
(
const
DevMem2D
image
,
DevMem2D
components
,
F
connected
)
{
int
x
=
threadIdx
.
x
+
blockIdx
.
x
*
blockDim
.
x
;
int
y
=
threadIdx
.
y
+
blockIdx
.
y
*
blockDim
.
y
;
...
...
@@ -108,15 +108,16 @@ namespace cv { namespace gpu { namespace device
components
(
y
,
x
)
=
c
;
}
void
computeEdges
(
const
DevMem2D
&
image
,
DevMem2D
components
,
const
int
lo
,
const
int
hi
)
void
computeEdges
(
const
DevMem2D
&
image
,
DevMem2D
edges
,
const
int
lo
,
const
int
hi
,
cudaStream_t
stream
)
{
dim3
block
(
CTA_SIZE_X
,
CTA_SIZE_Y
);
dim3
grid
(
divUp
(
image
.
cols
,
block
.
x
),
divUp
(
image
.
rows
,
block
.
y
));
InInterval
<
int
>
inInt
(
lo
,
hi
);
computeCo
mponents
<
InInterval
<
int
>
><<<
grid
,
block
>>>
(
image
,
component
s
,
inInt
);
computeCo
nnectivity
<
InInterval
<
int
>
><<<
grid
,
block
,
0
,
stream
>>>
(
image
,
edge
s
,
inInt
);
cudaSafeCall
(
cudaGetLastError
()
);
cudaSafeCall
(
cudaDeviceSynchronize
()
);
if
(
stream
==
0
)
cudaSafeCall
(
cudaDeviceSynchronize
()
);
}
__global__
void
lableTiles
(
const
DevMem2D
edges
,
DevMem2Di
comps
)
...
...
@@ -384,25 +385,25 @@ namespace cv { namespace gpu { namespace device
comps
(
y
,
x
)
=
root
(
comps
,
comps
(
y
,
x
));
}
void
labelComponents
(
const
DevMem2D
&
edges
,
DevMem2Di
comps
)
void
labelComponents
(
const
DevMem2D
&
edges
,
DevMem2Di
comps
,
cudaStream_t
stream
)
{
dim3
block
(
CTA_SIZE_X
,
CTA_SIZE_Y
);
dim3
grid
(
divUp
(
edges
.
cols
,
TILE_COLS
),
divUp
(
edges
.
rows
,
TILE_ROWS
));
lableTiles
<<<
grid
,
block
>>>
(
edges
,
comps
);
lableTiles
<<<
grid
,
block
,
0
,
stream
>>>
(
edges
,
comps
);
cudaSafeCall
(
cudaGetLastError
()
);
int
tileSizeX
=
TILE_COLS
,
tileSizeY
=
TILE_ROWS
;
cudaSafeCall
(
cudaGetLastError
()
);
cudaSafeCall
(
cudaDeviceSynchronize
()
);
//
cudaSafeCall( cudaDeviceSynchronize() );
while
(
grid
.
x
>
1
||
grid
.
y
>
1
)
{
dim3
mergeGrid
(
ceilf
(
grid
.
x
/
2.0
),
ceilf
(
grid
.
y
/
2.0
));
dim3
mergeBlock
(
STA_SIZE_MARGE_X
,
STA_SIZE_MARGE_Y
);
std
::
cout
<<
"merging: "
<<
grid
.
y
<<
" x "
<<
grid
.
x
<<
" ---> "
<<
mergeGrid
.
y
<<
" x "
<<
mergeGrid
.
x
<<
" for tiles: "
<<
tileSizeY
<<
" x "
<<
tileSizeX
<<
std
::
endl
;
crossMerge
<<<
mergeGrid
,
mergeBlock
>>>
(
2
,
2
,
tileSizeY
,
tileSizeX
,
edges
,
comps
,
ceilf
(
grid
.
y
/
2.0
)
-
grid
.
y
/
2
,
ceilf
(
grid
.
x
/
2.0
)
-
grid
.
x
/
2
);
crossMerge
<<<
mergeGrid
,
mergeBlock
,
0
,
stream
>>>
(
2
,
2
,
tileSizeY
,
tileSizeX
,
edges
,
comps
,
ceilf
(
grid
.
y
/
2.0
)
-
grid
.
y
/
2
,
ceilf
(
grid
.
x
/
2.0
)
-
grid
.
x
/
2
);
tileSizeX
<<=
1
;
tileSizeY
<<=
1
;
grid
=
mergeGrid
;
...
...
@@ -412,9 +413,10 @@ namespace cv { namespace gpu { namespace device
grid
.
x
=
divUp
(
edges
.
cols
,
block
.
x
);
grid
.
y
=
divUp
(
edges
.
rows
,
block
.
y
);
flatten
<<<
grid
,
block
>>>
(
edges
,
comps
);
flatten
<<<
grid
,
block
,
0
,
stream
>>>
(
edges
,
comps
);
cudaSafeCall
(
cudaGetLastError
()
);
cudaSafeCall
(
cudaDeviceSynchronize
()
);
if
(
stream
==
0
)
cudaSafeCall
(
cudaDeviceSynchronize
()
);
}
}
}
}
}
\ No newline at end of file
modules/gpu/src/graphcuts.cpp
浏览文件 @
51433a93
...
...
@@ -47,7 +47,7 @@
void
cv
::
gpu
::
graphcut
(
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
Stream
&
)
{
throw_nogpu
();
}
void
cv
::
gpu
::
graphcut
(
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
Stream
&
)
{
throw_nogpu
();
}
void
cv
::
gpu
::
labelComponents
(
const
GpuMat
&
image
,
GpuMat
&
mask
,
GpuMat
&
components
,
const
cv
::
Scalar
&
lo
,
const
cv
::
Scalar
&
hi
)
{
throw_nogpu
();
}
void
cv
::
gpu
::
labelComponents
(
const
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
const
cv
::
Scalar
&
,
const
cv
::
Scalar
&
,
Stream
&
)
{
throw_nogpu
();
}
#else
/* !defined (HAVE_CUDA) */
...
...
@@ -55,15 +55,28 @@ namespace cv { namespace gpu { namespace device
{
namespace
ccl
{
void
labelComponents
(
const
DevMem2D
&
edges
,
DevMem2Di
comps
);
void
computeEdges
(
const
DevMem2D
&
image
,
DevMem2D
edges
,
const
int
lo
,
const
int
hi
);
void
labelComponents
(
const
DevMem2D
&
edges
,
DevMem2Di
comps
,
cudaStream_t
stream
);
void
computeEdges
(
const
DevMem2D
&
image
,
DevMem2D
edges
,
const
int
lo
,
const
int
hi
,
cudaStream_t
stream
);
}
}}}
void
cv
::
gpu
::
labelComponents
(
const
GpuMat
&
image
,
GpuMat
&
mask
,
GpuMat
&
components
,
const
cv
::
Scalar
&
lo
,
const
cv
::
Scalar
&
hi
)
void
cv
::
gpu
::
labelComponents
(
const
GpuMat
&
image
,
GpuMat
&
mask
,
GpuMat
&
components
,
const
cv
::
Scalar
&
lo
,
const
cv
::
Scalar
&
hi
,
Stream
&
s
)
{
device
::
ccl
::
computeEdges
(
image
,
mask
,
lo
[
0
],
hi
[
0
]);
device
::
ccl
::
labelComponents
(
mask
,
components
);
CV_Assert
(
!
image
.
empty
());
int
type
=
image
.
type
();
CV_Assert
(
type
==
CV_8UC1
);
if
(
image
.
size
()
!=
mask
.
size
()
||
mask
.
type
()
!=
CV_8UC1
)
mask
.
create
(
image
.
size
(),
CV_8UC1
);
if
(
image
.
size
()
!=
components
.
size
()
||
components
.
type
()
!=
CV_32SC1
)
components
.
create
(
image
.
size
(),
CV_32SC1
);
cudaStream_t
stream
=
StreamAccessor
::
getStream
(
s
);
device
::
ccl
::
computeEdges
(
image
,
mask
,
lo
[
0
],
hi
[
0
],
stream
);
device
::
ccl
::
labelComponents
(
mask
,
components
,
stream
);
}
...
...
modules/gpu/test/test_labeling.cpp
浏览文件 @
51433a93
...
...
@@ -63,9 +63,6 @@ TEST_P(Labeling, ConnectedComponents)
{
cv
::
Mat
image
;
cvtColor
(
loat_image
(),
image
,
CV_BGR2GRAY
);
cv
::
Mat
image_cpu
=
image
.
clone
();
// cv::floodFill(image, cv::Point(1,1),cv::Scalar::all(64), 0, cv::Scalar::all(0), cv::Scalar::all(256));
cv
::
gpu
::
GpuMat
mask
;
mask
.
create
(
image
.
rows
,
image
.
cols
,
CV_8UC1
);
...
...
@@ -73,21 +70,8 @@ TEST_P(Labeling, ConnectedComponents)
cv
::
gpu
::
GpuMat
components
;
components
.
create
(
image
.
rows
,
image
.
cols
,
CV_32SC1
);
std
::
cout
<<
"summary: "
<<
image
.
cols
<<
" "
<<
image
.
rows
<<
" "
<<
cv
::
gpu
::
GpuMat
(
image
).
cols
<<
" "
<<
cv
::
gpu
::
GpuMat
(
image
).
rows
<<
" "
<<
mask
.
cols
<<
" "
<<
mask
.
rows
<<
" "
<<
components
.
cols
<<
" "
<<
components
.
rows
<<
std
::
endl
;
cv
::
gpu
::
labelComponents
(
cv
::
gpu
::
GpuMat
(
image
),
mask
,
components
,
cv
::
Scalar
::
all
(
0
),
cv
::
Scalar
::
all
(
2
));
// // for(int i = 0; i + 32 < image.rows; i += 32)
// // for(int j = 0; j + 32 < image.cols; j += 32)
// // {
// // std::cout << cv::Mat(cv::Mat(mask), cv::Rect(j, i, 32, 32 ))<< std::endl;
// // std::cout << cv::Mat(cv::Mat(components), cv::Rect(j, i, 32, 32 )) << std::endl;
// // }
// std::cout << cv::Mat(components) << std::endl;
// cv::imshow("test", image);
// cv::waitKey(0);
...
...
@@ -102,7 +86,6 @@ TEST_P(Labeling, ConnectedComponents)
cv
::
waitKey
(
0
);
cv
::
imshow
(
"test"
,
cv
::
Mat
(
components
)
*
2
);
cv
::
waitKey
(
0
);
std
::
cout
<<
"test! "
<<
image
.
cols
<<
std
::
endl
;
}
INSTANTIATE_TEST_CASE_P
(
ConnectedComponents
,
Labeling
,
ALL_DEVICES
);
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录