\r
bool use_local_init_data_cost;\r
private:\r
- GpuMat u[2], d[2], l[2], r[2];\r
- GpuMat disp_selected_pyr[2];\r
-\r
- GpuMat data_cost;\r
- GpuMat data_cost_selected;\r
-\r
+ GpuMat messages_buffers;\r
+ \r
GpuMat temp;\r
-\r
GpuMat out;\r
};\r
\r
__constant__ int cth;\r
\r
__constant__ size_t cimg_step;\r
- __constant__ size_t cmsg_step1;\r
- __constant__ size_t cmsg_step2;\r
+ __constant__ size_t cmsg_step; \r
__constant__ size_t cdisp_step1;\r
__constant__ size_t cdisp_step2;\r
\r
\r
if (y < h && x < w)\r
{\r
- T* selected_disparity = selected_disp_pyr + y * cmsg_step1 + x;\r
- T* data_cost_selected = data_cost_selected_ + y * cmsg_step1 + x;\r
- T* data_cost = (T*)ctemp + y * cmsg_step1 + x;\r
+ T* selected_disparity = selected_disp_pyr + y * cmsg_step + x;\r
+ T* data_cost_selected = data_cost_selected_ + y * cmsg_step + x;\r
+ T* data_cost = (T*)ctemp + y * cmsg_step + x;\r
\r
for(int i = 0; i < nr_plane; i++)\r
{\r
\r
if (y < h && x < w)\r
{\r
- T* selected_disparity = selected_disp_pyr + y * cmsg_step1 + x;\r
- T* data_cost_selected = data_cost_selected_ + y * cmsg_step1 + x;\r
- T* data_cost = (T*)ctemp + y * cmsg_step1 + x;\r
+ T* selected_disparity = selected_disp_pyr + y * cmsg_step + x;\r
+ T* data_cost_selected = data_cost_selected_ + y * cmsg_step + x;\r
+ T* data_cost = (T*)ctemp + y * cmsg_step + x;\r
\r
int nr_local_minimum = 0;\r
\r
int x0 = x << level;\r
int xt = (x + 1) << level;\r
\r
- T* data_cost = (T*)ctemp + y * cmsg_step1 + x;\r
+ T* data_cost = (T*)ctemp + y * cmsg_step + x;\r
\r
for(int d = 0; d < cndisp; ++d)\r
{\r
if (winsz >= 4) if (tid < 2) vdline[tid] += vdline[tid + 2];\r
if (winsz >= 2) if (tid < 1) vdline[tid] += vdline[tid + 1];\r
\r
- T* data_cost = (T*)ctemp + y_out * cmsg_step1 + x_out;\r
+ T* data_cost = (T*)ctemp + y_out * cmsg_step + x_out;\r
\r
if (tid == 0)\r
data_cost[cdisp_step1 * d] = saturate_cast<T>(dline[0]);\r
\r
size_t disp_step = msg_step * h;\r
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step1, &disp_step, sizeof(size_t)) );\r
- cudaSafeCall( cudaMemcpyToSymbol(cmsg_step1, &msg_step, sizeof(size_t)) );\r
+ cudaSafeCall( cudaMemcpyToSymbol(cmsg_step, &msg_step, sizeof(size_t)) );\r
\r
init_data_cost_callers[level](rows, cols, h, w, level, ndisp, channels, stream);\r
cudaSafeCall( cudaGetLastError() );\r
int x0 = x << level;\r
int xt = (x + 1) << level;\r
\r
- const T* selected_disparity = selected_disp_pyr + y/2 * cmsg_step2 + x/2;\r
- T* data_cost = data_cost_ + y * cmsg_step1 + x;\r
+ const T* selected_disparity = selected_disp_pyr + y/2 * cmsg_step + x/2;\r
+ T* data_cost = data_cost_ + y * cmsg_step + x;\r
\r
for(int d = 0; d < nr_plane; d++)\r
{\r
\r
int tid = threadIdx.x;\r
\r
- const T* selected_disparity = selected_disp_pyr + y_out/2 * cmsg_step2 + x_out/2;\r
- T* data_cost = data_cost_ + y_out * cmsg_step1 + x_out;\r
+ const T* selected_disparity = selected_disp_pyr + y_out/2 * cmsg_step + x_out/2;\r
+ T* data_cost = data_cost_ + y_out * cmsg_step + x_out;\r
\r
if (d < nr_plane)\r
{\r
}\r
\r
template<class T>\r
- void compute_data_cost(const T* disp_selected_pyr, T* data_cost, size_t msg_step1, size_t msg_step2,\r
+ void compute_data_cost(const T* disp_selected_pyr, T* data_cost, size_t msg_step,\r
int rows, int cols, int h, int w, int h2, int level, int nr_plane, int channels, cudaStream_t stream)\r
{\r
typedef void (*ComputeDataCostCaller)(const T* disp_selected_pyr, T* data_cost, int rows, int cols,\r
compute_data_cost_reduce_caller_<T, 64>, compute_data_cost_reduce_caller_<T, 128>, compute_data_cost_reduce_caller_<T, 256>\r
};\r
\r
- size_t disp_step1 = msg_step1 * h;\r
- size_t disp_step2 = msg_step2 * h2;\r
+ size_t disp_step1 = msg_step * h;\r
+ size_t disp_step2 = msg_step * h2;\r
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step1, &disp_step1, sizeof(size_t)) );\r
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step2, &disp_step2, sizeof(size_t)) );\r
- cudaSafeCall( cudaMemcpyToSymbol(cmsg_step1, &msg_step1, sizeof(size_t)) );\r
- cudaSafeCall( cudaMemcpyToSymbol(cmsg_step2, &msg_step2, sizeof(size_t)) );\r
-\r
+ cudaSafeCall( cudaMemcpyToSymbol(cmsg_step, &msg_step, sizeof(size_t)) );\r
+ \r
callers[level](disp_selected_pyr, data_cost, rows, cols, h, w, level, nr_plane, channels, stream);\r
cudaSafeCall( cudaGetLastError() );\r
\r
cudaSafeCall( cudaDeviceSynchronize() );\r
}\r
\r
- template void compute_data_cost(const short* disp_selected_pyr, short* data_cost, size_t msg_step1, size_t msg_step2,\r
+ template void compute_data_cost(const short* disp_selected_pyr, short* data_cost, size_t msg_step,\r
int rows, int cols, int h, int w, int h2, int level, int nr_plane, int channels, cudaStream_t stream);\r
\r
- template void compute_data_cost(const float* disp_selected_pyr, float* data_cost, size_t msg_step1, size_t msg_step2,\r
+ template void compute_data_cost(const float* disp_selected_pyr, float* data_cost, size_t msg_step,\r
int rows, int cols, int h, int w, int h2, int level, int nr_plane, int channels, cudaStream_t stream);\r
\r
\r
\r
if (y < h && x < w)\r
{\r
- const T* u_cur = u_cur_ + ::min(h2-1, y/2 + 1) * cmsg_step2 + x/2;\r
- const T* d_cur = d_cur_ + ::max(0, y/2 - 1) * cmsg_step2 + x/2;\r
- const T* l_cur = l_cur_ + (y/2) * cmsg_step2 + ::min(w2-1, x/2 + 1);\r
- const T* r_cur = r_cur_ + (y/2) * cmsg_step2 + ::max(0, x/2 - 1);\r
+ const T* u_cur = u_cur_ + ::min(h2-1, y/2 + 1) * cmsg_step + x/2;\r
+ const T* d_cur = d_cur_ + ::max(0, y/2 - 1) * cmsg_step + x/2;\r
+ const T* l_cur = l_cur_ + (y/2) * cmsg_step + ::min(w2-1, x/2 + 1);\r
+ const T* r_cur = r_cur_ + (y/2) * cmsg_step + ::max(0, x/2 - 1);\r
\r
- T* data_cost_new = (T*)ctemp + y * cmsg_step1 + x;\r
+ T* data_cost_new = (T*)ctemp + y * cmsg_step + x;\r
\r
- const T* disparity_selected_cur = selected_disp_pyr_cur + y/2 * cmsg_step2 + x/2;\r
- const T* data_cost = data_cost_ + y * cmsg_step1 + x;\r
+ const T* disparity_selected_cur = selected_disp_pyr_cur + y/2 * cmsg_step + x/2;\r
+ const T* data_cost = data_cost_ + y * cmsg_step + x;\r
\r
for(int d = 0; d < nr_plane2; d++)\r
{\r
data_cost_new[d * cdisp_step1] = val;\r
}\r
\r
- T* data_cost_selected = data_cost_selected_ + y * cmsg_step1 + x;\r
- T* disparity_selected_new = selected_disp_pyr_new + y * cmsg_step1 + x;\r
+ T* data_cost_selected = data_cost_selected_ + y * cmsg_step + x;\r
+ T* disparity_selected_new = selected_disp_pyr_new + y * cmsg_step + x;\r
\r
- T* u_new = u_new_ + y * cmsg_step1 + x;\r
- T* d_new = d_new_ + y * cmsg_step1 + x;\r
- T* l_new = l_new_ + y * cmsg_step1 + x;\r
- T* r_new = r_new_ + y * cmsg_step1 + x;\r
+ T* u_new = u_new_ + y * cmsg_step + x;\r
+ T* d_new = d_new_ + y * cmsg_step + x;\r
+ T* l_new = l_new_ + y * cmsg_step + x;\r
+ T* r_new = r_new_ + y * cmsg_step + x;\r
\r
- u_cur = u_cur_ + y/2 * cmsg_step2 + x/2;\r
- d_cur = d_cur_ + y/2 * cmsg_step2 + x/2;\r
- l_cur = l_cur_ + y/2 * cmsg_step2 + x/2;\r
- r_cur = r_cur_ + y/2 * cmsg_step2 + x/2;\r
+ u_cur = u_cur_ + y/2 * cmsg_step + x/2;\r
+ d_cur = d_cur_ + y/2 * cmsg_step + x/2;\r
+ l_cur = l_cur_ + y/2 * cmsg_step + x/2;\r
+ r_cur = r_cur_ + y/2 * cmsg_step + x/2;\r
\r
get_first_k_element_increase(u_new, d_new, l_new, r_new, u_cur, d_cur, l_cur, r_cur,\r
data_cost_selected, disparity_selected_new, data_cost_new,\r
void init_message(T* u_new, T* d_new, T* l_new, T* r_new,\r
const T* u_cur, const T* d_cur, const T* l_cur, const T* r_cur,\r
T* selected_disp_pyr_new, const T* selected_disp_pyr_cur,\r
- T* data_cost_selected, const T* data_cost, size_t msg_step1, size_t msg_step2,\r
+ T* data_cost_selected, const T* data_cost, size_t msg_step,\r
int h, int w, int nr_plane, int h2, int w2, int nr_plane2, cudaStream_t stream)\r
{\r
\r
- size_t disp_step1 = msg_step1 * h;\r
- size_t disp_step2 = msg_step2 * h2;\r
+ size_t disp_step1 = msg_step * h;\r
+ size_t disp_step2 = msg_step * h2;\r
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step1, &disp_step1, sizeof(size_t)) );\r
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step2, &disp_step2, sizeof(size_t)) );\r
- cudaSafeCall( cudaMemcpyToSymbol(cmsg_step1, &msg_step1, sizeof(size_t)) );\r
- cudaSafeCall( cudaMemcpyToSymbol(cmsg_step2, &msg_step2, sizeof(size_t)) );\r
-\r
+ cudaSafeCall( cudaMemcpyToSymbol(cmsg_step, &msg_step, sizeof(size_t)) );\r
+ \r
dim3 threads(32, 8, 1);\r
dim3 grid(1, 1, 1);\r
\r
template void init_message(short* u_new, short* d_new, short* l_new, short* r_new,\r
const short* u_cur, const short* d_cur, const short* l_cur, const short* r_cur,\r
short* selected_disp_pyr_new, const short* selected_disp_pyr_cur,\r
- short* data_cost_selected, const short* data_cost, size_t msg_step1, size_t msg_step2,\r
+ short* data_cost_selected, const short* data_cost, size_t msg_step,\r
int h, int w, int nr_plane, int h2, int w2, int nr_plane2, cudaStream_t stream);\r
\r
template void init_message(float* u_new, float* d_new, float* l_new, float* r_new,\r
const float* u_cur, const float* d_cur, const float* l_cur, const float* r_cur,\r
float* selected_disp_pyr_new, const float* selected_disp_pyr_cur,\r
- float* data_cost_selected, const float* data_cost, size_t msg_step1, size_t msg_step2,\r
+ float* data_cost_selected, const float* data_cost, size_t msg_step,\r
int h, int w, int nr_plane, int h2, int w2, int nr_plane2, cudaStream_t stream); \r
\r
///////////////////////////////////////////////////////////////\r
\r
if (y > 0 && y < h - 1 && x > 0 && x < w - 1)\r
{\r
- const T* data = data_cost_selected + y * cmsg_step1 + x;\r
+ const T* data = data_cost_selected + y * cmsg_step + x;\r
\r
- T* u = u_ + y * cmsg_step1 + x;\r
- T* d = d_ + y * cmsg_step1 + x;\r
- T* l = l_ + y * cmsg_step1 + x;\r
- T* r = r_ + y * cmsg_step1 + x;\r
+ T* u = u_ + y * cmsg_step + x;\r
+ T* d = d_ + y * cmsg_step + x;\r
+ T* l = l_ + y * cmsg_step + x;\r
+ T* r = r_ + y * cmsg_step + x;\r
\r
- const T* disp = selected_disp_pyr_cur + y * cmsg_step1 + x;\r
+ const T* disp = selected_disp_pyr_cur + y * cmsg_step + x;\r
\r
- T* temp = (T*)ctemp + y * cmsg_step1 + x;\r
+ T* temp = (T*)ctemp + y * cmsg_step + x;\r
\r
- message_per_pixel(data, u, r - 1, u + cmsg_step1, l + 1, disp, disp - cmsg_step1, nr_plane, temp);\r
- message_per_pixel(data, d, d - cmsg_step1, r - 1, l + 1, disp, disp + cmsg_step1, nr_plane, temp);\r
- message_per_pixel(data, l, u + cmsg_step1, d - cmsg_step1, l + 1, disp, disp - 1, nr_plane, temp);\r
- message_per_pixel(data, r, u + cmsg_step1, d - cmsg_step1, r - 1, disp, disp + 1, nr_plane, temp);\r
+ message_per_pixel(data, u, r - 1, u + cmsg_step, l + 1, disp, disp - cmsg_step, nr_plane, temp);\r
+ message_per_pixel(data, d, d - cmsg_step, r - 1, l + 1, disp, disp + cmsg_step, nr_plane, temp);\r
+ message_per_pixel(data, l, u + cmsg_step, d - cmsg_step, l + 1, disp, disp - 1, nr_plane, temp);\r
+ message_per_pixel(data, r, u + cmsg_step, d - cmsg_step, r - 1, disp, disp + 1, nr_plane, temp);\r
}\r
}\r
\r
{\r
size_t disp_step = msg_step * h;\r
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step1, &disp_step, sizeof(size_t)) );\r
- cudaSafeCall( cudaMemcpyToSymbol(cmsg_step1, &msg_step, sizeof(size_t)) );\r
+ cudaSafeCall( cudaMemcpyToSymbol(cmsg_step, &msg_step, sizeof(size_t)) );\r
\r
dim3 threads(32, 8, 1);\r
dim3 grid(1, 1, 1);\r
\r
if (y > 0 && y < disp.rows - 1 && x > 0 && x < disp.cols - 1)\r
{\r
- const T* data = data_cost_selected + y * cmsg_step1 + x;\r
- const T* disp_selected = disp_selected_pyr + y * cmsg_step1 + x;\r
+ const T* data = data_cost_selected + y * cmsg_step + x;\r
+ const T* disp_selected = disp_selected_pyr + y * cmsg_step + x;\r
\r
- const T* u = u_ + (y+1) * cmsg_step1 + (x+0);\r
- const T* d = d_ + (y-1) * cmsg_step1 + (x+0);\r
- const T* l = l_ + (y+0) * cmsg_step1 + (x+1);\r
- const T* r = r_ + (y+0) * cmsg_step1 + (x-1);\r
+ const T* u = u_ + (y+1) * cmsg_step + (x+0);\r
+ const T* d = d_ + (y-1) * cmsg_step + (x+0);\r
+ const T* l = l_ + (y+0) * cmsg_step + (x+1);\r
+ const T* r = r_ + (y+0) * cmsg_step + (x-1);\r
\r
int best = 0;\r
T best_val = numeric_limits<T>::max();\r
{\r
size_t disp_step = disp.rows * msg_step;\r
cudaSafeCall( cudaMemcpyToSymbol(cdisp_step1, &disp_step, sizeof(size_t)) );\r
- cudaSafeCall( cudaMemcpyToSymbol(cmsg_step1, &msg_step, sizeof(size_t)) );\r
+ cudaSafeCall( cudaMemcpyToSymbol(cmsg_step, &msg_step, sizeof(size_t)) );\r
\r
dim3 threads(32, 8, 1);\r
dim3 grid(1, 1, 1);\r
int h, int w, int level, int nr_plane, int ndisp, int channels, bool use_local_init_data_cost, cudaStream_t stream);\r
\r
template<class T>\r
- void compute_data_cost(const T* disp_selected_pyr, T* data_cost, size_t msg_step1, size_t msg_step2,\r
+ void compute_data_cost(const T* disp_selected_pyr, T* data_cost, size_t msg_step,\r
int rows, int cols, int h, int w, int h2, int level, int nr_plane, int channels, cudaStream_t stream);\r
\r
template<class T>\r
void init_message(T* u_new, T* d_new, T* l_new, T* r_new,\r
const T* u_cur, const T* d_cur, const T* l_cur, const T* r_cur,\r
T* selected_disp_pyr_new, const T* selected_disp_pyr_cur,\r
- T* data_cost_selected, const T* data_cost, size_t msg_step1, size_t msg_step2,\r
+ T* data_cost_selected, const T* data_cost, size_t msg_step,\r
int h, int w, int nr_plane, int h2, int w2, int nr_plane2, cudaStream_t stream);\r
\r
template<class T>\r
}\r
\r
template<class T>\r
-static void csbp_operator(StereoConstantSpaceBP& rthis, GpuMat u[2], GpuMat d[2], GpuMat l[2], GpuMat r[2],\r
- GpuMat disp_selected_pyr[2], GpuMat& data_cost, GpuMat& data_cost_selected,\r
- GpuMat& temp, GpuMat& out, const GpuMat& left, const GpuMat& right, GpuMat& disp, Stream& stream)\r
+static void csbp_operator(StereoConstantSpaceBP& rthis, GpuMat& mbuf, GpuMat& temp, GpuMat& out, const GpuMat& left, const GpuMat& right, GpuMat& disp, Stream& stream)\r
{\r
CV_DbgAssert(0 < rthis.ndisp && 0 < rthis.iters && 0 < rthis.levels && 0 < rthis.nr_plane\r
&& left.rows == right.rows && left.cols == right.cols && left.type() == right.type());\r
////////////////////////////////////////////////////////////////////////////////////////////\r
// Init\r
\r
- int rows = left.rows;\r
+ int rows = left.rows;\r
int cols = left.cols;\r
\r
- rthis.levels = min(rthis.levels, int(log((double)rthis.ndisp) / log(2.0)));\r
+ rthis.levels = min(rthis.levels, int(log((double)rthis.ndisp) / log(2.0)));\r
int levels = rthis.levels;\r
-\r
- AutoBuffer<int> buf(levels * 4);\r
-\r
+ \r
+ // compute sizes\r
+ AutoBuffer<int> buf(levels * 3); \r
int* cols_pyr = buf;\r
int* rows_pyr = cols_pyr + levels;\r
int* nr_plane_pyr = rows_pyr + levels;\r
- int* step_pyr = nr_plane_pyr + levels;\r
-\r
- cols_pyr[0] = cols;\r
- rows_pyr[0] = rows;\r
+ \r
+ cols_pyr[0] = cols;\r
+ rows_pyr[0] = rows;\r
nr_plane_pyr[0] = rthis.nr_plane;\r
-\r
- const int n = 64;\r
- step_pyr[0] = static_cast<int>(alignSize(cols * sizeof(T), n) / sizeof(T));\r
+ \r
for (int i = 1; i < levels; i++)\r
{\r
- cols_pyr[i] = (cols_pyr[i-1] + 1) / 2;\r
- rows_pyr[i] = (rows_pyr[i-1] + 1) / 2;\r
-\r
- nr_plane_pyr[i] = nr_plane_pyr[i-1] * 2;\r
-\r
- step_pyr[i] = static_cast<int>(alignSize(cols_pyr[i] * sizeof(T), n) / sizeof(T));\r
- }\r
-\r
- Size msg_size(step_pyr[0], rows * nr_plane_pyr[0]);\r
- Size data_cost_size(step_pyr[0], rows * nr_plane_pyr[0] * 2);\r
-\r
- u[0].create(msg_size, DataType<T>::type);\r
- d[0].create(msg_size, DataType<T>::type);\r
- l[0].create(msg_size, DataType<T>::type);\r
- r[0].create(msg_size, DataType<T>::type);\r
-\r
- u[1].create(msg_size, DataType<T>::type);\r
- d[1].create(msg_size, DataType<T>::type);\r
- l[1].create(msg_size, DataType<T>::type);\r
- r[1].create(msg_size, DataType<T>::type);\r
-\r
- disp_selected_pyr[0].create(msg_size, DataType<T>::type);\r
- disp_selected_pyr[1].create(msg_size, DataType<T>::type);\r
-\r
- data_cost.create(data_cost_size, DataType<T>::type);\r
- data_cost_selected.create(msg_size, DataType<T>::type);\r
-\r
- step_pyr[0] = static_cast<int>(data_cost.step / sizeof(T));\r
-\r
- Size temp_size = data_cost_size;\r
- if (data_cost_size.width * data_cost_size.height < step_pyr[levels - 1] * rows_pyr[levels - 1] * rthis.ndisp)\r
- temp_size = Size(step_pyr[levels - 1], rows_pyr[levels - 1] * rthis.ndisp);\r
-\r
+ cols_pyr[i] = cols_pyr[i-1] / 2;\r
+ rows_pyr[i] = rows_pyr[i-1] / 2;\r
+ nr_plane_pyr[i] = nr_plane_pyr[i-1] * 2; \r
+ } \r
+\r
+\r
+ GpuMat u[2], d[2], l[2], r[2], disp_selected_pyr[2], data_cost, data_cost_selected;\r
+\r
+\r
+ //allocate buffers \r
+ int buffers_count = 10; // (up + down + left + right + disp_selected_pyr) * 2\r
+ buffers_count += 2; // data_cost has twice more rows than other buffers, what's why +2, not +1;\r
+ buffers_count += 1; // data_cost_selected\r
+ mbuf.create(rows * rthis.nr_plane * buffers_count, cols, DataType<T>::type);\r
+ \r
+ data_cost = mbuf.rowRange(0, rows * rthis.nr_plane * 2); \r
+ data_cost_selected = mbuf.rowRange(data_cost.rows, data_cost.rows + rows * rthis.nr_plane);\r
+ \r
+ for(int k = 0; k < 2; ++k) // in/out\r
+ { \r
+ GpuMat sub1 = mbuf.rowRange(data_cost.rows + data_cost_selected.rows, mbuf.rows);\r
+ GpuMat sub2 = sub1.rowRange((k+0)*sub1.rows/2, (k+1)*sub1.rows/2);\r
+\r
+ GpuMat *buf_ptrs[] = { &u[k], &d[k], &l[k], &r[k], &disp_selected_pyr[k] }; \r
+ for(int r = 0; r < 5; ++r) \r
+ {\r
+ *buf_ptrs[r] = sub2.rowRange(r * sub2.rows/5, (r+1) * sub2.rows/5);\r
+ assert(buf_ptrs[r]->cols == cols && buf_ptrs[r]->rows == rows * rthis.nr_plane);\r
+ }\r
+ };\r
+ \r
+ size_t elem_step = mbuf.step / sizeof(T); \r
+\r
+ Size temp_size = data_cost.size();\r
+ if ((size_t)temp_size.area() < elem_step * rows_pyr[levels - 1] * rthis.ndisp) \r
+ temp_size = Size(elem_step, rows_pyr[levels - 1] * rthis.ndisp);\r
+ \r
temp.create(temp_size, DataType<T>::type);\r
\r
////////////////////////////////////////////////////////////////////////////\r
if (i == levels - 1)\r
{\r
init_data_cost(left.rows, left.cols, disp_selected_pyr[cur_idx].ptr<T>(), data_cost_selected.ptr<T>(),\r
- 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);\r
+ elem_step, rows_pyr[i], cols_pyr[i], i, nr_plane_pyr[i], rthis.ndisp, left.channels(), rthis.use_local_init_data_cost, cudaStream);\r
}\r
else\r
{\r
- compute_data_cost(disp_selected_pyr[cur_idx].ptr<T>(), data_cost.ptr<T>(), step_pyr[i], step_pyr[i+1],\r
+ compute_data_cost(disp_selected_pyr[cur_idx].ptr<T>(), data_cost.ptr<T>(), elem_step,\r
left.rows, left.cols, rows_pyr[i], cols_pyr[i], rows_pyr[i+1], i, nr_plane_pyr[i+1], left.channels(), cudaStream);\r
\r
int new_idx = (cur_idx + 1) & 1;\r
init_message(u[new_idx].ptr<T>(), d[new_idx].ptr<T>(), l[new_idx].ptr<T>(), r[new_idx].ptr<T>(),\r
u[cur_idx].ptr<T>(), d[cur_idx].ptr<T>(), l[cur_idx].ptr<T>(), r[cur_idx].ptr<T>(),\r
disp_selected_pyr[new_idx].ptr<T>(), disp_selected_pyr[cur_idx].ptr<T>(),\r
- data_cost_selected.ptr<T>(), data_cost.ptr<T>(), step_pyr[i], step_pyr[i+1], rows_pyr[i],\r
+ data_cost_selected.ptr<T>(), data_cost.ptr<T>(), elem_step, rows_pyr[i],\r
cols_pyr[i], nr_plane_pyr[i], rows_pyr[i+1], cols_pyr[i+1], nr_plane_pyr[i+1], cudaStream);\r
\r
cur_idx = new_idx;\r
}\r
\r
calc_all_iterations(u[cur_idx].ptr<T>(), d[cur_idx].ptr<T>(), l[cur_idx].ptr<T>(), r[cur_idx].ptr<T>(),\r
- data_cost_selected.ptr<T>(), disp_selected_pyr[cur_idx].ptr<T>(), step_pyr[i],\r
+ data_cost_selected.ptr<T>(), disp_selected_pyr[cur_idx].ptr<T>(), elem_step,\r
rows_pyr[i], cols_pyr[i], nr_plane_pyr[i], rthis.iters, cudaStream);\r
}\r
\r
out.setTo(zero);\r
\r
compute_disp(u[cur_idx].ptr<T>(), d[cur_idx].ptr<T>(), l[cur_idx].ptr<T>(), r[cur_idx].ptr<T>(),\r
- data_cost_selected.ptr<T>(), disp_selected_pyr[cur_idx].ptr<T>(), step_pyr[0], out, nr_plane_pyr[0], cudaStream);\r
+ data_cost_selected.ptr<T>(), disp_selected_pyr[cur_idx].ptr<T>(), elem_step, out, nr_plane_pyr[0], cudaStream);\r
\r
if (disp.type() != CV_16S)\r
{\r
}\r
\r
\r
-typedef void (*csbp_operator_t)(StereoConstantSpaceBP& rthis, GpuMat u[2], GpuMat d[2], GpuMat l[2], GpuMat r[2],\r
- GpuMat disp_selected_pyr[2], GpuMat& data_cost, GpuMat& data_cost_selected,\r
+typedef void (*csbp_operator_t)(StereoConstantSpaceBP& rthis, GpuMat& mbuf,\r
GpuMat& temp, GpuMat& out, const GpuMat& left, const GpuMat& right, GpuMat& disp, Stream& stream);\r
\r
const static csbp_operator_t operators[] = {0, 0, 0, csbp_operator<short>, 0, csbp_operator<float>, 0, 0};\r
void cv::gpu::StereoConstantSpaceBP::operator()(const GpuMat& left, const GpuMat& right, GpuMat& disp, Stream& stream)\r
{\r
CV_Assert(msg_type == CV_32F || msg_type == CV_16S);\r
- operators[msg_type](*this, u, d, l, r, disp_selected_pyr, data_cost, data_cost_selected, temp, out, left, right, disp, stream);\r
+ operators[msg_type](*this, messages_buffers, temp, out, left, right, disp, stream);\r
}\r
\r
#endif /* !defined (HAVE_CUDA) */\r
{\r
static float getValue(float p[4], float x)\r
{\r
- 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])));\r
+ 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]))));\r
}\r
\r
static float getValue(float p[4][4], float x, float y)\r
\r
float vals[4][4] =\r
{\r
- {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)},\r
- {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)},\r
- {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)},\r
- {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)},\r
+ {(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)},\r
+ {(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)},\r
+ {(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)},\r
+ {(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)},\r
};\r
\r
- return cv::saturate_cast<T>(getValue(vals, (x - ix + 2.0) / 4.0, (y - iy + 2.0) / 4.0));\r
+ 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)));\r
}\r
};\r
\r
ASSERT_LE(cv::norm(tvec - tvec_gold), 1e-3);\r
}\r
\r
-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);\r
+\r
+////////////////////////////////////////////////////////////////////////////////\r
+// reprojectImageTo3D\r
+\r
+PARAM_TEST_CASE(ReprojectImageTo3D, cv::gpu::DeviceInfo, cv::Size, MatDepth, UseRoi)\r
+{\r
+ cv::gpu::DeviceInfo devInfo;\r
+ cv::Size size;\r
+ int depth;\r
+ bool useRoi;\r
+\r
+ virtual void SetUp()\r
+ {\r
+ devInfo = GET_PARAM(0);\r
+ size = GET_PARAM(1);\r
+ depth = GET_PARAM(2);\r
+ useRoi = GET_PARAM(3);\r
+\r
+ cv::gpu::setDevice(devInfo.deviceID());\r
+ }\r
+};\r
+\r
+TEST_P(ReprojectImageTo3D, Accuracy)\r
+{\r
+ cv::Mat disp = randomMat(size, depth, 5.0, 30.0);\r
+ cv::Mat Q = randomMat(cv::Size(4, 4), CV_32FC1, 0.1, 1.0);\r
+\r
+ cv::gpu::GpuMat dst;\r
+ cv::gpu::reprojectImageTo3D(loadMat(disp, useRoi), dst, Q, 3);\r
+ \r
+ cv::Mat dst_gold;\r
+ cv::reprojectImageTo3D(disp, dst_gold, Q, false);\r
+\r
+ EXPECT_MAT_NEAR(dst_gold, dst, 1e-5);\r
+}\r
+\r
INSTANTIATE_TEST_CASE_P(GPU_Calib3D, ReprojectImageTo3D, testing::Combine(\r
ALL_DEVICES,\r
DIFFERENT_SIZES,\r