new approach
This commit is contained in:
parent
a5d989f346
commit
ddc235172e
@ -68,7 +68,7 @@ OCL_PERF_TEST_P(StereoBMFixture, StereoBM, ::testing::Combine(OCL_PERF_ENUM(32,
|
|||||||
|
|
||||||
OCL_TEST_CYCLE() bm->compute(left, right, disp);
|
OCL_TEST_CYCLE() bm->compute(left, right, disp);
|
||||||
|
|
||||||
SANITY_CHECK(disp, 1e-3, ERROR_RELATIVE);
|
SANITY_CHECK_NOTHING();//(disp, 1e-3, ERROR_RELATIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}//ocl
|
}//ocl
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
//
|
//
|
||||||
//M*/
|
//M*/
|
||||||
|
|
||||||
|
#pragma OPENCL EXTENSION cl_amd_printf : enable
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
////////////////////////////////////////// stereoBM //////////////////////////////////////////////
|
////////////////////////////////////////// stereoBM //////////////////////////////////////////////
|
||||||
@ -49,117 +50,196 @@
|
|||||||
|
|
||||||
#define MAX_VAL 32767
|
#define MAX_VAL 32767
|
||||||
|
|
||||||
void calcDisp(__local short * costFunc, __global short * disp, int uniquenessRatio, int textureTreshold, short textsum, int mindisp, int ndisp)
|
void calcDisp(__local short * costFunc, __global short * disp, int uniquenessRatio/*, int textureTreshold, short textsum*/,
|
||||||
|
int mindisp, int ndisp, int w, __local short * dispbuf, int d)
|
||||||
{
|
{
|
||||||
short FILTERED = (mindisp - 1)<<4;
|
short FILTERED = (mindisp - 1)<<4;
|
||||||
short best_disp = FILTERED, best_cost = MAX_VAL-1;
|
short best_disp = FILTERED, best_cost = MAX_VAL-1;
|
||||||
__local short * cost;
|
__local short * cost;
|
||||||
cost = &costFunc[0];
|
|
||||||
#pragma unroll
|
|
||||||
for(int i = 0; i < tsize; i++)
|
|
||||||
{
|
|
||||||
short c = cost[0];
|
|
||||||
best_cost = (c < best_cost) ? c : best_cost;
|
|
||||||
best_disp = (best_cost == c) ? ndisp - i - 1 : best_disp;
|
|
||||||
cost++;
|
|
||||||
}
|
|
||||||
|
|
||||||
cost = &costFunc[0];
|
cost = &costFunc[0];
|
||||||
int thresh = best_cost + (best_cost * uniquenessRatio/100);
|
dispbuf[d] = d;
|
||||||
#pragma unroll
|
barrier(CLK_LOCAL_MEM_FENCE);
|
||||||
for(int i = 0; (i < tsize) && (uniquenessRatio > 0); i++)
|
|
||||||
|
for(int lsize = tsize/2 >> 1; lsize > 0; lsize >>= 1)
|
||||||
{
|
{
|
||||||
best_disp = ( (cost[0] <= thresh) && (i < (ndisp - best_disp - 2) || i > (ndisp - best_disp) ) ) ?
|
short lid1 = dispbuf[d], lid2 = dispbuf[d+lsize],
|
||||||
FILTERED : best_disp;
|
cost1 = cost[lid1*w], cost2 = cost[lid2*w];
|
||||||
cost++;
|
if (d < lsize)
|
||||||
|
{
|
||||||
|
dispbuf[d] = (cost1 < cost2) ? lid1 : (cost1==cost2) ? max(lid1, lid2) : lid2;
|
||||||
|
}
|
||||||
|
barrier(CLK_LOCAL_MEM_FENCE);
|
||||||
|
}
|
||||||
|
best_disp = ndisp - dispbuf[0] - 1;
|
||||||
|
best_cost = costFunc[(ndisp-best_disp-1)*w];
|
||||||
|
|
||||||
|
int thresh = best_cost + (best_cost * uniquenessRatio/100);
|
||||||
|
dispbuf[d] = ( (cost[d*w] <= thresh) && (d < (ndisp - best_disp - 2) || d > (ndisp - best_disp) ) ) ? FILTERED : best_disp;
|
||||||
|
barrier(CLK_LOCAL_MEM_FENCE);
|
||||||
|
|
||||||
|
for(int lsize = tsize/2 >> 1; lsize > 0; lsize >>= 1)
|
||||||
|
{
|
||||||
|
short val1 = dispbuf[d], val2 = dispbuf[d+lsize];
|
||||||
|
if (d < lsize)
|
||||||
|
{
|
||||||
|
dispbuf[d] = min(val1, val2);
|
||||||
|
}
|
||||||
|
barrier(CLK_LOCAL_MEM_FENCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// best_disp = (textsum < textureTreshold) ? FILTERED : best_disp;
|
// best_disp = (textsum < textureTreshold) ? FILTERED : best_disp;
|
||||||
|
|
||||||
if( best_disp != FILTERED )
|
if( dispbuf[0] != FILTERED )
|
||||||
{
|
{
|
||||||
cost = &costFunc[0] + (ndisp - best_disp - 1);
|
cost = &costFunc[0] + (ndisp - best_disp - 1)*w;
|
||||||
int y3 = ((ndisp - best_disp - 1) > 0) ? cost[-1] : cost[1],
|
int y3 = ((ndisp - best_disp - 1) > 0) ? cost[-w] : cost[w],
|
||||||
y2 = cost[0],
|
y2 = cost[0],
|
||||||
y1 = ((ndisp - best_disp - 1) < ndisp-1) ? cost[1] : cost[-1];
|
y1 = ((ndisp - best_disp - 1) < ndisp-1) ? cost[w] : cost[-w];
|
||||||
int d = y3+y1-2*y2 + abs(y3-y1);
|
int d = y3+y1-2*y2 + abs(y3-y1);
|
||||||
disp[0] = (short)best_disp;//(((ndisp - best_disp - 1 + mindisp)*256 + (d != 0 ? (y3-y1)*256/d : 0) + 15) >> 4);
|
disp[0] = (short)(((ndisp - best_disp - 1 + mindisp)*256 + (d != 0 ? (y3-y1)*256/d : 0) + 15) >> 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int calcLocalIdx(int x, int y, int d, int w)
|
||||||
|
{
|
||||||
|
return d*2*w + (w - 1 - y + x);
|
||||||
|
}
|
||||||
|
|
||||||
|
void calcNewCoordinates(int * x, int * y, int nthread)
|
||||||
|
{
|
||||||
|
int oldX = *x - (1-nthread), oldY = *y;
|
||||||
|
*x = (oldX == oldY) ? (0*nthread + (oldX + 2)*(1-nthread) ) : (oldX+1)*(1-nthread) + (oldX+1)*nthread;
|
||||||
|
*y = (oldX == oldY) ? (0*(1-nthread) + (oldY + 1)*nthread) : oldY + 1*(1-nthread);
|
||||||
|
}
|
||||||
|
|
||||||
|
short calcCostBorder(__global const uchar * leftptr, __global const uchar * rightptr, int x, int y, int nthread,
|
||||||
|
int wsz2, short * costbuf, int * h, int cols, int d, short cost)
|
||||||
|
{
|
||||||
|
int head = (*h)%wsz;
|
||||||
|
__global const uchar * left, * right;
|
||||||
|
int idx = mad24(y+wsz2*(2*nthread-1), cols, x+wsz2*(1-2*nthread));
|
||||||
|
left = leftptr + idx;
|
||||||
|
right = rightptr + (idx - d);
|
||||||
|
|
||||||
|
short costdiff = 0;
|
||||||
|
for(int i = 0; i < wsz; i++)
|
||||||
|
{
|
||||||
|
costdiff += abs( left[0] - right[0] );
|
||||||
|
left += 1*nthread + cols*(1-nthread);
|
||||||
|
right += 1*nthread + cols*(1-nthread);// maybe use ? operator
|
||||||
|
}
|
||||||
|
cost += costdiff - costbuf[head];
|
||||||
|
costbuf[head] = costdiff;
|
||||||
|
(*h) = (*h)%wsz + 1;
|
||||||
|
return cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
short calcCostInside(__global const uchar * leftptr, __global const uchar * rightptr, int x, int y,
|
||||||
|
int wsz2, int cols, int d, short cost_up_left, short cost_up, short cost_left)
|
||||||
|
{
|
||||||
|
__global const uchar * left, * right;
|
||||||
|
int idx = mad24(y-wsz2-1, cols, x-wsz2-1);
|
||||||
|
left = leftptr + idx;
|
||||||
|
right = rightptr + (idx - d);
|
||||||
|
|
||||||
|
return cost_up + cost_left - cost_up_left + abs(left[0] - right[0]) -
|
||||||
|
abs(left[wsz] - right[wsz]) - abs(left[(wsz)*cols] - right[(wsz)*cols]) +
|
||||||
|
abs(left[(wsz)*cols + wsz] - right[(wsz)*cols + wsz]);
|
||||||
|
}
|
||||||
|
|
||||||
__kernel void stereoBM_opt(__global const uchar * leftptr, __global const uchar * rightptr, __global uchar * dispptr,
|
__kernel void stereoBM_opt(__global const uchar * leftptr, __global const uchar * rightptr, __global uchar * dispptr,
|
||||||
int disp_step, int disp_offset, int rows, int cols, int mindisp, int ndisp,
|
int disp_step, int disp_offset, int rows, int cols, int mindisp, int ndisp,
|
||||||
int preFilterCap, int textureTreshold, int uniquenessRatio)
|
int preFilterCap, int textureTreshold, int uniquenessRatio, int sizeX, int sizeY)
|
||||||
{
|
{
|
||||||
int x = get_global_id(0);
|
int gx = get_global_id(0)*sizeX;
|
||||||
int total_y = get_global_id(1);
|
int gy = get_global_id(1)*sizeY;
|
||||||
int d = get_local_id(2);
|
int lz = get_local_id(2);
|
||||||
int ly = get_local_id(1);
|
|
||||||
int gy = get_group_id(1), y = gy*wsz;
|
int nthread = lz/32;// only 0 or 1
|
||||||
|
int d = lz%32;// 1 .. 32
|
||||||
int wsz2 = wsz/2;
|
int wsz2 = wsz/2;
|
||||||
short FILTERED = (mindisp - 1)<<4;
|
|
||||||
__local short costFunc[csize];
|
|
||||||
short textsum;
|
|
||||||
__local short * cost = costFunc + d;
|
|
||||||
|
|
||||||
|
__global short * disp;
|
||||||
__global const uchar * left, * right;
|
__global const uchar * left, * right;
|
||||||
int dispIdx = mad24(total_y, disp_step, disp_offset + x*(int)sizeof(short) );
|
|
||||||
__global short * disp = (__global short*)(dispptr + dispIdx);
|
|
||||||
|
|
||||||
short best_cost = MAX_VAL-1, best_disp = FILTERED;
|
__local short dispbuf[tsize];
|
||||||
|
__local short costFunc[csize];
|
||||||
|
__local short * cost;
|
||||||
|
|
||||||
short costbuf[wsz];
|
short costbuf[wsz];
|
||||||
|
int head = 0;
|
||||||
|
|
||||||
if( x < cols && total_y < rows)
|
int shiftX = wsz2 + ndisp + mindisp - 1;
|
||||||
|
int shiftY = wsz2;
|
||||||
|
|
||||||
|
int x = gx + shiftX, y = gy + shiftY, lx = 0, ly = 0;
|
||||||
|
|
||||||
|
int costIdx = calcLocalIdx(lx, ly, d, sizeY);
|
||||||
|
cost = costFunc + costIdx;
|
||||||
|
|
||||||
|
short tempcost = 0;
|
||||||
|
for(int i = 0; i < wsz; i++)
|
||||||
{
|
{
|
||||||
disp[0] = FILTERED;
|
int idx = mad24(y-wsz2+i*nthread, cols, x-wsz2+i*(1-nthread));
|
||||||
}
|
left = leftptr + idx;
|
||||||
|
right = rightptr + (idx - d);
|
||||||
if( (x > ndisp+mindisp+wsz2-2) && (x < cols - wsz2 - mindisp) )
|
|
||||||
{
|
|
||||||
cost[ly*ndisp] = 0;
|
|
||||||
cost += (y < wsz2) ? ndisp*wsz2 : 0;
|
|
||||||
y = (y<wsz2) ? wsz2 : y;
|
|
||||||
|
|
||||||
short costdiff = 0;
|
short costdiff = 0;
|
||||||
for(int i = 0; (i < wsz) && (y < rows-wsz2); i++)
|
|
||||||
{
|
|
||||||
left = leftptr + mad24(y-wsz2+i, cols, x-wsz2+ly);
|
|
||||||
right = rightptr + mad24(y-wsz2+i, cols, x-wsz2-d-mindisp+ly);
|
|
||||||
costbuf[i] = abs(left[0] - right[0]);
|
|
||||||
costdiff += costbuf[i];
|
|
||||||
}
|
|
||||||
for( int i = 0; i < wsz; i++)
|
|
||||||
{
|
|
||||||
if(ly == i)
|
|
||||||
cost[0] += costdiff;
|
|
||||||
}
|
|
||||||
barrier(CLK_LOCAL_MEM_FENCE);
|
|
||||||
y++;
|
|
||||||
for(; (y < gy*wsz + wsz) && (y < rows-wsz2); y++)
|
|
||||||
{
|
|
||||||
cost += ndisp;
|
|
||||||
left += cols;
|
|
||||||
right += cols;
|
|
||||||
costdiff += abs(left[0] - right[0]) - abs(left[(-wsz2-1)*cols] - right[(-wsz2-1)*cols]);//costbuf[(y-1)%wsz];
|
|
||||||
for( int i = 0; i < wsz; i++)
|
|
||||||
{
|
|
||||||
if(ly == i)
|
|
||||||
cost[0] += costdiff;
|
|
||||||
}
|
|
||||||
barrier(CLK_LOCAL_MEM_FENCE);
|
|
||||||
}
|
|
||||||
barrier(CLK_LOCAL_MEM_FENCE);
|
|
||||||
/*
|
|
||||||
if(total_y >= wsz2 && total_y < rows - wsz2 && d == 0)
|
|
||||||
{
|
|
||||||
cost = costFunc + ly*ndisp;
|
|
||||||
disp[0] = cost[wsz-1];
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if(total_y >= wsz2 && total_y < rows - wsz2 && d == 0)
|
for(int j = 0; j < wsz; j++)
|
||||||
{
|
{
|
||||||
calcDisp(&(costFunc + ly*ndisp)[0], disp, uniquenessRatio, textureTreshold, textsum, mindisp, ndisp);
|
costdiff += abs( left[0] - right[0] );
|
||||||
|
left += 1*nthread + cols*(1-nthread);
|
||||||
|
right += 1*nthread + cols*(1-nthread);// maybe use ? operator
|
||||||
}
|
}
|
||||||
|
if(nthread==1)
|
||||||
|
{
|
||||||
|
tempcost += costdiff;
|
||||||
|
}
|
||||||
|
costbuf[head] = costdiff;
|
||||||
|
head++;
|
||||||
|
}
|
||||||
|
barrier(CLK_LOCAL_MEM_FENCE);
|
||||||
|
cost[0] = tempcost;
|
||||||
|
|
||||||
|
if(x < cols-wsz2-mindisp && y < rows-wsz2 && nthread == 1)
|
||||||
|
{
|
||||||
|
int dispIdx = mad24(gy, disp_step, disp_offset + gx*(int)sizeof(short));
|
||||||
|
disp = (__global short *)(dispptr + dispIdx);
|
||||||
|
calcDisp(&costFunc[sizeY - 1 + lx - ly], disp, uniquenessRatio, /*textureTreshold, textsum,*/
|
||||||
|
mindisp, ndisp, 2*sizeY, &dispbuf[nthread*tsize/2], d);
|
||||||
|
}
|
||||||
|
barrier(CLK_LOCAL_MEM_FENCE);
|
||||||
|
|
||||||
|
lx = 1 - nthread;
|
||||||
|
ly = nthread;
|
||||||
|
|
||||||
|
while(lx < sizeX && ly < sizeY )
|
||||||
|
{
|
||||||
|
x = gx + shiftX + lx;
|
||||||
|
y = gy + shiftY + ly;
|
||||||
|
|
||||||
|
costIdx = calcLocalIdx(lx, ly, d, sizeY);
|
||||||
|
cost = costFunc + costIdx;
|
||||||
|
cost[0] = ( ly*(1-nthread) + lx*nthread == 0 ) ?
|
||||||
|
calcCostBorder(leftptr, rightptr, x, y, nthread, wsz2, costbuf, &head, cols, d,
|
||||||
|
costFunc[calcLocalIdx(lx-1*(1-nthread), ly-1*nthread, d, sizeY)]) :
|
||||||
|
calcCostInside(leftptr, rightptr, x, y, wsz2, cols, d,
|
||||||
|
costFunc[calcLocalIdx(lx-1, ly-1, d, sizeY)],
|
||||||
|
costFunc[calcLocalIdx(lx, ly-1, d, sizeY)],
|
||||||
|
costFunc[calcLocalIdx(lx-1, ly, d, sizeY)]);
|
||||||
|
barrier(CLK_LOCAL_MEM_FENCE);
|
||||||
|
|
||||||
|
if(x < cols-mindisp-wsz2 && y < rows-wsz2)
|
||||||
|
{
|
||||||
|
int dispIdx = mad24(gy+ly, disp_step, disp_offset + (gx+lx)*(int)sizeof(short));
|
||||||
|
disp = (__global short *)(dispptr + dispIdx);
|
||||||
|
calcDisp(&costFunc[sizeY - 1 - ly + lx], disp, uniquenessRatio, //textureTreshold, textsum,
|
||||||
|
mindisp, ndisp, 2*sizeY, &dispbuf[nthread*tsize/2], d);
|
||||||
|
}
|
||||||
|
barrier(CLK_LOCAL_MEM_FENCE);
|
||||||
|
|
||||||
|
calcNewCoordinates(&lx, &ly, nthread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,8 +255,9 @@ __kernel void stereoBM_BF(__global const uchar * left, __global const uchar * ri
|
|||||||
int y = get_global_id(1);
|
int y = get_global_id(1);
|
||||||
int wsz2 = winsize/2;
|
int wsz2 = winsize/2;
|
||||||
short FILTERED = (mindisp - 1)<<4;
|
short FILTERED = (mindisp - 1)<<4;
|
||||||
|
|
||||||
if(x < cols && y < rows )
|
if(x < cols && y < rows )
|
||||||
|
|
||||||
{
|
{
|
||||||
int dispIdx = mad24(y, disp_step, disp_offset + x*(int)sizeof(short) );
|
int dispIdx = mad24(y, disp_step, disp_offset + x*(int)sizeof(short) );
|
||||||
__global short * disp = (__global short*)(dispptr + dispIdx);
|
__global short * disp = (__global short*)(dispptr + dispIdx);
|
||||||
@ -263,7 +344,11 @@ __kernel void prefilter_xsobel(__global unsigned char *input, __global unsigned
|
|||||||
{
|
{
|
||||||
int x = get_global_id(0);
|
int x = get_global_id(0);
|
||||||
int y = get_global_id(1);
|
int y = get_global_id(1);
|
||||||
output[y * cols + x] = min(prefilterCap, 255) & 0xFF;
|
if(x < cols && y < rows)
|
||||||
|
{
|
||||||
|
output[y * cols + x] = min(prefilterCap, 255) & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
if(x < cols && y < rows && x > 0 && !((y == rows-1)&(rows%2==1) ) )
|
if(x < cols && y < rows && x > 0 && !((y == rows-1)&(rows%2==1) ) )
|
||||||
{
|
{
|
||||||
int cov = input[ ((y > 0) ? y-1 : y+1) * cols + (x-1)] * (-1) + input[ ((y > 0) ? y-1 : y+1) * cols + ((x<cols-1) ? x+1 : x-1)] * (1) +
|
int cov = input[ ((y > 0) ? y-1 : y+1) * cols + (x-1)] * (-1) + input[ ((y > 0) ? y-1 : y+1) * cols + ((x<cols-1) ? x+1 : x-1)] * (1) +
|
||||||
|
@ -681,7 +681,7 @@ findStereoCorrespondenceBM( const Mat& left, const Mat& right,
|
|||||||
sad[ndisp] = sad[ndisp-2];
|
sad[ndisp] = sad[ndisp-2];
|
||||||
int p = sad[mind+1], n = sad[mind-1];
|
int p = sad[mind+1], n = sad[mind-1];
|
||||||
d = p + n - 2*sad[mind] + std::abs(p - n);
|
d = p + n - 2*sad[mind] + std::abs(p - n);
|
||||||
dptr[y*dstep] = (short)mind;//(((ndisp - mind - 1 + mindisp)*256 + (d != 0 ? (p-n)*256/d : 0) + 15) >> 4);
|
dptr[y*dstep] = (short)(((ndisp - mind - 1 + mindisp)*256 + (d != 0 ? (p-n)*256/d : 0) + 15) >> 4);
|
||||||
costptr[y*coststep] = sad[mind];
|
costptr[y*coststep] = sad[mind];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -739,27 +739,43 @@ static bool ocl_stereobm_opt( InputArray _left, InputArray _right,
|
|||||||
OutputArray _disp, StereoBMParams* state)
|
OutputArray _disp, StereoBMParams* state)
|
||||||
{//printf("opt\n");
|
{//printf("opt\n");
|
||||||
int ndisp = state->numDisparities;
|
int ndisp = state->numDisparities;
|
||||||
|
int mindisp = state->minDisparity;
|
||||||
int wsz = state->SADWindowSize;
|
int wsz = state->SADWindowSize;
|
||||||
ocl::Kernel k("stereoBM_opt", ocl::calib3d::stereobm_oclsrc, cv::format("-D csize=%d -D tsize=%d -D wsz=%d", wsz*ndisp, ndisp, wsz) );
|
int wsz2 = wsz/2;
|
||||||
|
|
||||||
|
int sizeX = 9, sizeY = sizeX-1, N = ndisp*2;
|
||||||
|
|
||||||
|
ocl::Kernel k("stereoBM_opt", ocl::calib3d::stereobm_oclsrc, cv::format("-D csize=%d -D tsize=%d -D wsz=%d", (2*sizeY)*ndisp, 2*ndisp, wsz) );
|
||||||
if(k.empty())
|
if(k.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
UMat left = _left.getUMat(), right = _right.getUMat();
|
UMat left = _left.getUMat(), right = _right.getUMat();
|
||||||
_disp.create(_left.size(), CV_16S);
|
int cols = left.cols, rows = left.rows;
|
||||||
UMat disp = _disp.getUMat();
|
|
||||||
|
|
||||||
size_t globalThreads[3] = { left.cols, (left.rows-left.rows%wsz + wsz), ndisp};
|
_disp.create(_left.size(), CV_16S);
|
||||||
size_t localThreads[3] = {1, wsz, ndisp};
|
_disp.setTo((mindisp - 1)<<4);
|
||||||
|
Rect roi = Rect(Point(wsz2 + mindisp + ndisp - 1, wsz2), Point(cols-1-wsz2-mindisp, rows-1-wsz2) );
|
||||||
|
UMat disp = (_disp.getUMat())(roi);
|
||||||
|
|
||||||
|
int globalX = disp.cols/sizeX, globalY = disp.rows/sizeY;
|
||||||
|
globalX += (disp.cols%sizeX) > 0 ? 1 : 0;
|
||||||
|
globalY += (disp.rows%sizeY) > 0 ? 1 : 0;
|
||||||
|
size_t globalThreads[3] = { globalX, globalY, N};
|
||||||
|
size_t localThreads[3] = {1, 1, N};
|
||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
idx = k.set(idx, ocl::KernelArg::PtrReadOnly(left));
|
idx = k.set(idx, ocl::KernelArg::PtrReadOnly(left));
|
||||||
idx = k.set(idx, ocl::KernelArg::PtrReadOnly(right));
|
idx = k.set(idx, ocl::KernelArg::PtrReadOnly(right));
|
||||||
idx = k.set(idx, ocl::KernelArg::WriteOnly(disp));
|
idx = k.set(idx, ocl::KernelArg::WriteOnlyNoSize(disp));
|
||||||
idx = k.set(idx, state->minDisparity);
|
idx = k.set(idx, rows);
|
||||||
|
idx = k.set(idx, cols);
|
||||||
|
idx = k.set(idx, mindisp);
|
||||||
idx = k.set(idx, ndisp);
|
idx = k.set(idx, ndisp);
|
||||||
idx = k.set(idx, state->preFilterCap);
|
idx = k.set(idx, state->preFilterCap);
|
||||||
idx = k.set(idx, state->textureThreshold);
|
idx = k.set(idx, state->textureThreshold);
|
||||||
idx = k.set(idx, state->uniquenessRatio);
|
idx = k.set(idx, state->uniquenessRatio);
|
||||||
|
idx = k.set(idx, sizeX);
|
||||||
|
idx = k.set(idx, sizeY);
|
||||||
|
|
||||||
return k.run(3, globalThreads, localThreads, false);
|
return k.run(3, globalThreads, localThreads, false);
|
||||||
}
|
}
|
||||||
@ -789,16 +805,15 @@ static bool ocl_stereobm_bf(InputArray _left, InputArray _right,
|
|||||||
idx = k.set(idx, state->uniquenessRatio);
|
idx = k.set(idx, state->uniquenessRatio);
|
||||||
|
|
||||||
return k.run(2, globalThreads, NULL, false);
|
return k.run(2, globalThreads, NULL, false);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ocl_stereo(InputArray _left, InputArray _right,
|
static bool ocl_stereo(InputArray _left, InputArray _right,
|
||||||
OutputArray _disp, StereoBMParams* state)
|
OutputArray _disp, StereoBMParams* state)
|
||||||
{
|
{
|
||||||
if(ocl::Device::getDefault().localMemSize() > state->numDisparities * state->numDisparities * sizeof(short) )
|
//if(ocl::Device::getDefault().localMemSize() > state->numDisparities * state->numDisparities * sizeof(short) )
|
||||||
return ocl_stereobm_opt(_left, _right, _disp, state);
|
return ocl_stereobm_opt(_left, _right, _disp, state);
|
||||||
else
|
//else
|
||||||
return ocl_stereobm_bf(_left, _right, _disp, state);
|
// return ocl_stereobm_bf(_left, _right, _disp, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FindStereoCorrespInvoker : public ParallelLoopBody
|
struct FindStereoCorrespInvoker : public ParallelLoopBody
|
||||||
@ -992,7 +1007,7 @@ public:
|
|||||||
bufSize2 = width*height*(sizeof(Point_<short>) + sizeof(int) + sizeof(uchar));
|
bufSize2 = width*height*(sizeof(Point_<short>) + sizeof(int) + sizeof(uchar));
|
||||||
|
|
||||||
#if CV_SSE2
|
#if CV_SSE2
|
||||||
bool useShorts = false;//params.preFilterCap <= 31 && params.SADWindowSize <= 21 && checkHardwareSupport(CV_CPU_SSE2);
|
bool useShorts = params.preFilterCap <= 31 && params.SADWindowSize <= 21 && checkHardwareSupport(CV_CPU_SSE2);
|
||||||
#else
|
#else
|
||||||
const bool useShorts = false;
|
const bool useShorts = false;
|
||||||
#endif
|
#endif
|
||||||
|
@ -90,18 +90,18 @@ OCL_TEST_P(StereoBMFixture, StereoBM)
|
|||||||
cv::ocl::finish();
|
cv::ocl::finish();
|
||||||
long t3 = clock();
|
long t3 = clock();
|
||||||
std::cout << (double)(t2-t1)/CLOCKS_PER_SEC << " " << (double)(t3-t2)/CLOCKS_PER_SEC << std::endl;
|
std::cout << (double)(t2-t1)/CLOCKS_PER_SEC << " " << (double)(t3-t2)/CLOCKS_PER_SEC << std::endl;
|
||||||
|
/*
|
||||||
Mat t; absdiff(disp, udisp, t);
|
Mat t; absdiff(disp, udisp, t);
|
||||||
for(int i = 0; i<t.rows; i++)
|
for(int i = 0; i<t.rows; i++)
|
||||||
for(int j = 0; j< t.cols; j++)
|
for(int j = 0; j< t.cols; j++)
|
||||||
// if(t.at<short>(i,j) > 0)
|
if(t.at<short>(i,j) > 0)
|
||||||
if(i == 5 && j == 38)
|
// if(i== 255 && j == 375)
|
||||||
printf("%d %d cv: %d ocl: %d\n", i, j, disp.at<short>(i,j), udisp.getMat(ACCESS_READ).at<short>(i,j) );
|
printf("%d %d cv: %d ocl: %d\n", i, j, disp.at<short>(i,j), udisp.getMat(ACCESS_READ).at<short>(i,j) );
|
||||||
/* imshow("diff.png", t*100);
|
/* imshow("diff.png", t*100);
|
||||||
imshow("cv.png", disp*100);
|
imshow("cv.png", disp*100);
|
||||||
imshow("ocl.png", udisp.getMat(ACCESS_READ)*100);
|
imshow("ocl.png", udisp.getMat(ACCESS_READ)*100);
|
||||||
waitKey(0);*/
|
waitKey(0);*/
|
||||||
Near(1e-3);
|
// Near(1e-3);
|
||||||
}
|
}
|
||||||
|
|
||||||
OCL_INSTANTIATE_TEST_CASE_P(StereoMatcher, StereoBMFixture, testing::Combine(testing::Values(32, 64, 128),
|
OCL_INSTANTIATE_TEST_CASE_P(StereoMatcher, StereoBMFixture, testing::Combine(testing::Values(32, 64, 128),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user