{
Size src_size = src.size();
- // Delete those two clause below which exist before, However, the result is alos correct
+ // Delete those two clause below which exist before, However, the result is also correct
// dst.create(src_size, src.type());
// dst = Scalar(0.0);
{
Filter2DEngine_GPU::apply(src, dst);
- //if (iters > 1)
- //{
- // Size wholesize;
- // Point ofs;
- // dst.locateROI(wholesize,ofs);
- // int rows = dst.rows, cols = dst.cols;
- // dst.adjustROI(ofs.y,-ofs.y-rows+dst.wholerows,ofs.x,-ofs.x-cols+dst.wholecols);
- // dst.copyTo(morfBuf);
- // dst.adjustROI(-ofs.y,ofs.y+rows-dst.wholerows,-ofs.x,ofs.x+cols-dst.wholecols);
- // morfBuf.adjustROI(-ofs.y,ofs.y+rows-dst.wholerows,-ofs.x,ofs.x+cols-dst.wholecols);
- // //morfBuf.create(src.size(),src.type());
- // //Filter2DEngine_GPU::apply(dst, morfBuf);
- // //morfBuf.copyTo(dst);
- //}
for (int i = 1; i < iters; ++i)
{
- //dst.swap(morfBuf);
Size wholesize;
Point ofs;
dst.locateROI(wholesize, ofs);
virtual void apply(const oclMat &src, oclMat &dst, Rect roi = Rect(0, 0, -1, -1))
{
Size src_size = src.size();
- //int src_type = src.type();
int cn = src.oclchannels();
- //dst.create(src_size, src_type);
- //dst = Scalar(0.0);
- //dstBuf.create(src_size, src_type);
dstBuf.create(src_size.height + ksize.height - 1, src_size.width, CV_MAKETYPE(CV_32F, cn));
- //dstBuf = Scalar(0.0);
normalizeROI(roi, ksize, anchor, src_size);
srcROI = src(roi);
dstROI = dst(roi);
- //dstBufROI = dstBuf(roi);
(*rowFilter)(srcROI, dstBuf);
- //Mat rm(dstBufROI);
- //std::cout << "rm " << rm << endl;
(*columnFilter)(dstBuf, dstROI);
}
CV_Assert(src.oclchannels() == dst.oclchannels());
CV_Assert(ksize == (anchor << 1) + 1);
int src_pix_per_row, dst_pix_per_row;
- //int src_offset_x, src_offset_y;
int dst_offset_in_pixel;
src_pix_per_row = src.step / src.elemSize();
- //src_offset_x = (src.offset % src.step) / src.elemSize();
- //src_offset_y = src.offset / src.step;
dst_pix_per_row = dst.step / dst.elemSize();
dst_offset_in_pixel = dst.offset / dst.elemSize();
args.push_back(make_pair(sizeof(cl_int), (void *)&src.wholecols));
args.push_back(make_pair(sizeof(cl_int), (void *)&src.wholerows));
args.push_back(make_pair(sizeof(cl_int), (void *)&src_pix_per_row));
- //args.push_back(make_pair(sizeof(cl_int),(void*)&src_offset_x));
- //args.push_back(make_pair(sizeof(cl_int),(void*)&src_offset_y));
args.push_back(make_pair(sizeof(cl_int), (void *)&dst_pix_per_row));
args.push_back(make_pair(sizeof(cl_int), (void *)&dst_offset_in_pixel));
args.push_back(make_pair(sizeof(cl_mem), (void *)&mat_kernel.data));
linearColumnFilter_gpu<int>,
linearColumnFilter_gpu<float>
};
- /*
- CV_Assert(dstType == CV_8UC4 || dstType == CV_8SC4 || dstType == CV_16UC2 ||
- dstType == CV_16SC2 || dstType == CV_32SC1 || dstType == CV_32FC1);
- CV_Assert(bufType == CV_8UC4 || bufType == CV_8SC4 || bufType == CV_16UC2 ||
- bufType == CV_16SC2 || bufType == CV_32SC1 || bufType == CV_32FC1);
-
- Mat temp(columnKernel.size(), CV_32SC1);
- columnKernel.convertTo(temp, CV_32SC1);
- Mat cont_krnl = temp.reshape(1, 1);
- */
+
Mat temp = columnKernel.reshape(1, 1);
oclMat mat_kernel(temp);
int ksize = temp.cols;
-
- //CV_Assert(ksize < 16);
-
normalizeAnchor(anchor, ksize);
return Ptr<BaseColumnFilter_GPU>(new GpuLinearColumnFilter(ksize, anchor, mat_kernel,
}
if (ddepth < 0)
- {
ddepth = src.depth();
- }
- //CV_Assert(ddepth == src.depth());
dst.create(src.size(), CV_MAKETYPE(ddepth, src.channels()));
Ptr<FilterEngine_GPU> f = createSeparableLinearFilter_GPU(src.type(), dst.type(), kernelX, kernelY, anchor, delta, bordertype);
// usually the smoothing part is the slowest to compute,
// so try to scale it instead of the faster differenciating part
if (dx == 0)
- {
kx *= scale;
- }
else
- {
ky *= scale;
- }
}
- // Mat kx_, ky_;
- //ky.convertTo(ky_,CV_32S,1<<8);
- //kx.convertTo(kx_,CV_32S,1<<8);
-
sepFilter2D(src, dst, ddepth, kx, ky, Point(-1, -1), delta, borderType);
}
// usually the smoothing part is the slowest to compute,
// so try to scale it instead of the faster differenciating part
if (dx == 0)
- {
kx *= scale;
- }
else
- {
ky *= scale;
- }
}
- // Mat kx_, ky_;
- //ky.convertTo(ky_,CV_32S,1<<8);
- //kx.convertTo(kx_,CV_32S,1<<8);
-
sepFilter2D(src, dst, ddepth, kx, ky, Point(-1, -1), delta, bordertype);
}
Mat kernel(3, 3, CV_32S, (void *)K[ksize == 3]);
if (scale != 1)
- {
kernel *= scale;
- }
filter2D(src, dst, ddepth, kernel, Point(-1, -1));
}
// automatic detection of kernel size from sigma
if (ksize.width <= 0 && sigma1 > 0)
- {
ksize.width = cvRound(sigma1 * (depth == CV_8U ? 3 : 4) * 2 + 1) | 1;
- }
if (ksize.height <= 0 && sigma2 > 0)
- {
ksize.height = cvRound(sigma2 * (depth == CV_8U ? 3 : 4) * 2 + 1) | 1;
- }
CV_Assert(ksize.width > 0 && ksize.width % 2 == 1 && ksize.height > 0 && ksize.height % 2 == 1);
Mat ky;
if (ksize.height == ksize.width && std::abs(sigma1 - sigma2) < DBL_EPSILON)
- {
ky = kx;
- }
else
- {
ky = getGaussianKernel(ksize.height, sigma2, std::max(depth, CV_32F));
- }
- //Mat kx_, ky_;
- //kx.convertTo(kx_,CV_32S,1<<8);
- //ky.convertTo(ky_,CV_32S,1<<8);
return createSeparableLinearFilter_GPU(type, type, kx, ky, Point(-1, -1), 0.0, bordertype);
}
if (bordertype != BORDER_CONSTANT)
{
if (src.rows == 1)
- {
ksize.height = 1;
- }
if (src.cols == 1)
- {
ksize.width = 1;
- }
}
Ptr<FilterEngine_GPU> f = createGaussianFilter_GPU(src.type(), ksize, sigma1, sigma2, bordertype);
{
lut.at<float>(idx++) = sigma2 / (sigma2 + x * x + y * y);
}
+
oclMat dlut(lut);
int depth = src.depth();
int cn = src.oclchannels();
kernelName = "remapNNF1Constant";
}
- //int channels = dst.oclchannels();
- //int depth = dst.depth();
- //int type = src.type();
size_t blkSizeX = 16, blkSizeY = 16;
size_t glbSizeX;
int cols = dst.cols;
openCLExecuteKernel(clCxt, &imgproc_median, kernelName, globalThreads, localThreads, args, src.oclchannels(), src.depth());
}
else
- {
CV_Error(CV_StsUnsupportedFormat, "Non-supported filter length");
- //string kernelName = "medianFilter";
- //args.push_back( make_pair( sizeof(cl_int),(void*)&m));
-
- //openCLExecuteKernel(clCxt,&imgproc_median,kernelName,globalThreads,localThreads,args,src.oclchannels(),-1);
- }
-
}
////////////////////////////////////////////////////////////////////////
// copyMakeBorder
void copyMakeBorder(const oclMat &src, oclMat &dst, int top, int bottom, int left, int right, int bordertype, const Scalar &scalar)
{
- //CV_Assert(src.oclchannels() != 2);
CV_Assert(top >= 0 && bottom >= 0 && left >= 0 && right >= 0);
if((dst.cols != dst.wholecols) || (dst.rows != dst.wholerows)) //has roi
{
{
CV_Assert((src.cols >= left) && (src.cols >= right) && (src.rows >= top) && (src.rows >= bottom));
}
+
if(bordertype == cv::BORDER_REFLECT_101)
{
CV_Assert((src.cols > left) && (src.cols > right) && (src.rows > top) && (src.rows > bottom));
}
+
dst.create(src.rows + top + bottom, src.cols + left + right, src.type());
int srcStep = src.step1() / src.oclchannels();
int dstStep = dst.step1() / dst.oclchannels();
}
openCLExecuteKernel(src.clCxt, &imgproc_copymakeboder, kernelName, globalThreads, localThreads, args, -1, -1, compile_option);
- //uchar* cputemp=new uchar[32*dst.wholerows];
- ////int* cpudata=new int[this->step*this->wholerows/sizeof(int)];
- //openCLSafeCall(clEnqueueReadBuffer(src.clCxt->impl->clCmdQueue, (cl_mem)dst.data, CL_TRUE,
- // 0, 32*dst.wholerows, cputemp, 0, NULL, NULL));
- //for(int i=0;i<dst.wholerows;i++)
- //{
- // for(int j=0;j<dst.wholecols;j++)
- // {
- // cout<< (int)cputemp[i*32+j]<<" ";
- // }
- // cout<<endl;
- //}
- //delete []cputemp;
}
////////////////////////////////////////////////////////////////////////
if( src.depth() != CV_8U || src.oclchannels() != 4 )
CV_Error( CV_StsUnsupportedFormat, "Only 8-bit, 4-channel images are supported" );
- // if(!src.clCxt->supportsFeature(Context::CL_DOUBLE))
- // {
- // CV_Error( CV_GpuNotSupported, "Selected device doesn't support double, so a deviation exists.\nIf the accuracy is acceptable, the error can be ignored.\n");
- // }
-
dst.create( src.size(), CV_8UC4 );
if( !(criteria.type & TermCriteria::MAX_ITER) )