mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 22:44:02 +08:00
changed kernel.set to support unsuccssful set
This commit is contained in:
parent
66ed6a8a50
commit
eb2e8a11fa
@ -599,17 +599,6 @@ protected:
|
||||
|
||||
CV_EXPORTS MatAllocator* getOpenCLAllocator();
|
||||
|
||||
#define SAFE_KERNEL_SET_ARG(idx, arg) \
|
||||
{\
|
||||
int idxNew = kernel.set(idx, arg); \
|
||||
if (-1 == idxNew)\
|
||||
{\
|
||||
printf("algorithm can't setup argument index = %d to kernel\n", idx); \
|
||||
return false; \
|
||||
}\
|
||||
idx = idxNew; \
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
@ -2796,7 +2796,8 @@ int Kernel::set(int i, const void* value, size_t sz)
|
||||
{
|
||||
if (!p || !p->handle)
|
||||
return -1;
|
||||
CV_Assert(i >= 0);
|
||||
if (i < 0)
|
||||
return i;
|
||||
if( i == 0 )
|
||||
p->cleanupUMats();
|
||||
|
||||
@ -2822,7 +2823,8 @@ int Kernel::set(int i, const KernelArg& arg)
|
||||
{
|
||||
if( !p || !p->handle )
|
||||
return -1;
|
||||
CV_Assert( i >= 0 );
|
||||
if (i < 0)
|
||||
return i;
|
||||
if( i == 0 )
|
||||
p->cleanupUMats();
|
||||
if( arg.m )
|
||||
|
@ -726,7 +726,6 @@ namespace cv
|
||||
ocl::Image2D imageI(I);
|
||||
ocl::Image2D imageJ(J);
|
||||
int idxArg = 0;
|
||||
#if 0
|
||||
idxArg = kernel.set(idxArg, imageI); //image2d_t I
|
||||
idxArg = kernel.set(idxArg, imageJ); //image2d_t J
|
||||
idxArg = kernel.set(idxArg, ocl::KernelArg::PtrReadOnly(prevPts)); // __global const float2* prevPts
|
||||
@ -744,26 +743,6 @@ namespace cv
|
||||
idxArg = kernel.set(idxArg, (int)winSize.height); // int c_winSize_y
|
||||
idxArg = kernel.set(idxArg, (int)iters); // int c_iters
|
||||
idxArg = kernel.set(idxArg, (char)calcErr); //char calcErr
|
||||
#else
|
||||
SAFE_KERNEL_SET_ARG(idxArg, imageI); //image2d_t I
|
||||
SAFE_KERNEL_SET_ARG(idxArg, imageJ); //image2d_t J
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadOnly(prevPts)); // __global const float2* prevPts
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)prevPts.step); // int prevPtsStep
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadWrite(nextPts)); // __global const float2* nextPts
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)nextPts.step); // int nextPtsStep
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadWrite(status)); // __global uchar* status
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadWrite(err)); // __global float* err
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)level); // const int level
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)I.rows); // const int rows
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)I.cols); // const int cols
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)patch.x); // int PATCH_X
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)patch.y); // int PATCH_Y
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)winSize.width); // int c_winSize_x
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)winSize.height); // int c_winSize_y
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)iters); // int c_iters
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (char)calcErr); //char calcErr
|
||||
#endif
|
||||
|
||||
return kernel.run(2, globalThreads, localThreads, true);
|
||||
}
|
||||
private:
|
||||
|
@ -204,7 +204,6 @@ bool cv_ocl_tvl1flow::centeredGradient(const UMat &src, UMat &dx, UMat &dy)
|
||||
return false;
|
||||
|
||||
int idxArg = 0;
|
||||
#if 0
|
||||
idxArg = kernel.set(idxArg, ocl::KernelArg::PtrReadOnly(src));//src mat
|
||||
idxArg = kernel.set(idxArg, (int)(src.cols));//src mat col
|
||||
idxArg = kernel.set(idxArg, (int)(src.rows));//src mat rows
|
||||
@ -212,15 +211,6 @@ bool cv_ocl_tvl1flow::centeredGradient(const UMat &src, UMat &dx, UMat &dy)
|
||||
idxArg = kernel.set(idxArg, ocl::KernelArg::PtrWriteOnly(dx));//res mat dx
|
||||
idxArg = kernel.set(idxArg, ocl::KernelArg::PtrWriteOnly(dy));//res mat dy
|
||||
idxArg = kernel.set(idxArg, (int)(dx.step/dx.elemSize()));//res mat step
|
||||
#else
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadOnly(src));
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(src.cols));
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(src.rows));
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(src.step / src.elemSize()));
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrWriteOnly(dx));
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrWriteOnly(dy));
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(dx.step / dx.elemSize()));
|
||||
#endif
|
||||
return kernel.run(2, globalsize, NULL, false);
|
||||
}
|
||||
|
||||
@ -235,7 +225,6 @@ bool cv_ocl_tvl1flow::warpBackward(const UMat &I0, const UMat &I1, UMat &I1x, UM
|
||||
return false;
|
||||
|
||||
int idxArg = 0;
|
||||
#if 0
|
||||
idxArg = kernel.set(idxArg, ocl::KernelArg::PtrReadOnly(I0));//I0 mat
|
||||
int I0_step = (int)(I0.step / I0.elemSize());
|
||||
idxArg = kernel.set(idxArg, I0_step);//I0_step
|
||||
@ -265,37 +254,6 @@ bool cv_ocl_tvl1flow::warpBackward(const UMat &I0, const UMat &I1, UMat &I1x, UM
|
||||
u2_offset_x = (int) (u2_offset_x / u2.elemSize());
|
||||
idxArg = kernel.set(idxArg, (int)u2_offset_x);//u2_offset_x
|
||||
idxArg = kernel.set(idxArg, (int)(u2.offset / u2.step));//u2_offset_y
|
||||
#else
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadOnly(I0));//I0 mat
|
||||
int I0_step = (int)(I0.step / I0.elemSize());
|
||||
SAFE_KERNEL_SET_ARG(idxArg, I0_step);//I0_step
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(I0.cols));//I0_col
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(I0.rows));//I0_row
|
||||
ocl::Image2D imageI1(I1);
|
||||
ocl::Image2D imageI1x(I1x);
|
||||
ocl::Image2D imageI1y(I1y);
|
||||
SAFE_KERNEL_SET_ARG(idxArg, imageI1);//image2d_t tex_I1
|
||||
SAFE_KERNEL_SET_ARG(idxArg, imageI1x);//image2d_t tex_I1x
|
||||
SAFE_KERNEL_SET_ARG(idxArg, imageI1y);//image2d_t tex_I1y
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadOnly(u1));//const float* u1
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(u1.step / u1.elemSize()));//int u1_step
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadOnly(u2));//const float* u2
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrWriteOnly(I1w));///float* I1w
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrWriteOnly(I1wx));//float* I1wx
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrWriteOnly(I1wy));//float* I1wy
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrWriteOnly(grad));//float* grad
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrWriteOnly(rho));//float* rho
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(I1w.step / I1w.elemSize()));//I1w_step
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(u2.step / u2.elemSize()));//u2_step
|
||||
int u1_offset_x = (int)((u1.offset) % (u1.step));
|
||||
u1_offset_x = (int)(u1_offset_x / u1.elemSize());
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)u1_offset_x);//u1_offset_x
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(u1.offset / u1.step));//u1_offset_y
|
||||
int u2_offset_x = (int)((u2.offset) % (u2.step));
|
||||
u2_offset_x = (int)(u2_offset_x / u2.elemSize());
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)u2_offset_x);//u2_offset_x
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(u2.offset / u2.step));//u2_offset_y
|
||||
#endif
|
||||
return kernel.run(2, globalsize, NULL, false);
|
||||
}
|
||||
|
||||
@ -311,7 +269,6 @@ bool cv_ocl_tvl1flow::estimateU(UMat &I1wx, UMat &I1wy, UMat &grad,
|
||||
return false;
|
||||
|
||||
int idxArg = 0;
|
||||
#if 0
|
||||
idxArg = kernel.set(idxArg, ocl::KernelArg::PtrReadOnly(I1wx)); //const float* I1wx
|
||||
idxArg = kernel.set(idxArg, (int)(I1wx.cols)); //int I1wx_col
|
||||
idxArg = kernel.set(idxArg, (int)(I1wx.rows)); //int I1wx_row
|
||||
@ -339,35 +296,7 @@ bool cv_ocl_tvl1flow::estimateU(UMat &I1wx, UMat &I1wy, UMat &grad,
|
||||
idxArg = kernel.set(idxArg, (int)u2_offset_x ); //int u2_offset_x
|
||||
idxArg = kernel.set(idxArg, (int)(u2.offset / u2.step)); //int u2_offset_y
|
||||
idxArg = kernel.set(idxArg, (char)calc_error); //char calc_error
|
||||
#else
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadOnly(I1wx)); //const float* I1wx
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(I1wx.cols)); //int I1wx_col
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(I1wx.rows)); //int I1wx_row
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(I1wx.step / I1wx.elemSize())); //int I1wx_step
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadOnly(I1wy)); //const float* I1wy
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadOnly(grad)); //const float* grad
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadOnly(rho_c)); //const float* rho_c
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadOnly(p11)); //const float* p11
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadOnly(p12)); //const float* p12
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadOnly(p21)); //const float* p21
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadOnly(p22)); //const float* p22
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadWrite(u1)); //float* u1
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(u1.step / u1.elemSize())); //int u1_step
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadWrite(u2)); //float* u2
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrWriteOnly(error)); //float* error
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (float)l_t); //float l_t
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (float)theta); //float theta
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(u2.step / u2.elemSize()));//int u2_step
|
||||
int u1_offset_x = (int)(u1.offset % u1.step);
|
||||
u1_offset_x = (int)(u1_offset_x / u1.elemSize());
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)u1_offset_x); //int u1_offset_x
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(u1.offset / u1.step)); //int u1_offset_y
|
||||
int u2_offset_x = (int)(u2.offset % u2.step);
|
||||
u2_offset_x = (int)(u2_offset_x / u2.elemSize());
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)u2_offset_x); //int u2_offset_x
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(u2.offset / u2.step)); //int u2_offset_y
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (char)calc_error); //char calc_error
|
||||
#endif
|
||||
|
||||
return kernel.run(2, globalsize, NULL, false);
|
||||
}
|
||||
|
||||
@ -381,7 +310,6 @@ bool cv_ocl_tvl1flow::estimateDualVariables(UMat &u1, UMat &u2,
|
||||
return false;
|
||||
|
||||
int idxArg = 0;
|
||||
#if 0
|
||||
idxArg = kernel.set(idxArg, ocl::KernelArg::PtrReadOnly(u1));// const float* u1
|
||||
idxArg = kernel.set(idxArg, (int)(u1.cols)); //int u1_col
|
||||
idxArg = kernel.set(idxArg, (int)(u1.rows)); //int u1_row
|
||||
@ -402,33 +330,11 @@ bool cv_ocl_tvl1flow::estimateDualVariables(UMat &u1, UMat &u2,
|
||||
u2_offset_x = (int)(u2_offset_x / u2.elemSize());
|
||||
idxArg = kernel.set(idxArg, u2_offset_x); //int u2_offset_x
|
||||
idxArg = kernel.set(idxArg, (int)(u2.offset / u2.step)); //int u2_offset_y
|
||||
#else
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadOnly(u1));// const float* u1
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(u1.cols)); //int u1_col
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(u1.rows)); //int u1_row
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(u1.step / u1.elemSize())); //int u1_step
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadOnly(u2)); // const float* u2
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadWrite(p11)); // float* p11
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(p11.step / p11.elemSize())); //int p11_step
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadWrite(p12)); // float* p12
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadWrite(p21)); // float* p21
|
||||
SAFE_KERNEL_SET_ARG(idxArg, ocl::KernelArg::PtrReadWrite(p22)); // float* p22
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (float)(taut)); //float taut
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(u2.step / u2.elemSize())); //int u2_step
|
||||
int u1_offset_x = (int)(u1.offset % u1.step);
|
||||
u1_offset_x = (int)(u1_offset_x / u1.elemSize());
|
||||
SAFE_KERNEL_SET_ARG(idxArg, u1_offset_x); //int u1_offset_x
|
||||
SAFE_KERNEL_SET_ARG(idxArg, (int)(u1.offset / u1.step)); //int u1_offset_y
|
||||
int u2_offset_x = (int)(u2.offset % u2.step);
|
||||
u2_offset_x = (int)(u2_offset_x / u2.elemSize());
|
||||
SAFE_KERNEL_SET_ARG(idxArg, u2_offset_x); //int u2_offset_x
|
||||
idxArg = kernel.set(idxArg, (int)(u2.offset / u2.step)); //int u2_offset_y
|
||||
#endif
|
||||
|
||||
return kernel.run(2, globalsize, NULL, false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
OpticalFlowDual_TVL1::OpticalFlowDual_TVL1()
|
||||
{
|
||||
tau = 0.25;
|
||||
|
Loading…
Reference in New Issue
Block a user