mirror of
https://github.com/opencv/opencv.git
synced 2024-11-25 11:40:44 +08:00
fixed bug #1367 in CSBP
This commit is contained in:
parent
d2bc0065a6
commit
a22641aa9c
@ -1095,14 +1095,9 @@ public:
|
||||
|
||||
bool use_local_init_data_cost;
|
||||
private:
|
||||
GpuMat u[2], d[2], l[2], r[2];
|
||||
GpuMat disp_selected_pyr[2];
|
||||
|
||||
GpuMat data_cost;
|
||||
GpuMat data_cost_selected;
|
||||
|
||||
GpuMat messages_buffers;
|
||||
|
||||
GpuMat temp;
|
||||
|
||||
GpuMat out;
|
||||
};
|
||||
|
||||
|
@ -62,8 +62,7 @@ namespace cv { namespace gpu { namespace device
|
||||
__constant__ int cth;
|
||||
|
||||
__constant__ size_t cimg_step;
|
||||
__constant__ size_t cmsg_step1;
|
||||
__constant__ size_t cmsg_step2;
|
||||
__constant__ size_t cmsg_step;
|
||||
__constant__ size_t cdisp_step1;
|
||||
__constant__ size_t cdisp_step2;
|
||||
|
||||
@ -137,9 +136,9 @@ namespace cv { namespace gpu { namespace device
|
||||
|
||||
if (y < h && x < w)
|
||||
{
|
||||
T* selected_disparity = selected_disp_pyr + y * cmsg_step1 + x;
|
||||
T* data_cost_selected = data_cost_selected_ + y * cmsg_step1 + x;
|
||||
T* data_cost = (T*)ctemp + y * cmsg_step1 + x;
|
||||
T* selected_disparity = selected_disp_pyr + y * cmsg_step + x;
|
||||
T* data_cost_selected = data_cost_selected_ + y * cmsg_step + x;
|
||||
T* data_cost = (T*)ctemp + y * cmsg_step + x;
|
||||
|
||||
for(int i = 0; i < nr_plane; i++)
|
||||
{
|
||||
@ -171,9 +170,9 @@ namespace cv { namespace gpu { namespace device
|
||||
|
||||
if (y < h && x < w)
|
||||
{
|
||||
T* selected_disparity = selected_disp_pyr + y * cmsg_step1 + x;
|
||||
T* data_cost_selected = data_cost_selected_ + y * cmsg_step1 + x;
|
||||
T* data_cost = (T*)ctemp + y * cmsg_step1 + x;
|
||||
T* selected_disparity = selected_disp_pyr + y * cmsg_step + x;
|
||||
T* data_cost_selected = data_cost_selected_ + y * cmsg_step + x;
|
||||
T* data_cost = (T*)ctemp + y * cmsg_step + x;
|
||||
|
||||
int nr_local_minimum = 0;
|
||||
|
||||
@ -233,7 +232,7 @@ namespace cv { namespace gpu { namespace device
|
||||
int x0 = x << level;
|
||||
int xt = (x + 1) << level;
|
||||
|
||||
T* data_cost = (T*)ctemp + y * cmsg_step1 + x;
|
||||
T* data_cost = (T*)ctemp + y * cmsg_step + x;
|
||||
|
||||
for(int d = 0; d < cndisp; ++d)
|
||||
{
|
||||
@ -314,7 +313,7 @@ namespace cv { namespace gpu { namespace device
|
||||
if (winsz >= 4) if (tid < 2) vdline[tid] += vdline[tid + 2];
|
||||
if (winsz >= 2) if (tid < 1) vdline[tid] += vdline[tid + 1];
|
||||
|
||||
T* data_cost = (T*)ctemp + y_out * cmsg_step1 + x_out;
|
||||
T* data_cost = (T*)ctemp + y_out * cmsg_step + x_out;
|
||||
|
||||
if (tid == 0)
|
||||
data_cost[cdisp_step1 * d] = saturate_cast<T>(dline[0]);
|
||||
@ -375,7 +374,7 @@ namespace cv { namespace gpu { namespace device
|
||||
|
||||
size_t disp_step = msg_step * h;
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step1, &disp_step, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmsg_step1, &msg_step, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmsg_step, &msg_step, sizeof(size_t)) );
|
||||
|
||||
init_data_cost_callers[level](rows, cols, h, w, level, ndisp, channels, stream);
|
||||
cudaSafeCall( cudaGetLastError() );
|
||||
@ -424,8 +423,8 @@ namespace cv { namespace gpu { namespace device
|
||||
int x0 = x << level;
|
||||
int xt = (x + 1) << level;
|
||||
|
||||
const T* selected_disparity = selected_disp_pyr + y/2 * cmsg_step2 + x/2;
|
||||
T* data_cost = data_cost_ + y * cmsg_step1 + x;
|
||||
const T* selected_disparity = selected_disp_pyr + y/2 * cmsg_step + x/2;
|
||||
T* data_cost = data_cost_ + y * cmsg_step + x;
|
||||
|
||||
for(int d = 0; d < nr_plane; d++)
|
||||
{
|
||||
@ -462,8 +461,8 @@ namespace cv { namespace gpu { namespace device
|
||||
|
||||
int tid = threadIdx.x;
|
||||
|
||||
const T* selected_disparity = selected_disp_pyr + y_out/2 * cmsg_step2 + x_out/2;
|
||||
T* data_cost = data_cost_ + y_out * cmsg_step1 + x_out;
|
||||
const T* selected_disparity = selected_disp_pyr + y_out/2 * cmsg_step + x_out/2;
|
||||
T* data_cost = data_cost_ + y_out * cmsg_step + x_out;
|
||||
|
||||
if (d < nr_plane)
|
||||
{
|
||||
@ -558,7 +557,7 @@ namespace cv { namespace gpu { namespace device
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void compute_data_cost(const T* disp_selected_pyr, T* data_cost, size_t msg_step1, size_t msg_step2,
|
||||
void compute_data_cost(const T* disp_selected_pyr, T* data_cost, size_t msg_step,
|
||||
int rows, int cols, int h, int w, int h2, int level, int nr_plane, int channels, cudaStream_t stream)
|
||||
{
|
||||
typedef void (*ComputeDataCostCaller)(const T* disp_selected_pyr, T* data_cost, int rows, int cols,
|
||||
@ -571,13 +570,12 @@ namespace cv { namespace gpu { namespace device
|
||||
compute_data_cost_reduce_caller_<T, 64>, compute_data_cost_reduce_caller_<T, 128>, compute_data_cost_reduce_caller_<T, 256>
|
||||
};
|
||||
|
||||
size_t disp_step1 = msg_step1 * h;
|
||||
size_t disp_step2 = msg_step2 * h2;
|
||||
size_t disp_step1 = msg_step * h;
|
||||
size_t disp_step2 = msg_step * h2;
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step1, &disp_step1, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step2, &disp_step2, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmsg_step1, &msg_step1, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmsg_step2, &msg_step2, sizeof(size_t)) );
|
||||
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmsg_step, &msg_step, sizeof(size_t)) );
|
||||
|
||||
callers[level](disp_selected_pyr, data_cost, rows, cols, h, w, level, nr_plane, channels, stream);
|
||||
cudaSafeCall( cudaGetLastError() );
|
||||
|
||||
@ -585,10 +583,10 @@ namespace cv { namespace gpu { namespace device
|
||||
cudaSafeCall( cudaDeviceSynchronize() );
|
||||
}
|
||||
|
||||
template void compute_data_cost(const short* disp_selected_pyr, short* data_cost, size_t msg_step1, size_t msg_step2,
|
||||
template void compute_data_cost(const short* disp_selected_pyr, short* data_cost, size_t msg_step,
|
||||
int rows, int cols, int h, int w, int h2, int level, int nr_plane, int channels, cudaStream_t stream);
|
||||
|
||||
template void compute_data_cost(const float* disp_selected_pyr, float* data_cost, size_t msg_step1, size_t msg_step2,
|
||||
template void compute_data_cost(const float* disp_selected_pyr, float* data_cost, size_t msg_step,
|
||||
int rows, int cols, int h, int w, int h2, int level, int nr_plane, int channels, cudaStream_t stream);
|
||||
|
||||
|
||||
@ -642,15 +640,15 @@ namespace cv { namespace gpu { namespace device
|
||||
|
||||
if (y < h && x < w)
|
||||
{
|
||||
const T* u_cur = u_cur_ + ::min(h2-1, y/2 + 1) * cmsg_step2 + x/2;
|
||||
const T* d_cur = d_cur_ + ::max(0, y/2 - 1) * cmsg_step2 + x/2;
|
||||
const T* l_cur = l_cur_ + (y/2) * cmsg_step2 + ::min(w2-1, x/2 + 1);
|
||||
const T* r_cur = r_cur_ + (y/2) * cmsg_step2 + ::max(0, x/2 - 1);
|
||||
const T* u_cur = u_cur_ + ::min(h2-1, y/2 + 1) * cmsg_step + x/2;
|
||||
const T* d_cur = d_cur_ + ::max(0, y/2 - 1) * cmsg_step + x/2;
|
||||
const T* l_cur = l_cur_ + (y/2) * cmsg_step + ::min(w2-1, x/2 + 1);
|
||||
const T* r_cur = r_cur_ + (y/2) * cmsg_step + ::max(0, x/2 - 1);
|
||||
|
||||
T* data_cost_new = (T*)ctemp + y * cmsg_step1 + x;
|
||||
T* data_cost_new = (T*)ctemp + y * cmsg_step + x;
|
||||
|
||||
const T* disparity_selected_cur = selected_disp_pyr_cur + y/2 * cmsg_step2 + x/2;
|
||||
const T* data_cost = data_cost_ + y * cmsg_step1 + x;
|
||||
const T* disparity_selected_cur = selected_disp_pyr_cur + y/2 * cmsg_step + x/2;
|
||||
const T* data_cost = data_cost_ + y * cmsg_step + x;
|
||||
|
||||
for(int d = 0; d < nr_plane2; d++)
|
||||
{
|
||||
@ -660,18 +658,18 @@ namespace cv { namespace gpu { namespace device
|
||||
data_cost_new[d * cdisp_step1] = val;
|
||||
}
|
||||
|
||||
T* data_cost_selected = data_cost_selected_ + y * cmsg_step1 + x;
|
||||
T* disparity_selected_new = selected_disp_pyr_new + y * cmsg_step1 + x;
|
||||
T* data_cost_selected = data_cost_selected_ + y * cmsg_step + x;
|
||||
T* disparity_selected_new = selected_disp_pyr_new + y * cmsg_step + x;
|
||||
|
||||
T* u_new = u_new_ + y * cmsg_step1 + x;
|
||||
T* d_new = d_new_ + y * cmsg_step1 + x;
|
||||
T* l_new = l_new_ + y * cmsg_step1 + x;
|
||||
T* r_new = r_new_ + y * cmsg_step1 + x;
|
||||
T* u_new = u_new_ + y * cmsg_step + x;
|
||||
T* d_new = d_new_ + y * cmsg_step + x;
|
||||
T* l_new = l_new_ + y * cmsg_step + x;
|
||||
T* r_new = r_new_ + y * cmsg_step + x;
|
||||
|
||||
u_cur = u_cur_ + y/2 * cmsg_step2 + x/2;
|
||||
d_cur = d_cur_ + y/2 * cmsg_step2 + x/2;
|
||||
l_cur = l_cur_ + y/2 * cmsg_step2 + x/2;
|
||||
r_cur = r_cur_ + y/2 * cmsg_step2 + x/2;
|
||||
u_cur = u_cur_ + y/2 * cmsg_step + x/2;
|
||||
d_cur = d_cur_ + y/2 * cmsg_step + x/2;
|
||||
l_cur = l_cur_ + y/2 * cmsg_step + x/2;
|
||||
r_cur = r_cur_ + y/2 * cmsg_step + x/2;
|
||||
|
||||
get_first_k_element_increase(u_new, d_new, l_new, r_new, u_cur, d_cur, l_cur, r_cur,
|
||||
data_cost_selected, disparity_selected_new, data_cost_new,
|
||||
@ -684,17 +682,16 @@ namespace cv { namespace gpu { namespace device
|
||||
void init_message(T* u_new, T* d_new, T* l_new, T* r_new,
|
||||
const T* u_cur, const T* d_cur, const T* l_cur, const T* r_cur,
|
||||
T* selected_disp_pyr_new, const T* selected_disp_pyr_cur,
|
||||
T* data_cost_selected, const T* data_cost, size_t msg_step1, size_t msg_step2,
|
||||
T* data_cost_selected, const T* data_cost, size_t msg_step,
|
||||
int h, int w, int nr_plane, int h2, int w2, int nr_plane2, cudaStream_t stream)
|
||||
{
|
||||
|
||||
size_t disp_step1 = msg_step1 * h;
|
||||
size_t disp_step2 = msg_step2 * h2;
|
||||
size_t disp_step1 = msg_step * h;
|
||||
size_t disp_step2 = msg_step * h2;
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step1, &disp_step1, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step2, &disp_step2, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmsg_step1, &msg_step1, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmsg_step2, &msg_step2, sizeof(size_t)) );
|
||||
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmsg_step, &msg_step, sizeof(size_t)) );
|
||||
|
||||
dim3 threads(32, 8, 1);
|
||||
dim3 grid(1, 1, 1);
|
||||
|
||||
@ -716,13 +713,13 @@ namespace cv { namespace gpu { namespace device
|
||||
template void init_message(short* u_new, short* d_new, short* l_new, short* r_new,
|
||||
const short* u_cur, const short* d_cur, const short* l_cur, const short* r_cur,
|
||||
short* selected_disp_pyr_new, const short* selected_disp_pyr_cur,
|
||||
short* data_cost_selected, const short* data_cost, size_t msg_step1, size_t msg_step2,
|
||||
short* data_cost_selected, const short* data_cost, size_t msg_step,
|
||||
int h, int w, int nr_plane, int h2, int w2, int nr_plane2, cudaStream_t stream);
|
||||
|
||||
template void init_message(float* u_new, float* d_new, float* l_new, float* r_new,
|
||||
const float* u_cur, const float* d_cur, const float* l_cur, const float* r_cur,
|
||||
float* selected_disp_pyr_new, const float* selected_disp_pyr_cur,
|
||||
float* data_cost_selected, const float* data_cost, size_t msg_step1, size_t msg_step2,
|
||||
float* data_cost_selected, const float* data_cost, size_t msg_step,
|
||||
int h, int w, int nr_plane, int h2, int w2, int nr_plane2, cudaStream_t stream);
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
@ -772,21 +769,21 @@ namespace cv { namespace gpu { namespace device
|
||||
|
||||
if (y > 0 && y < h - 1 && x > 0 && x < w - 1)
|
||||
{
|
||||
const T* data = data_cost_selected + y * cmsg_step1 + x;
|
||||
const T* data = data_cost_selected + y * cmsg_step + x;
|
||||
|
||||
T* u = u_ + y * cmsg_step1 + x;
|
||||
T* d = d_ + y * cmsg_step1 + x;
|
||||
T* l = l_ + y * cmsg_step1 + x;
|
||||
T* r = r_ + y * cmsg_step1 + x;
|
||||
T* u = u_ + y * cmsg_step + x;
|
||||
T* d = d_ + y * cmsg_step + x;
|
||||
T* l = l_ + y * cmsg_step + x;
|
||||
T* r = r_ + y * cmsg_step + x;
|
||||
|
||||
const T* disp = selected_disp_pyr_cur + y * cmsg_step1 + x;
|
||||
const T* disp = selected_disp_pyr_cur + y * cmsg_step + x;
|
||||
|
||||
T* temp = (T*)ctemp + y * cmsg_step1 + x;
|
||||
T* temp = (T*)ctemp + y * cmsg_step + x;
|
||||
|
||||
message_per_pixel(data, u, r - 1, u + cmsg_step1, l + 1, disp, disp - cmsg_step1, nr_plane, temp);
|
||||
message_per_pixel(data, d, d - cmsg_step1, r - 1, l + 1, disp, disp + cmsg_step1, nr_plane, temp);
|
||||
message_per_pixel(data, l, u + cmsg_step1, d - cmsg_step1, l + 1, disp, disp - 1, nr_plane, temp);
|
||||
message_per_pixel(data, r, u + cmsg_step1, d - cmsg_step1, r - 1, disp, disp + 1, nr_plane, temp);
|
||||
message_per_pixel(data, u, r - 1, u + cmsg_step, l + 1, disp, disp - cmsg_step, nr_plane, temp);
|
||||
message_per_pixel(data, d, d - cmsg_step, r - 1, l + 1, disp, disp + cmsg_step, nr_plane, temp);
|
||||
message_per_pixel(data, l, u + cmsg_step, d - cmsg_step, l + 1, disp, disp - 1, nr_plane, temp);
|
||||
message_per_pixel(data, r, u + cmsg_step, d - cmsg_step, r - 1, disp, disp + 1, nr_plane, temp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -797,7 +794,7 @@ namespace cv { namespace gpu { namespace device
|
||||
{
|
||||
size_t disp_step = msg_step * h;
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step1, &disp_step, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmsg_step1, &msg_step, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmsg_step, &msg_step, sizeof(size_t)) );
|
||||
|
||||
dim3 threads(32, 8, 1);
|
||||
dim3 grid(1, 1, 1);
|
||||
@ -836,13 +833,13 @@ namespace cv { namespace gpu { namespace device
|
||||
|
||||
if (y > 0 && y < disp.rows - 1 && x > 0 && x < disp.cols - 1)
|
||||
{
|
||||
const T* data = data_cost_selected + y * cmsg_step1 + x;
|
||||
const T* disp_selected = disp_selected_pyr + y * cmsg_step1 + x;
|
||||
const T* data = data_cost_selected + y * cmsg_step + x;
|
||||
const T* disp_selected = disp_selected_pyr + y * cmsg_step + x;
|
||||
|
||||
const T* u = u_ + (y+1) * cmsg_step1 + (x+0);
|
||||
const T* d = d_ + (y-1) * cmsg_step1 + (x+0);
|
||||
const T* l = l_ + (y+0) * cmsg_step1 + (x+1);
|
||||
const T* r = r_ + (y+0) * cmsg_step1 + (x-1);
|
||||
const T* u = u_ + (y+1) * cmsg_step + (x+0);
|
||||
const T* d = d_ + (y-1) * cmsg_step + (x+0);
|
||||
const T* l = l_ + (y+0) * cmsg_step + (x+1);
|
||||
const T* r = r_ + (y+0) * cmsg_step + (x-1);
|
||||
|
||||
int best = 0;
|
||||
T best_val = numeric_limits<T>::max();
|
||||
@ -867,7 +864,7 @@ namespace cv { namespace gpu { namespace device
|
||||
{
|
||||
size_t disp_step = disp.rows * msg_step;
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step1, &disp_step, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmsg_step1, &msg_step, sizeof(size_t)) );
|
||||
cudaSafeCall( cudaMemcpyToSymbol(cmsg_step, &msg_step, sizeof(size_t)) );
|
||||
|
||||
dim3 threads(32, 8, 1);
|
||||
dim3 grid(1, 1, 1);
|
||||
|
@ -69,14 +69,14 @@ namespace cv { namespace gpu { namespace device
|
||||
int h, int w, int level, int nr_plane, int ndisp, int channels, bool use_local_init_data_cost, cudaStream_t stream);
|
||||
|
||||
template<class T>
|
||||
void compute_data_cost(const T* disp_selected_pyr, T* data_cost, size_t msg_step1, size_t msg_step2,
|
||||
void compute_data_cost(const T* disp_selected_pyr, T* data_cost, size_t msg_step,
|
||||
int rows, int cols, int h, int w, int h2, int level, int nr_plane, int channels, cudaStream_t stream);
|
||||
|
||||
template<class T>
|
||||
void init_message(T* u_new, T* d_new, T* l_new, T* r_new,
|
||||
const T* u_cur, const T* d_cur, const T* l_cur, const T* r_cur,
|
||||
T* selected_disp_pyr_new, const T* selected_disp_pyr_cur,
|
||||
T* data_cost_selected, const T* data_cost, size_t msg_step1, size_t msg_step2,
|
||||
T* data_cost_selected, const T* data_cost, size_t msg_step,
|
||||
int h, int w, int nr_plane, int h2, int w2, int nr_plane2, cudaStream_t stream);
|
||||
|
||||
template<class T>
|
||||
@ -137,9 +137,7 @@ cv::gpu::StereoConstantSpaceBP::StereoConstantSpaceBP(int ndisp_, int iters_, in
|
||||
}
|
||||
|
||||
template<class T>
|
||||
static void csbp_operator(StereoConstantSpaceBP& rthis, GpuMat u[2], GpuMat d[2], GpuMat l[2], GpuMat r[2],
|
||||
GpuMat disp_selected_pyr[2], GpuMat& data_cost, GpuMat& data_cost_selected,
|
||||
GpuMat& temp, GpuMat& out, const GpuMat& left, const GpuMat& right, GpuMat& disp, Stream& stream)
|
||||
static void csbp_operator(StereoConstantSpaceBP& rthis, GpuMat& mbuf, GpuMat& temp, GpuMat& out, const GpuMat& left, const GpuMat& right, GpuMat& disp, Stream& stream)
|
||||
{
|
||||
CV_DbgAssert(0 < rthis.ndisp && 0 < rthis.iters && 0 < rthis.levels && 0 < rthis.nr_plane
|
||||
&& left.rows == right.rows && left.cols == right.cols && left.type() == right.type());
|
||||
@ -153,60 +151,61 @@ static void csbp_operator(StereoConstantSpaceBP& rthis, GpuMat u[2], GpuMat d[2]
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Init
|
||||
|
||||
int rows = left.rows;
|
||||
int rows = left.rows;
|
||||
int cols = left.cols;
|
||||
|
||||
rthis.levels = min(rthis.levels, int(log((double)rthis.ndisp) / log(2.0)));
|
||||
rthis.levels = min(rthis.levels, int(log((double)rthis.ndisp) / log(2.0)));
|
||||
int levels = rthis.levels;
|
||||
|
||||
AutoBuffer<int> buf(levels * 4);
|
||||
|
||||
|
||||
// compute sizes
|
||||
AutoBuffer<int> buf(levels * 3);
|
||||
int* cols_pyr = buf;
|
||||
int* rows_pyr = cols_pyr + levels;
|
||||
int* nr_plane_pyr = rows_pyr + levels;
|
||||
int* step_pyr = nr_plane_pyr + levels;
|
||||
|
||||
cols_pyr[0] = cols;
|
||||
rows_pyr[0] = rows;
|
||||
|
||||
cols_pyr[0] = cols;
|
||||
rows_pyr[0] = rows;
|
||||
nr_plane_pyr[0] = rthis.nr_plane;
|
||||
|
||||
const int n = 64;
|
||||
step_pyr[0] = static_cast<int>(alignSize(cols * sizeof(T), n) / sizeof(T));
|
||||
|
||||
for (int i = 1; i < levels; i++)
|
||||
{
|
||||
cols_pyr[i] = (cols_pyr[i-1] + 1) / 2;
|
||||
rows_pyr[i] = (rows_pyr[i-1] + 1) / 2;
|
||||
cols_pyr[i] = cols_pyr[i-1] / 2;
|
||||
rows_pyr[i] = rows_pyr[i-1] / 2;
|
||||
nr_plane_pyr[i] = nr_plane_pyr[i-1] * 2;
|
||||
}
|
||||
|
||||
nr_plane_pyr[i] = nr_plane_pyr[i-1] * 2;
|
||||
|
||||
step_pyr[i] = static_cast<int>(alignSize(cols_pyr[i] * sizeof(T), n) / sizeof(T));
|
||||
}
|
||||
GpuMat u[2], d[2], l[2], r[2], disp_selected_pyr[2], data_cost, data_cost_selected;
|
||||
|
||||
Size msg_size(step_pyr[0], rows * nr_plane_pyr[0]);
|
||||
Size data_cost_size(step_pyr[0], rows * nr_plane_pyr[0] * 2);
|
||||
|
||||
u[0].create(msg_size, DataType<T>::type);
|
||||
d[0].create(msg_size, DataType<T>::type);
|
||||
l[0].create(msg_size, DataType<T>::type);
|
||||
r[0].create(msg_size, DataType<T>::type);
|
||||
//allocate buffers
|
||||
int buffers_count = 10; // (up + down + left + right + disp_selected_pyr) * 2
|
||||
buffers_count += 2; // data_cost has twice more rows than other buffers, what's why +2, not +1;
|
||||
buffers_count += 1; // data_cost_selected
|
||||
mbuf.create(rows * rthis.nr_plane * buffers_count, cols, DataType<T>::type);
|
||||
|
||||
data_cost = mbuf.rowRange(0, rows * rthis.nr_plane * 2);
|
||||
data_cost_selected = mbuf.rowRange(data_cost.rows, data_cost.rows + rows * rthis.nr_plane);
|
||||
|
||||
for(int k = 0; k < 2; ++k) // in/out
|
||||
{
|
||||
GpuMat sub1 = mbuf.rowRange(data_cost.rows + data_cost_selected.rows, mbuf.rows);
|
||||
GpuMat sub2 = sub1.rowRange((k+0)*sub1.rows/2, (k+1)*sub1.rows/2);
|
||||
|
||||
u[1].create(msg_size, DataType<T>::type);
|
||||
d[1].create(msg_size, DataType<T>::type);
|
||||
l[1].create(msg_size, DataType<T>::type);
|
||||
r[1].create(msg_size, DataType<T>::type);
|
||||
|
||||
disp_selected_pyr[0].create(msg_size, DataType<T>::type);
|
||||
disp_selected_pyr[1].create(msg_size, DataType<T>::type);
|
||||
|
||||
data_cost.create(data_cost_size, DataType<T>::type);
|
||||
data_cost_selected.create(msg_size, DataType<T>::type);
|
||||
|
||||
step_pyr[0] = static_cast<int>(data_cost.step / sizeof(T));
|
||||
|
||||
Size temp_size = data_cost_size;
|
||||
if (data_cost_size.width * data_cost_size.height < step_pyr[levels - 1] * rows_pyr[levels - 1] * rthis.ndisp)
|
||||
temp_size = Size(step_pyr[levels - 1], rows_pyr[levels - 1] * rthis.ndisp);
|
||||
GpuMat *buf_ptrs[] = { &u[k], &d[k], &l[k], &r[k], &disp_selected_pyr[k] };
|
||||
for(int r = 0; r < 5; ++r)
|
||||
{
|
||||
*buf_ptrs[r] = sub2.rowRange(r * sub2.rows/5, (r+1) * sub2.rows/5);
|
||||
assert(buf_ptrs[r]->cols == cols && buf_ptrs[r]->rows == rows * rthis.nr_plane);
|
||||
}
|
||||
};
|
||||
|
||||
size_t elem_step = mbuf.step / sizeof(T);
|
||||
|
||||
Size temp_size = data_cost.size();
|
||||
if ((size_t)temp_size.area() < elem_step * rows_pyr[levels - 1] * rthis.ndisp)
|
||||
temp_size = Size(elem_step, rows_pyr[levels - 1] * rthis.ndisp);
|
||||
|
||||
temp.create(temp_size, DataType<T>::type);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
@ -252,11 +251,11 @@ static void csbp_operator(StereoConstantSpaceBP& rthis, GpuMat u[2], GpuMat d[2]
|
||||
if (i == levels - 1)
|
||||
{
|
||||
init_data_cost(left.rows, left.cols, disp_selected_pyr[cur_idx].ptr<T>(), data_cost_selected.ptr<T>(),
|
||||
step_pyr[i], rows_pyr[i], cols_pyr[i], i, nr_plane_pyr[i], rthis.ndisp, left.channels(), rthis.use_local_init_data_cost, cudaStream);
|
||||
elem_step, rows_pyr[i], cols_pyr[i], i, nr_plane_pyr[i], rthis.ndisp, left.channels(), rthis.use_local_init_data_cost, cudaStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
compute_data_cost(disp_selected_pyr[cur_idx].ptr<T>(), data_cost.ptr<T>(), step_pyr[i], step_pyr[i+1],
|
||||
compute_data_cost(disp_selected_pyr[cur_idx].ptr<T>(), data_cost.ptr<T>(), elem_step,
|
||||
left.rows, left.cols, rows_pyr[i], cols_pyr[i], rows_pyr[i+1], i, nr_plane_pyr[i+1], left.channels(), cudaStream);
|
||||
|
||||
int new_idx = (cur_idx + 1) & 1;
|
||||
@ -264,14 +263,14 @@ static void csbp_operator(StereoConstantSpaceBP& rthis, GpuMat u[2], GpuMat d[2]
|
||||
init_message(u[new_idx].ptr<T>(), d[new_idx].ptr<T>(), l[new_idx].ptr<T>(), r[new_idx].ptr<T>(),
|
||||
u[cur_idx].ptr<T>(), d[cur_idx].ptr<T>(), l[cur_idx].ptr<T>(), r[cur_idx].ptr<T>(),
|
||||
disp_selected_pyr[new_idx].ptr<T>(), disp_selected_pyr[cur_idx].ptr<T>(),
|
||||
data_cost_selected.ptr<T>(), data_cost.ptr<T>(), step_pyr[i], step_pyr[i+1], rows_pyr[i],
|
||||
data_cost_selected.ptr<T>(), data_cost.ptr<T>(), elem_step, rows_pyr[i],
|
||||
cols_pyr[i], nr_plane_pyr[i], rows_pyr[i+1], cols_pyr[i+1], nr_plane_pyr[i+1], cudaStream);
|
||||
|
||||
cur_idx = new_idx;
|
||||
}
|
||||
|
||||
calc_all_iterations(u[cur_idx].ptr<T>(), d[cur_idx].ptr<T>(), l[cur_idx].ptr<T>(), r[cur_idx].ptr<T>(),
|
||||
data_cost_selected.ptr<T>(), disp_selected_pyr[cur_idx].ptr<T>(), step_pyr[i],
|
||||
data_cost_selected.ptr<T>(), disp_selected_pyr[cur_idx].ptr<T>(), elem_step,
|
||||
rows_pyr[i], cols_pyr[i], nr_plane_pyr[i], rthis.iters, cudaStream);
|
||||
}
|
||||
|
||||
@ -286,7 +285,7 @@ static void csbp_operator(StereoConstantSpaceBP& rthis, GpuMat u[2], GpuMat d[2]
|
||||
out.setTo(zero);
|
||||
|
||||
compute_disp(u[cur_idx].ptr<T>(), d[cur_idx].ptr<T>(), l[cur_idx].ptr<T>(), r[cur_idx].ptr<T>(),
|
||||
data_cost_selected.ptr<T>(), disp_selected_pyr[cur_idx].ptr<T>(), step_pyr[0], out, nr_plane_pyr[0], cudaStream);
|
||||
data_cost_selected.ptr<T>(), disp_selected_pyr[cur_idx].ptr<T>(), elem_step, out, nr_plane_pyr[0], cudaStream);
|
||||
|
||||
if (disp.type() != CV_16S)
|
||||
{
|
||||
@ -298,8 +297,7 @@ static void csbp_operator(StereoConstantSpaceBP& rthis, GpuMat u[2], GpuMat d[2]
|
||||
}
|
||||
|
||||
|
||||
typedef void (*csbp_operator_t)(StereoConstantSpaceBP& rthis, GpuMat u[2], GpuMat d[2], GpuMat l[2], GpuMat r[2],
|
||||
GpuMat disp_selected_pyr[2], GpuMat& data_cost, GpuMat& data_cost_selected,
|
||||
typedef void (*csbp_operator_t)(StereoConstantSpaceBP& rthis, GpuMat& mbuf,
|
||||
GpuMat& temp, GpuMat& out, const GpuMat& left, const GpuMat& right, GpuMat& disp, Stream& stream);
|
||||
|
||||
const static csbp_operator_t operators[] = {0, 0, 0, csbp_operator<short>, 0, csbp_operator<float>, 0, 0};
|
||||
@ -307,7 +305,7 @@ const static csbp_operator_t operators[] = {0, 0, 0, csbp_operator<short>, 0, cs
|
||||
void cv::gpu::StereoConstantSpaceBP::operator()(const GpuMat& left, const GpuMat& right, GpuMat& disp, Stream& stream)
|
||||
{
|
||||
CV_Assert(msg_type == CV_32F || msg_type == CV_16S);
|
||||
operators[msg_type](*this, u, d, l, r, disp_selected_pyr, data_cost, data_cost_selected, temp, out, left, right, disp, stream);
|
||||
operators[msg_type](*this, messages_buffers, temp, out, left, right, disp, stream);
|
||||
}
|
||||
|
||||
#endif /* !defined (HAVE_CUDA) */
|
||||
|
@ -85,7 +85,7 @@ template <typename T> struct CubicInterpolator
|
||||
{
|
||||
static float getValue(float p[4], float x)
|
||||
{
|
||||
return p[1] + 0.5 * x * (p[2] - p[0] + x*(2.0*p[0] - 5.0*p[1] + 4.0*p[2] - p[3] + x*(3.0*(p[1] - p[2]) + p[3] - p[0])));
|
||||
return static_cast<float>(p[1] + 0.5 * x * (p[2] - p[0] + x*(2.0*p[0] - 5.0*p[1] + 4.0*p[2] - p[3] + x*(3.0*(p[1] - p[2]) + p[3] - p[0]))));
|
||||
}
|
||||
|
||||
static float getValue(float p[4][4], float x, float y)
|
||||
@ -107,13 +107,13 @@ template <typename T> struct CubicInterpolator
|
||||
|
||||
float vals[4][4] =
|
||||
{
|
||||
{readVal<T>(src, iy - 2, ix - 2, c, border_type, borderVal), readVal<T>(src, iy - 2, ix - 1, c, border_type, borderVal), readVal<T>(src, iy - 2, ix, c, border_type, borderVal), readVal<T>(src, iy - 2, ix + 1, c, border_type, borderVal)},
|
||||
{readVal<T>(src, iy - 1, ix - 2, c, border_type, borderVal), readVal<T>(src, iy - 1, ix - 1, c, border_type, borderVal), readVal<T>(src, iy - 1, ix, c, border_type, borderVal), readVal<T>(src, iy - 1, ix + 1, c, border_type, borderVal)},
|
||||
{readVal<T>(src, iy , ix - 2, c, border_type, borderVal), readVal<T>(src, iy , ix - 1, c, border_type, borderVal), readVal<T>(src, iy , ix, c, border_type, borderVal), readVal<T>(src, iy , ix + 1, c, border_type, borderVal)},
|
||||
{readVal<T>(src, iy + 1, ix - 2, c, border_type, borderVal), readVal<T>(src, iy + 1, ix - 1, c, border_type, borderVal), readVal<T>(src, iy + 1, ix, c, border_type, borderVal), readVal<T>(src, iy + 1, ix + 1, c, border_type, borderVal)},
|
||||
{(float)readVal<T>(src, iy - 2, ix - 2, c, border_type, borderVal), (float)readVal<T>(src, iy - 2, ix - 1, c, border_type, borderVal), (float)readVal<T>(src, iy - 2, ix, c, border_type, borderVal), (float)readVal<T>(src, iy - 2, ix + 1, c, border_type, borderVal)},
|
||||
{(float)readVal<T>(src, iy - 1, ix - 2, c, border_type, borderVal), (float)readVal<T>(src, iy - 1, ix - 1, c, border_type, borderVal), (float)readVal<T>(src, iy - 1, ix, c, border_type, borderVal), (float)readVal<T>(src, iy - 1, ix + 1, c, border_type, borderVal)},
|
||||
{(float)readVal<T>(src, iy , ix - 2, c, border_type, borderVal), (float)readVal<T>(src, iy , ix - 1, c, border_type, borderVal), (float)readVal<T>(src, iy , ix, c, border_type, borderVal), (float)readVal<T>(src, iy , ix + 1, c, border_type, borderVal)},
|
||||
{(float)readVal<T>(src, iy + 1, ix - 2, c, border_type, borderVal), (float)readVal<T>(src, iy + 1, ix - 1, c, border_type, borderVal), (float)readVal<T>(src, iy + 1, ix, c, border_type, borderVal), (float)readVal<T>(src, iy + 1, ix + 1, c, border_type, borderVal)},
|
||||
};
|
||||
|
||||
return cv::saturate_cast<T>(getValue(vals, (x - ix + 2.0) / 4.0, (y - iy + 2.0) / 4.0));
|
||||
return cv::saturate_cast<T>(getValue(vals, static_cast<float>((x - ix + 2.0) / 4.0), static_cast<float>((y - iy + 2.0) / 4.0)));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -299,43 +299,43 @@ TEST_P(SolvePnPRansac, Accuracy)
|
||||
ASSERT_LE(cv::norm(tvec - tvec_gold), 1e-3);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Calib3D, SolvePnPRansac, ALL_DEVICES);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// reprojectImageTo3D
|
||||
|
||||
PARAM_TEST_CASE(ReprojectImageTo3D, cv::gpu::DeviceInfo, cv::Size, MatDepth, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int depth;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
depth = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReprojectImageTo3D, Accuracy)
|
||||
{
|
||||
cv::Mat disp = randomMat(size, depth, 5.0, 30.0);
|
||||
cv::Mat Q = randomMat(cv::Size(4, 4), CV_32FC1, 0.1, 1.0);
|
||||
|
||||
cv::gpu::GpuMat dst;
|
||||
cv::gpu::reprojectImageTo3D(loadMat(disp, useRoi), dst, Q, 3);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::reprojectImageTo3D(disp, dst_gold, Q, false);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 1e-5);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Calib3D, SolvePnPRansac, ALL_DEVICES);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// reprojectImageTo3D
|
||||
|
||||
PARAM_TEST_CASE(ReprojectImageTo3D, cv::gpu::DeviceInfo, cv::Size, MatDepth, UseRoi)
|
||||
{
|
||||
cv::gpu::DeviceInfo devInfo;
|
||||
cv::Size size;
|
||||
int depth;
|
||||
bool useRoi;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
devInfo = GET_PARAM(0);
|
||||
size = GET_PARAM(1);
|
||||
depth = GET_PARAM(2);
|
||||
useRoi = GET_PARAM(3);
|
||||
|
||||
cv::gpu::setDevice(devInfo.deviceID());
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(ReprojectImageTo3D, Accuracy)
|
||||
{
|
||||
cv::Mat disp = randomMat(size, depth, 5.0, 30.0);
|
||||
cv::Mat Q = randomMat(cv::Size(4, 4), CV_32FC1, 0.1, 1.0);
|
||||
|
||||
cv::gpu::GpuMat dst;
|
||||
cv::gpu::reprojectImageTo3D(loadMat(disp, useRoi), dst, Q, 3);
|
||||
|
||||
cv::Mat dst_gold;
|
||||
cv::reprojectImageTo3D(disp, dst_gold, Q, false);
|
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, dst, 1e-5);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_Calib3D, ReprojectImageTo3D, testing::Combine(
|
||||
ALL_DEVICES,
|
||||
DIFFERENT_SIZES,
|
||||
|
Loading…
Reference in New Issue
Block a user