本文整理汇总了C++中DImage::shearedH方法的典型用法代码示例。如果您正苦于以下问题:C++ DImage::shearedH方法的具体用法?C++ DImage::shearedH怎么用?C++ DImage::shearedH使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DImage
的用法示例。
在下文中一共展示了DImage::shearedH方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fillMaskFlipped
void
mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
// check for proper number and size of arguments
//errCheck(nrhs == 1,"Arguments: filePath");
//errCheck(nlhs == 1,"Outputs: skew");
std::string inDir = mxArrayToString(prhs[0]);
std::string filePath = mxArrayToString(prhs[1]);
std::string dirPath = mxArrayToString(prhs[2]);
double slant = mxGetScalar(prhs[3]);
bool VIZ=false;
/*if (filePath.compare("wordimg_9")==0 ||
filePath.compare("wordimg_78")==0 )
VIZ=true;
*/
//DImage img(("tmp/"+filePath+".tif").c_str(),DImage::DFileFormat_tiff);
Mat mat = imread(inDir+filePath, CV_LOAD_IMAGE_GRAYSCALE);
//cout << "read image" <<endl;
//TODO clean
Mat initBin = Binarization::otsuBinarization(mat);
if (VIZ)
{Binarization::imshowB("otsu",initBin,255,0); waitKey();}
Mat dilated = Binarization::dilate(initBin,3);//dilate the fg, shrinking the bg
//cout << "dilated" <<endl;
Mat dilatedFlip = dilated.clone();
for (int r=0; r<dilatedFlip.rows; r++)
for (int c=0; c<dilatedFlip.cols; c++)
{
if (dilatedFlip.at<unsigned char>(r,c)==1)
dilatedFlip.at<unsigned char>(r,c)=0;
else
dilatedFlip.at<unsigned char>(r,c)=1;
}
Mat prime;
Mat bg_estimation = Binarization::inpainting(mat,dilatedFlip,&prime);
//cout << "inpainted" <<endl;
if (VIZ)
{imshow("bg_estimation",bg_estimation); waitKey();}
double average, std;
Binarization::extract_feat(prime, NULL, &average, &std);
bg_estimation = Binarization::inpainting(mat,dilatedFlip,NULL,&average,&std);
//cout << "found avg" <<endl;
DImage img;
convertMatToDImage(mat,&img);
//cout << "converted" <<endl;
int pad=255;
img = img.shearedH(slant,pad,true);//fill corners with black
//cout << "sheared" <<endl;
convertDImageToMat(img,&mat);
//cout << "converted back" <<endl;
if (VIZ)
{imshow("sheared",mat); waitKey();}
//fill corners
Mat fillMaskFlipped(mat.rows,mat.cols,CV_8U,Scalar(1));
for (int r=fillMaskFlipped.rows-1; r>=0; r--)
for (int c=0; c<fillMaskFlipped.cols; c++)
{
int flag = (abs(mat.at<unsigned char>(r,c)-pad)<3 ||
abs(mat.at<unsigned char>(r+1,c-1)-pad)<3 ||
abs(mat.at<unsigned char>(r-1,c+1)-pad)<3)?0:1;
fillMaskFlipped.at<unsigned char>(r,c)=flag;
}
/*
int space=1;
//for (int r=fillMaskFlipped.rows-1; r>fillMaskFlipped.rows-1-space; r--)
// for (int c=0; c<space; c++)
// {
// int flag = (abs(mat.at<unsigned char>(r,c)-pad)<3)?0:1;
// fillMaskFlipped.at<unsigned char>(r,c)=flag;
// }
for (int r=fillMaskFlipped.rows-1; r>=0; r--)
for (int c=0; c<space; c++)
{
int flag = (abs(mat.at<unsigned char>(r,c)-pad)<3)?0:1;
fillMaskFlipped.at<unsigned char>(r,c)=flag;
}
for (int c=0; c<fillMaskFlipped.cols; c++)
for (int r=fillMaskFlipped.rows-1; r>fillMaskFlipped.rows-1-space; r--)
{
int flag = (abs(mat.at<unsigned char>(r,c)-pad)<3)?0:1;
fillMaskFlipped.at<unsigned char>(r,c)=flag;
}
for (int c=0; c<fillMaskFlipped.cols-space; c++)
{
//.........这里部分代码省略.........