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
04f70c92
Commit
04f70c92
authored
9 years ago
by
Maksim Shabunin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5449 from rokm:stereo-fixes
parents
0d297744
7452f9a5
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
11 deletions
+74
-11
calib3d.hpp
modules/calib3d/include/opencv2/calib3d.hpp
+2
-1
cudastereo.hpp
modules/cudastereo/include/opencv2/cudastereo.hpp
+9
-4
util.cu
modules/cudastereo/src/cuda/util.cu
+55
-0
util.cpp
modules/cudastereo/src/util.cpp
+8
-6
No files found.
modules/calib3d/include/opencv2/calib3d.hpp
View file @
04f70c92
...
...
@@ -1375,7 +1375,8 @@ CV_EXPORTS_W void validateDisparity( InputOutputArray disparity, InputArray cost
/** @brief Reprojects a disparity image to 3D space.
@param disparity Input single-channel 8-bit unsigned, 16-bit signed, 32-bit signed or 32-bit
floating-point disparity image.
floating-point disparity image. If 16-bit signed format is used, the values are assumed to have no
fractional bits.
@param _3dImage Output 3-channel floating-point image of the same size as disparity . Each
element of _3dImage(x,y) contains 3D coordinates of the point (x,y) computed from the disparity
map.
...
...
This diff is collapsed.
Click to expand it.
modules/cudastereo/include/opencv2/cudastereo.hpp
View file @
04f70c92
...
...
@@ -138,7 +138,8 @@ public:
@param data User-specified data cost, a matrix of msg_type type and
Size(\<image columns\>\*ndisp, \<image rows\>) size.
@param disparity Output disparity map. If disparity is empty, the output type is CV_16SC1 .
Otherwise, the type is retained.
Otherwise, the type is retained. In 16-bit signed format, the disparity values do not have
fractional bits.
@param stream Stream for the asynchronous version.
*/
virtual
void
compute
(
InputArray
data
,
OutputArray
disparity
,
Stream
&
stream
=
Stream
::
Null
())
=
0
;
...
...
@@ -295,7 +296,9 @@ CV_EXPORTS Ptr<cuda::DisparityBilateralFilter>
/** @brief Reprojects a disparity image to 3D space.
@param disp Input disparity image. CV_8U and CV_16S types are supported.
@param disp Input single-channel 8-bit unsigned, 16-bit signed, 32-bit signed or 32-bit
floating-point disparity image. If 16-bit signed format is used, the values are assumed to have no
fractional bits.
@param xyzw Output 3- or 4-channel floating-point image of the same size as disp . Each element of
xyzw(x,y) contains 3D coordinates (x,y,z) or (x,y,z,1) of the point (x,y) , computed from the
disparity map.
...
...
@@ -309,8 +312,10 @@ CV_EXPORTS void reprojectImageTo3D(InputArray disp, OutputArray xyzw, InputArray
/** @brief Colors a disparity image.
@param src_disp Source disparity image. CV_8UC1 and CV_16SC1 types are supported.
@param dst_disp Output disparity image. It has the same size as src_disp . The type is CV_8UC4
@param src_disp Input single-channel 8-bit unsigned, 16-bit signed, 32-bit signed or 32-bit
floating-point disparity image. If 16-bit signed format is used, the values are assumed to have no
fractional bits.
@param dst_disp Output disparity image. It has the same size as src_disp. The type is CV_8UC4
in BGRA format (alpha = 255).
@param ndisp Number of disparities.
@param stream Stream for the asynchronous version.
...
...
This diff is collapsed.
Click to expand it.
modules/cudastereo/src/cuda/util.cu
View file @
04f70c92
...
...
@@ -98,6 +98,10 @@ namespace cv { namespace cuda { namespace device
template void reprojectImageTo3D_gpu<uchar, float4>(const PtrStepSzb disp, PtrStepSzb xyz, const float* q, cudaStream_t stream);
template void reprojectImageTo3D_gpu<short, float3>(const PtrStepSzb disp, PtrStepSzb xyz, const float* q, cudaStream_t stream);
template void reprojectImageTo3D_gpu<short, float4>(const PtrStepSzb disp, PtrStepSzb xyz, const float* q, cudaStream_t stream);
template void reprojectImageTo3D_gpu<int, float3>(const PtrStepSzb disp, PtrStepSzb xyz, const float* q, cudaStream_t stream);
template void reprojectImageTo3D_gpu<int, float4>(const PtrStepSzb disp, PtrStepSzb xyz, const float* q, cudaStream_t stream);
template void reprojectImageTo3D_gpu<float, float3>(const PtrStepSzb disp, PtrStepSzb xyz, const float* q, cudaStream_t stream);
template void reprojectImageTo3D_gpu<float, float4>(const PtrStepSzb disp, PtrStepSzb xyz, const float* q, cudaStream_t stream);
/////////////////////////////////// drawColorDisp ///////////////////////////////////////////////
...
...
@@ -201,6 +205,29 @@ namespace cv { namespace cuda { namespace device
}
}
__global__ void drawColorDisp(int* disp, size_t disp_step, uchar* out_image, size_t out_step, int width, int height, int ndisp)
{
const int x = blockIdx.x * blockDim.x + threadIdx.x;
const int y = blockIdx.y * blockDim.y + threadIdx.y;
if(x < width && y < height)
{
uint *line = (uint*)(out_image + y * out_step);
line[x] = cvtPixel(disp[y*disp_step + x], ndisp);
}
}
__global__ void drawColorDisp(float* disp, size_t disp_step, uchar* out_image, size_t out_step, int width, int height, int ndisp)
{
const int x = blockIdx.x * blockDim.x + threadIdx.x;
const int y = blockIdx.y * blockDim.y + threadIdx.y;
if(x < width && y < height)
{
uint *line = (uint*)(out_image + y * out_step);
line[x] = cvtPixel(disp[y*disp_step + x], ndisp);
}
}
void drawColorDisp_gpu(const PtrStepSzb& src, const PtrStepSzb& dst, int ndisp, const cudaStream_t& stream)
{
...
...
@@ -229,6 +256,34 @@ namespace cv { namespace cuda { namespace device
if (stream == 0)
cudaSafeCall( cudaDeviceSynchronize() );
}
void drawColorDisp_gpu(const PtrStepSz<int>& src, const PtrStepSzb& dst, int ndisp, const cudaStream_t& stream)
{
dim3 threads(32, 8, 1);
dim3 grid(1, 1, 1);
grid.x = divUp(src.cols, threads.x);
grid.y = divUp(src.rows, threads.y);
drawColorDisp<<<grid, threads, 0, stream>>>(src.data, src.step / sizeof(int), dst.data, dst.step, src.cols, src.rows, ndisp);
cudaSafeCall( cudaGetLastError() );
if (stream == 0)
cudaSafeCall( cudaDeviceSynchronize() );
}
void drawColorDisp_gpu(const PtrStepSz<float>& src, const PtrStepSzb& dst, int ndisp, const cudaStream_t& stream)
{
dim3 threads(32, 8, 1);
dim3 grid(1, 1, 1);
grid.x = divUp(src.cols, threads.x);
grid.y = divUp(src.rows, threads.y);
drawColorDisp<<<grid, threads, 0, stream>>>(src.data, src.step / sizeof(float), dst.data, dst.step, src.cols, src.rows, ndisp);
cudaSafeCall( cudaGetLastError() );
if (stream == 0)
cudaSafeCall( cudaDeviceSynchronize() );
}
}}} // namespace cv { namespace cuda { namespace cudev
...
...
This diff is collapsed.
Click to expand it.
modules/cudastereo/src/util.cpp
View file @
04f70c92
...
...
@@ -66,16 +66,16 @@ void cv::cuda::reprojectImageTo3D(InputArray _disp, OutputArray _xyz, InputArray
using
namespace
cv
::
cuda
::
device
;
typedef
void
(
*
func_t
)(
const
PtrStepSzb
disp
,
PtrStepSzb
xyz
,
const
float
*
q
,
cudaStream_t
stream
);
static
const
func_t
funcs
[
2
][
4
]
=
static
const
func_t
funcs
[
2
][
6
]
=
{
{
reprojectImageTo3D_gpu
<
uchar
,
float3
>
,
0
,
0
,
reprojectImageTo3D_gpu
<
short
,
float3
>
},
{
reprojectImageTo3D_gpu
<
uchar
,
float4
>
,
0
,
0
,
reprojectImageTo3D_gpu
<
short
,
float4
>
}
{
reprojectImageTo3D_gpu
<
uchar
,
float3
>
,
0
,
0
,
reprojectImageTo3D_gpu
<
short
,
float3
>
,
reprojectImageTo3D_gpu
<
int
,
float3
>
,
reprojectImageTo3D_gpu
<
float
,
float3
>
},
{
reprojectImageTo3D_gpu
<
uchar
,
float4
>
,
0
,
0
,
reprojectImageTo3D_gpu
<
short
,
float4
>
,
reprojectImageTo3D_gpu
<
int
,
float4
>
,
reprojectImageTo3D_gpu
<
float
,
float4
>
}
};
GpuMat
disp
=
_disp
.
getGpuMat
();
Mat
Q
=
_Q
.
getMat
();
CV_Assert
(
disp
.
type
()
==
CV_8U
||
disp
.
type
()
==
CV_16S
);
CV_Assert
(
disp
.
type
()
==
CV_8U
||
disp
.
type
()
==
CV_16S
||
disp
.
type
()
==
CV_32S
||
disp
.
type
()
==
CV_32F
);
CV_Assert
(
Q
.
type
()
==
CV_32F
&&
Q
.
rows
==
4
&&
Q
.
cols
==
4
&&
Q
.
isContinuous
()
);
CV_Assert
(
dst_cn
==
3
||
dst_cn
==
4
);
...
...
@@ -92,6 +92,8 @@ namespace cv { namespace cuda { namespace device
{
void
drawColorDisp_gpu
(
const
PtrStepSzb
&
src
,
const
PtrStepSzb
&
dst
,
int
ndisp
,
const
cudaStream_t
&
stream
);
void
drawColorDisp_gpu
(
const
PtrStepSz
<
short
>&
src
,
const
PtrStepSzb
&
dst
,
int
ndisp
,
const
cudaStream_t
&
stream
);
void
drawColorDisp_gpu
(
const
PtrStepSz
<
int
>&
src
,
const
PtrStepSzb
&
dst
,
int
ndisp
,
const
cudaStream_t
&
stream
);
void
drawColorDisp_gpu
(
const
PtrStepSz
<
float
>&
src
,
const
PtrStepSzb
&
dst
,
int
ndisp
,
const
cudaStream_t
&
stream
);
}}}
namespace
...
...
@@ -111,11 +113,11 @@ namespace
void
cv
::
cuda
::
drawColorDisp
(
InputArray
_src
,
OutputArray
dst
,
int
ndisp
,
Stream
&
stream
)
{
typedef
void
(
*
drawColorDisp_caller_t
)(
const
GpuMat
&
src
,
OutputArray
dst
,
int
ndisp
,
const
cudaStream_t
&
stream
);
const
drawColorDisp_caller_t
drawColorDisp_callers
[]
=
{
drawColorDisp_caller
<
unsigned
char
>
,
0
,
0
,
drawColorDisp_caller
<
short
>
,
0
,
0
,
0
,
0
};
const
drawColorDisp_caller_t
drawColorDisp_callers
[]
=
{
drawColorDisp_caller
<
unsigned
char
>
,
0
,
0
,
drawColorDisp_caller
<
short
>
,
drawColorDisp_caller
<
int
>
,
drawColorDisp_caller
<
float
>
,
0
,
0
};
GpuMat
src
=
_src
.
getGpuMat
();
CV_Assert
(
src
.
type
()
==
CV_8U
||
src
.
type
()
==
CV_16S
);
CV_Assert
(
src
.
type
()
==
CV_8U
||
src
.
type
()
==
CV_16S
||
src
.
type
()
==
CV_32S
||
src
.
type
()
==
CV_32F
);
drawColorDisp_callers
[
src
.
type
()](
src
,
dst
,
ndisp
,
StreamAccessor
::
getStream
(
stream
));
}
...
...
This diff is collapsed.
Click to expand it.
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