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
20e2dc84
Commit
20e2dc84
authored
Jul 19, 2010
by
Andrey Morozov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added implementation SetTo() with mask
parent
da1526aa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
4 deletions
+41
-4
mat_operators.cu
modules/gpu/cuda/mat_operators.cu
+40
-2
gpumat.cpp
modules/gpu/src/gpumat.cpp
+1
-2
No files found.
modules/gpu/cuda/mat_operators.cu
View file @
20e2dc84
...
@@ -57,28 +57,66 @@ namespace mat_operators
...
@@ -57,28 +57,66 @@ namespace mat_operators
mat[i] = static_cast<T>(scalar_d[i % channels]);
mat[i] = static_cast<T>(scalar_d[i % channels]);
unroll<T, channels, count - 1>::unroll_set(mat, i+1);
unroll<T, channels, count - 1>::unroll_set(mat, i+1);
}
}
__device__ static void unroll_set_with_mask(T * mat, float mask, size_t i)
{
mat[i] = mask * static_cast<T>(scalar_d[i % channels]);
unroll<T, channels, count - 1>::unroll_set_with_mask(mat, mask, i+1);
}
};
};
template <typename T, int channels>
template <typename T, int channels>
struct unroll<T,channels,0>
struct unroll<T,channels,0>
{
{
__device__ static void unroll_set(T * , size_t){}
__device__ static void unroll_set(T * , size_t){}
__device__ static void unroll_set_with_mask(T * , float, size_t){}
};
};
template <typename T, int channels>
template <typename T, int channels>
__global__ void kernel_set_to_without_mask(T * mat)
__global__ void kernel_set_to_without_mask(T * mat)
{
{
size_t i = (blockIdx.x * blockDim.x + threadIdx.x) * sizeof(T);
size_t i = (blockIdx.x * blockDim.x + threadIdx.x) * sizeof(T);
unroll<T, channels>::unroll_set(mat, i);
unroll<T, channels>::unroll_set(mat, i);
}
}
template <typename T, int channels>
__global__ void kernel_set_to_with_mask(T * mat, const float * mask)
{
size_t i = (blockIdx.x * blockDim.x + threadIdx.x) * sizeof(T);
unroll<T, channels>::unroll_set_with_mask(mat, i, mask[i]);
}
}
}
extern "C" void cv::gpu::impl::set_to_with_mask(const DevMem2D& mat, const double * scalar, const DevMem2D& mask, int depth, int channels)
extern "C" void cv::gpu::impl::set_to_with_mask(const DevMem2D& mat, const double * scalar, const DevMem2D& mask, int depth, int channels)
{
{
scalar_d[0] = scalar[0];
scalar_d[1] = scalar[1];
scalar_d[2] = scalar[2];
scalar_d[3] = scalar[3];
int numBlocks = mat.rows * mat.step / 256;
dim3 threadsPerBlock(256);
if (channels == 1)
{
if (depth == 1) ::mat_operators::kernel_set_to_with_mask<unsigned char, 1><<<numBlocks,threadsPerBlock>>>(mat.ptr, (float *)mask.ptr);
if (depth == 2) ::mat_operators::kernel_set_to_with_mask<unsigned short, 1><<<numBlocks,threadsPerBlock>>>((unsigned short *)mat.ptr, (float *)mask.ptr);
if (depth == 4) ::mat_operators::kernel_set_to_with_mask<unsigned int, 1><<<numBlocks,threadsPerBlock>>>((unsigned int *)mat.ptr, (float *)mask.ptr);
}
if (channels == 2)
{
if (depth == 1) ::mat_operators::kernel_set_to_with_mask<unsigned char, 2><<<numBlocks,threadsPerBlock>>>(mat.ptr, (float *)mask.ptr);
if (depth == 2) ::mat_operators::kernel_set_to_with_mask<unsigned short, 2><<<numBlocks,threadsPerBlock>>>((unsigned short *)mat.ptr, (float *)mask.ptr);
if (depth == 4) ::mat_operators::kernel_set_to_with_mask<unsigned int, 2><<<numBlocks,threadsPerBlock>>>((unsigned int *)mat.ptr, (float *)mask.ptr);
}
if (channels == 3)
{
if (depth == 1) ::mat_operators::kernel_set_to_with_mask<unsigned char, 3><<<numBlocks,threadsPerBlock>>>(mat.ptr, (float *)mask.ptr);
if (depth == 2) ::mat_operators::kernel_set_to_with_mask<unsigned short, 3><<<numBlocks,threadsPerBlock>>>((unsigned short *)mat.ptr, (float *)mask.ptr);
if (depth == 4) ::mat_operators::kernel_set_to_with_mask<unsigned int, 3><<<numBlocks,threadsPerBlock>>>((unsigned int *)mat.ptr, (float *)mask.ptr);
}
}
}
extern "C" void cv::gpu::impl::set_to_without_mask(const DevMem2D& mat, const double * scalar, int depth, int channels)
extern "C" void cv::gpu::impl::set_to_without_mask(const DevMem2D& mat, const double * scalar, int depth, int channels)
...
...
modules/gpu/src/gpumat.cpp
View file @
20e2dc84
...
@@ -81,14 +81,13 @@ void GpuMat::convertTo( GpuMat& /*m*/, int /*rtype*/, double /*alpha*/, double /
...
@@ -81,14 +81,13 @@ void GpuMat::convertTo( GpuMat& /*m*/, int /*rtype*/, double /*alpha*/, double /
GpuMat
&
GpuMat
::
operator
=
(
const
Scalar
&
s
)
GpuMat
&
GpuMat
::
operator
=
(
const
Scalar
&
s
)
{
{
CV_Assert
(
!
"Not implemented"
);
cv
::
gpu
::
impl
::
set_to_without_mask
(
*
this
,
s
.
val
,
this
->
depth
(),
this
->
channels
());
cv
::
gpu
::
impl
::
set_to_without_mask
(
*
this
,
s
.
val
,
this
->
depth
(),
this
->
channels
());
return
*
this
;
return
*
this
;
}
}
GpuMat
&
GpuMat
::
setTo
(
const
Scalar
&
s
,
const
GpuMat
&
mask
)
GpuMat
&
GpuMat
::
setTo
(
const
Scalar
&
s
,
const
GpuMat
&
mask
)
{
{
CV_Assert
(
!
"Not implemented"
);
CV_Assert
(
mask
.
type
()
==
CV_32F
);
CV_DbgAssert
(
!
this
->
empty
());
CV_DbgAssert
(
!
this
->
empty
());
...
...
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