本文整理汇总了C++中DImage::width方法的典型用法代码示例。如果您正苦于以下问题:C++ DImage::width方法的具体用法?C++ DImage::width怎么用?C++ DImage::width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DImage
的用法示例。
在下文中一共展示了DImage::width方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getImageVerticalProfile
/**Each row of img is projected onto the vertical axis. Resulting
data length will be equal to the height of img. The profile is a summation
of the grayscale values in each row. If fNormalize is true, then each value
is divided by img.width() so it is the average grayscale value for the row
instead of the sum.
If fNormalize is true, the resulting profile values are divided by the image
width.
*/
void DProfile::getImageVerticalProfile(const DImage &img, bool fNormalize){
int w, h;
w = img.width();
h = img.height();
// allocate the rgProf array
if(NULL == rgProf){
rgProf = (double*)malloc(h * sizeof(double));
D_CHECKPTR(rgProf);
len = h;
}
else{
if(len != h){
rgProf = (double*)realloc(rgProf,h*sizeof(double));
D_CHECKPTR(rgProf);
len = h;
}
}
switch(img.getImageType()){
case DImage::DImage_u8:
{
D_uint8 *pu8;
pu8=img.dataPointer_u8();
for(int y = 0, idx=0; y < h; ++y){
rgProf[y] = 0.;
for(int x = 0; x < w; ++x, ++idx){
rgProf[y] += pu8[idx];
}
if(fNormalize)
rgProf[y] /= w;
}
}
break;
case DImage::DImage_flt_multi:
{
float *pflt;
if(img.numChannels() > 1){
fprintf(stderr,"DProfile::getImageVerticalProfile() floats only "
"supported with a single channel\n");
abort();
}
pflt=img.dataPointer_flt(0);
for(int y = 0, idx=0; y < h; ++y){
rgProf[y] = 0.;
for(int x = 0; x < w; ++x, ++idx){
rgProf[y] += pflt[idx];
}
if(fNormalize)
rgProf[y] /= w;
}
}
break;
default:
fprintf(stderr, "Not yet implemented!\n");
abort();
}//end switch(img.getImageType())
}
示例2: getHorizMaxRunlengthProfile
/**Max runlength in each column of img is projected onto the horizontal axis.
Resulting data length will be equal to the width of img.
If fNormalize is true, each profile value will be divided by image height,
so the value is a fraction of the image height instead of a number of pixels.
*/
void DProfile::getHorizMaxRunlengthProfile(const DImage &img, D_uint32 rgbVal,
bool fNormalize){
int w, h;
unsigned int *rgRunlengths;
w = img.width();
h = img.height();
// allocate the rgProf array
if(NULL == rgProf){
rgProf = (double*)malloc(w * sizeof(double));
D_CHECKPTR(rgProf);
len = w;
}
else{
if(len != w){
rgProf = (double*)realloc(rgProf,w*sizeof(double));
D_CHECKPTR(rgProf);
len = w;
}
}
rgRunlengths = (unsigned int*)malloc(sizeof(unsigned int)*w);
D_CHECKPTR(rgRunlengths);
memset(rgRunlengths, 0, sizeof(unsigned int)*w);
memset(rgProf, 0, sizeof(double) * w);
switch(img.getImageType()){
case DImage::DImage_u8:
{
D_uint8 *pu8;
pu8=img.dataPointer_u8();
for(int y = 0, idx=0; y < h; ++y){
for(int x = 0; x < w; ++x, ++idx){
if((D_uint8)rgbVal == pu8[idx]){//increment run length for this col
++(rgRunlengths[x]);
if(rgRunlengths[x] > rgProf[x])
rgProf[x] = (double)rgRunlengths[x];
}
else{
rgRunlengths[x] = 0;
}
}
}
if(fNormalize){
for(int x = 0; x < w; ++x)
rgProf[x] /= h;
}
}
break;
default:
fprintf(stderr, "Not yet implemented!\n");
abort();
}//end switch(img.getImageType())
free(rgRunlengths);
}
示例3: getVertAvgRunlengthProfile
/**Avg runlength in each column of img is projected onto the vertical axis.
Resulting data length will be equal to the height of img.
If fNormalize is true, each profile value will be divided by image width,
so the value is a fraction of the image width instead of a number of pixels.
*/
void DProfile::getVertAvgRunlengthProfile(const DImage &img, D_uint32 rgbVal,
bool fNormalize){
int w, h;
unsigned int runLength, numRuns;
w = img.width();
h = img.height();
// allocate the rgProf array
if(NULL == rgProf){
rgProf = (double*)malloc(h * sizeof(double));
D_CHECKPTR(rgProf);
len = h;
}
else{
if(len != h){
rgProf = (double*)realloc(rgProf,h*sizeof(double));
D_CHECKPTR(rgProf);
len = h;
}
}
switch(img.getImageType()){
case DImage::DImage_u8:
{
D_uint8 *pu8;
pu8=img.dataPointer_u8();
for(int y = 0, idx=0; y < h; ++y){
rgProf[y] = 0.;
runLength = 0;
numRuns = 0;
for(int x = 0; x < w; ++x, ++idx){
if((D_uint8)rgbVal == pu8[idx]){//increment run length for this row
if(0==runLength)
++numRuns;
++runLength;
++(rgProf[y]);
}
else{
runLength = 0;
}
}
if(numRuns > 0)
rgProf[y] /= numRuns; //(we have sum and need to divide for avg)
if(fNormalize)
rgProf[y] /= w;
}
}
break;
default:
fprintf(stderr, "Not yet implemented!\n");
abort();
}//end switch(img.getImageType())
}
示例4: Laplacian
void OpticalFlow::Laplacian(DImage &output, const DImage &input, const DImage& weight)
{
if(output.matchDimension(input)==false)
output.allocate(input);
output.reset();
if(input.matchDimension(weight)==false)
{
cout<<"Error in image dimension matching OpticalFlow::Laplacian()!"<<endl;
return;
}
const _FlowPrecision *inputData=input.data(),*weightData=weight.data();
int width=input.width(),height=input.height();
DImage foo(width,height);
_FlowPrecision *fooData=foo.data(),*outputData=output.data();
// horizontal filtering
for(int i=0;i<height;i++)
for(int j=0;j<width-1;j++)
{
int offset=i*width+j;
fooData[offset]=(inputData[offset+1]-inputData[offset])*weightData[offset];
}
for(int i=0;i<height;i++)
for(int j=0;j<width;j++)
{
int offset=i*width+j;
if(j<width-1)
outputData[offset]-=fooData[offset];
if(j>0)
outputData[offset]+=fooData[offset-1];
}
foo.reset();
// vertical filtering
for(int i=0;i<height-1;i++)
for(int j=0;j<width;j++)
{
int offset=i*width+j;
fooData[offset]=(inputData[offset+width]-inputData[offset])*weightData[offset];
}
for(int i=0;i<height;i++)
for(int j=0;j<width;j++)
{
int offset=i*width+j;
if(i<height-1)
outputData[offset]-=fooData[offset];
if(i>0)
outputData[offset]+=fooData[offset-width];
}
}
示例5: SanityCheck
//--------------------------------------------------------------------------------------------------------
// function to do sanity check: imdx*du+imdy*dy+imdt=0
//--------------------------------------------------------------------------------------------------------
void OpticalFlow::SanityCheck(const DImage &imdx, const DImage &imdy, const DImage &imdt, double du, double dv)
{
if(imdx.matchDimension(imdy)==false || imdx.matchDimension(imdt)==false)
{
cout<<"The dimensions of the derivatives don't match!"<<endl;
return;
}
const _FlowPrecision* pImDx,*pImDy,*pImDt;
pImDx=imdx.data();
pImDy=imdy.data();
pImDt=imdt.data();
double error=0;
for(int i=0;i<imdx.height();i++)
for(int j=0;j<imdx.width();j++)
for(int k=0;k<imdx.nchannels();k++)
{
int offset=(i*imdx.width()+j)*imdx.nchannels()+k;
double temp=pImDx[offset]*du+pImDy[offset]*dv+pImDt[offset];
error+=fabs(temp);
}
error/=imdx.nelements();
cout<<"The mean error of |dx*u+dy*v+dt| is "<<error<<endl;
}
示例6: showFlow
bool OpticalFlow::showFlow(const DImage& flow,const char* filename)
{
if(flow.nchannels()!=1)
{
cout<<"The flow must be a single channel image!"<<endl;
return false;
}
Image<unsigned char> foo;
foo.allocate(flow.width(),flow.height());
double Max = flow.max();
double Min = flow.min();
for(int i = 0;i<flow.npixels(); i++)
foo[i] = (flow[i]-Min)/(Max-Min)*255;
foo.imwrite(filename);
}
示例7: getImageHorizontalProfile
/**Each column of img is projected onto the horizontal axis.
Resulting data length will be equal to the width of img.
If fNormalize is true, the resulting profile values are divided by the image
height.
*/
void DProfile::getImageHorizontalProfile(const DImage &img, bool fNormalize){
int w, h;
w = img.width();
h = img.height();
// allocate the rgProf array
if(NULL == rgProf){
rgProf = (double*)malloc(w * sizeof(double));
D_CHECKPTR(rgProf);
len = w;
}
else{
if(len != w){
rgProf = (double*)realloc(rgProf,w*sizeof(double));
D_CHECKPTR(rgProf);
len = w;
}
}
memset(rgProf, 0, sizeof(double) * w);
switch(img.getImageType()){
case DImage::DImage_u8:
{
D_uint8 *pu8;
pu8=img.dataPointer_u8();
for(int y = 0, idx=0; y < h; ++y){
for(int x = 0; x < w; ++x, ++idx){
rgProf[x] += pu8[idx];
}
}
if(fNormalize){
for(int x = 0; x < w; ++x)
rgProf[x] /= h;
}
}
break;
default:
fprintf(stderr, "Not yet implemented!\n");
abort();
}//end switch(img.getImageType())
}
示例8: ParImageToIplImage
cv::Mat ParImageToIplImage(DImage& img)
{
int width = img.width();
int height = img.height();
int nChannels = img.nchannels();
if(width <= 0 || height <= 0 || nChannels != 1)
return cv::Mat();
BaseType*& pData = img.data();
cv::Mat image = cv::Mat(height, width, CV_MAKETYPE(8, 1));
for(int i = 0;i < height;i++)
{
for(int j = 0;j < width;j++)
{
image.ptr<uchar>(i)[j] = pData[i*width + j] * 255;
}
}
return image;
}
示例9: memset
/** imgDst will be 2*radius pixels less wide and high than imgSrc
* because of the padding that is added before calling this function.
* This function requires that imgDst.create() has already been called
* with the proper w,h,imgType,etc.
*/
void DMaxFilter::maxFiltHuang_u8_square(DImage &imgDst,
const DImage &imgSrc,
int radiusX, int radiusY,
int wKern, int hKern,
D_uint8 *rgKern,
int numKernPxls,
DProgress *pProg,
int progStart, int progMax,
int threadNumber, int numThreads){
int rgHist[256];
int max;
unsigned char valTmp;
int idxDst;
int idx3;
D_uint8 *pTmp; // pointer to padded image data
int wTmp, hTmp; // width, height of imgSrc
int w, h; // width, height of imgDst
D_uint8 *pDst;
wTmp = imgSrc.width();
hTmp = imgSrc.height();
w = wTmp - radiusX*2;
h = hTmp - radiusY*2;
pDst = imgDst.dataPointer_u8();
pTmp = imgSrc.dataPointer_u8();
for(int y = threadNumber; y < h; y += numThreads){
// update progress report and check if user cancelled the operation
if((NULL != pProg) && (0 == (y & 0x0000003f))){
if(0 != pProg->reportStatus(progStart + y, 0, progMax)){
// the operation has been cancelled
pProg->reportStatus(-1, 0, progMax); // report cancel acknowledged
return;
}
}
// position window at the beginning of a new row and fill the kernel, hist
memset(rgHist, 0, sizeof(int)*256);
for(int kr = 0, kidx =0; kr < hKern; ++kr){
for(int kc = 0; kc < wKern; ++kc, ++kidx){
if(rgKern[kidx]){ // pixel is part of the kernel mask
++(rgHist[pTmp[(y+kr)*wTmp+kc]]);//add pixel val to histogram
}
}
}
// calculate max for first spot
for(max = 255; (max > 0) && (0==rgHist[max]); --max){
// do nothing
}
// put the max in the spot we're at
idxDst = y*w;
pDst[idxDst] = (unsigned char)max;
// remove pixels from leftmost column
idx3 = y*wTmp+radiusX;
for(int ky = 0; ky < hKern; ++ky){
valTmp = pTmp[idx3 - wKern];
--(rgHist[valTmp]);
if((valTmp==max)&&(0 == rgHist[valTmp])){//update the max
for(;(max>0)&&(0==rgHist[max]); --max){
//do nothing
}
}
idx3 += wTmp;
}
for(int x=1; x < w; ++x){
++idxDst;
// add pixels from the right-hand side of kernel (after moving over one)
idx3 = y*wTmp+x+radiusX;
for(int ky = 0; ky < hKern; ++ky){
valTmp = pTmp[idx3 + wKern];
if(valTmp > max)//update the max
max = valTmp;
++(rgHist[valTmp]);
idx3 += wTmp;
}
// put the max value in the destination pixel
pDst[idxDst] = (unsigned char)max;
// remove pixels from leftmost column for next time through loop
if(x < (w-1)){//don't need to remove left edge if going to a new row
idx3 = y*wTmp+x+radiusX;
for(int ky = 0; ky < hKern; ++ky){
valTmp = pTmp[idx3 - wKern];
--(rgHist[valTmp]);
if((valTmp==max)&&(0 == rgHist[valTmp])){//update the max
for(;(max>0)&&(0==rgHist[max]); --max){
//do nothing
}
}
idx3 += wTmp;
} // end for(ky...
//.........这里部分代码省略.........
示例10: SmoothFlowSOR
//--------------------------------------------------------------------------------------------------------
// function to compute optical flow field using two fixed point iterations
// Input arguments:
// Im1, Im2: frame 1 and frame 2
// warpIm2: the warped frame 2 according to the current flow field u and v
// u,v: the current flow field, NOTICE that they are also output arguments
//
//--------------------------------------------------------------------------------------------------------
void OpticalFlow::SmoothFlowSOR(const DImage &Im1, const DImage &Im2, DImage &warpIm2, DImage &u, DImage &v,
double alpha, int nOuterFPIterations, int nInnerFPIterations, int nSORIterations)
{
// DImage mask,imdx,imdy,imdt;
DImage imdx,imdy,imdt;
int imWidth,imHeight,nChannels,nPixels;
imWidth=Im1.width();
imHeight=Im1.height();
nChannels=Im1.nchannels();
nPixels=imWidth*imHeight;
DImage du(imWidth,imHeight),dv(imWidth,imHeight);
DImage uu(imWidth,imHeight),vv(imWidth,imHeight);
DImage ux(imWidth,imHeight),uy(imWidth,imHeight);
DImage vx(imWidth,imHeight),vy(imWidth,imHeight);
DImage Phi_1st(imWidth,imHeight);
DImage Psi_1st(imWidth,imHeight,nChannels);
DImage imdxy,imdx2,imdy2,imdtdx,imdtdy;
DImage ImDxy,ImDx2,ImDy2,ImDtDx,ImDtDy;
DImage foo1,foo2;
double varepsilon_phi=pow(0.001,2);
double varepsilon_psi=pow(0.001,2);
//--------------------------------------------------------------------------
// the outer fixed point iteration
//--------------------------------------------------------------------------
for(int count=0;count<nOuterFPIterations;count++)
{
// compute the gradient
getDxs(imdx,imdy,imdt,Im1,warpIm2);
// generate the mask to set the weight of the pxiels moving outside of the image boundary to be zero
// genInImageMask(mask,u,v);
// set the derivative of the flow field to be zero
du.reset();
dv.reset();
//--------------------------------------------------------------------------
// the inner fixed point iteration
//--------------------------------------------------------------------------
for(int hh=0;hh<nInnerFPIterations;hh++)
{
// compute the derivatives of the current flow field
if(hh==0)
{
uu.copyData(u);
vv.copyData(v);
}
else
{
uu.Add(u,du);
vv.Add(v,dv);
}
uu.dx(ux);
uu.dy(uy);
vv.dx(vx);
vv.dy(vy);
// compute the weight of phi
Phi_1st.reset();
_FlowPrecision* phiData=Phi_1st.data();
double temp;
const _FlowPrecision *uxData,*uyData,*vxData,*vyData;
uxData=ux.data();
uyData=uy.data();
vxData=vx.data();
vyData=vy.data();
for(int i=0;i<nPixels;i++)
{
temp=uxData[i]*uxData[i]+uyData[i]*uyData[i]+vxData[i]*vxData[i]+vyData[i]*vyData[i];
phiData[i] = 0.5/sqrt(temp+varepsilon_phi);
}
// compute the nonlinear term of psi
Psi_1st.reset();
_FlowPrecision* psiData=Psi_1st.data();
const _FlowPrecision *imdxData,*imdyData,*imdtData;
const _FlowPrecision *duData,*dvData;
imdxData=imdx.data();
imdyData=imdy.data();
imdtData=imdt.data();
duData=du.data();
dvData=dv.data();
if(nChannels==1)
for(int i=0;i<nPixels;i++)
{
temp=imdtData[i]+imdxData[i]*duData[i]+imdyData[i]*dvData[i];
//.........这里部分代码省略.........
示例11: if
/** Takes profiles of numStrips vertical strips (plus numStrips-1
overlapping strips) and uses them to estimate the avg textline
height **/
int DTextlineSeparator::estimateAvgHeight2(DImage &imgBinary,
int numStrips,
char *stDebugBaseName){
int w, h;
D_uint8 *pu8;
DProfile prof;
DProfile *rgProfs;// profiles of overlapping strips of image
DProfile *rgProfsRL;//avg white RL profile
DProfile *rgProfsSmear;// profiles of overlapping strips of image after smear
char stTmp[1024];
int *rgPeakThresh;
int *rgPeakThreshRL;
double *rgPeakLineOffs;
rgProfs = new DProfile[numStrips*2-1];
D_CHECKPTR(rgProfs);
rgProfsRL = new DProfile[numStrips*2-1];
D_CHECKPTR(rgProfsRL);
rgProfsSmear = new DProfile[numStrips*2-1];
D_CHECKPTR(rgProfsSmear);
rgPeakThresh = new int[numStrips*2-1];
D_CHECKPTR(rgPeakThresh);
rgPeakThreshRL = new int[numStrips*2-1];
D_CHECKPTR(rgPeakThreshRL);
rgPeakLineOffs = new double[numStrips*2-1];
D_CHECKPTR(rgPeakLineOffs);
w = imgBinary.width();
h = imgBinary.height();
pu8 = imgBinary.dataPointer_u8();
for(int y=0, idx=0; y < h; ++y){
for(int x=0; x < w; ++x, ++idx){
if((pu8[idx] > 0) && (pu8[idx] < 255)){
fprintf(stderr, "DTextlineSeparator::estimateAvgHeight() requires "
"BINARY image with values of 0 or 255!\n");
exit(1);
}
}
}
DImage imgStrip;
int stripW, stripLeft;
DProfile profWeightedStrokeDist;
int **rgBlackSpacingHist;
rgBlackSpacingHist = new int*[numStrips*2-1];
D_CHECKPTR(rgBlackSpacingHist);
rgBlackSpacingHist[0]=new int[200*(numStrips*2-1)];
D_CHECKPTR(rgBlackSpacingHist[0]);
memset(rgBlackSpacingHist[0],0,sizeof(int)*200*(numStrips*2-1));
for(int i=1; i < (numStrips*2-1); ++i){
rgBlackSpacingHist[i] = &(rgBlackSpacingHist[i-1][200]);//only 2-199 are valid spacings
}
int **rgPeakYs;
int *rgNumPeaks;
int **rgValleyYs;
int *rgNumValleys;
rgPeakYs = new int*[numStrips*2-1];
D_CHECKPTR(rgPeakYs);
rgPeakYs[0] = new int[(numStrips*2-1)*h];
D_CHECKPTR(rgPeakYs[0]);
rgValleyYs = new int*[numStrips*2-1];
D_CHECKPTR(rgValleyYs);
rgValleyYs[0] = new int[(numStrips*2-1)*h];
D_CHECKPTR(rgValleyYs);
for(int i = 1; i < (numStrips*2-1); ++i){
rgPeakYs[i] = &(rgPeakYs[i-1][h]);
rgValleyYs[i] = &(rgValleyYs[i-1][h]);
}
rgNumPeaks = new int[numStrips*2-1];
D_CHECKPTR(rgNumPeaks);
rgNumValleys = new int[numStrips*2-1];
D_CHECKPTR(rgNumValleys);
for(int i=0; i < (numStrips*2-1); ++i){
rgNumPeaks[i] = 0;
rgNumValleys[i] = 0;
}
stripW = (w + numStrips-1) / numStrips;
printf("w=%d h=%d stripW=%d\n",w,h,stripW);
for(int i=0; i < numStrips*2-1; ++i){
stripLeft = i * stripW/2;
if(i == numStrips*2-2){//last strip may have slightly different width
stripW = w - stripLeft - 1;
}
imgBinary.copy_(imgStrip, stripLeft, 0, stripW, h);
rgProfs[i].getImageVerticalProfile(imgStrip,false);
rgProfs[i].smoothAvg(2);
rgProfsRL[i].getVertAvgRunlengthProfile(imgStrip,0xff,true);
rgProfsRL[i].smoothAvg(2);
double *pdbl;
pdbl = rgProfs[i].dataPointer();
//.........这里部分代码省略.........
示例12: getTextlineSlantAngleDeg
/**The slant angle is assumed to be between 60 and -45 degrees (0 deg=vertical,
* negative values are left-slanted, positive values right-slanted).
* To determine slant: at each x-position, the longest runlength at each angle
* is found and its squared value is added into the accumulator for that angle.
* The histogram is smoothed, and the angle corresponding to the highest value
* in the histogram is the returned angle (in degrees).
*
* Runlengths of less than rlThresh pixels are ignored.
*
* The image should be black(0) and white(255). The portion of the image
* specified by x0,y0 - x1,y1 is considered to be the textline of interest.
* If no coordinates are specified, then the entire image is used as the
* textline.
*
* If weight is not NULL, it will be the sum of max runlengths (not squared) at
* all 120 angles. Weights are used in determination of weighted average angle
* for all textlines in getAllTextlinesSlantAngleDeg() before adjusting angles.
*
* If rgSlantHist is not NULL, the squared max RL values in the angle histogram
* will be copied into the rgSlantHist array. It must already be allocated to
* 120*sizeof(unsigned int).
*
* if imgAngleHist is not NULL, then the image is set to w=120 and h=y1-y0+1.
* It is a (grayscale) graphical representation of what is in rgSlantHist.
*/
double DSlantAngle::getTextlineSlantAngleDeg(DImage &imgBW,
int rlThresh,
int x0,int y0,int x1,int y1,
double *weight,
unsigned int *rgSlantHist,
DImage *imgAngleHist){
int *rgLineSlantAngles;
int lineH;
int slantOffset, slantAngle, angle;
unsigned int rgSlantSums[120];
unsigned int rgSlantSumsTmp[120];
int runlen, maxrl; /* maximum slant runlen */
double slantDx;
int w, h;
D_uint8 *p8;
double dblWeight = 0;
w = imgBW.width();
h = imgBW.height();
p8 = imgBW.dataPointer_u8();
if(-1 == x1)
x1 = w-1;
if(-1 == y1)
y1 = h-1;
lineH = y1-y0+1;
/* estimate the predominant slant angle (0=vertical, +right, -left) */
slantOffset = (int)(0.5+ (lineH / 2.0) / tan(DMath::degreesToRadians(30.)));
for(int j = 0; j < 120; ++j){
rgSlantSums[j] = 0;
rgSlantSumsTmp[j] = 0;
}
for(angle = -45; angle <= 60; angle += 1){
/* at each x-position, sum the maximum run length at that angle into the
accumulator */
if(0 == angle) /* vertical, so tangent is infinity */
slantDx = 0.;
else
slantDx = -1.0 / tan(DMath::degreesToRadians(90-angle));
// for(j = slantOffset; j < (hdr.w-slantOffset); ++j){
for(int j = x0; j <= x1; ++j){
maxrl = 0;
runlen = 0;
for(int y = 0; y < lineH; ++y){
int x;
x = (int)(0.5+ j + y * slantDx);
if( (x>=x0) && (x <= x1)){ /* make sure we are within bounds */
int idxtmp;
idxtmp = (y+y0)*w+x;
// imgCoded[idxtmp*3] = 0;
if(0 == p8[idxtmp]){
++runlen;
if(runlen > maxrl){
maxrl = runlen;
}
}
else
runlen = 0;
} /* end if in bounds */
else{
runlen = 0; /* ignore runs that go off edge of image */
}
}
if(maxrl > rlThresh){
rgSlantSums[angle+45] += maxrl*maxrl;
dblWeight += maxrl;
}
} /* end for j */
} /* end for angle */
//smooth the histogram
rgSlantSumsTmp[0] = (rgSlantSums[0] + rgSlantSums[1]) / 2;
for(int aa = 1; aa < 119; ++aa){
rgSlantSumsTmp[aa]=(rgSlantSums[aa-1]+rgSlantSums[aa]+rgSlantSums[aa+1])/3;
//.........这里部分代码省略.........
示例13: warpFL
void OpticalFlow::warpFL(DImage &warpIm2, const DImage &Im1, const DImage &Im2, const DImage &Flow)
{
if(warpIm2.matchDimension(Im2)==false)
warpIm2.allocate(Im2.width(),Im2.height(),Im2.nchannels());
ImageProcessing::warpImageFlow(warpIm2.data(),Im1.data(),Im2.data(),Flow.data(),Im2.width(),Im2.height(),Im2.nchannels());
}
示例14: getTextlineRects
/** Takes profiles of numStrips vertical strips (plus numStrips-1
overlapping strips) and uses them to estimate the avg textline
height **/
void DTextlineSeparator::getTextlineRects(DImage &img, int *numTextlines,
DRect **rgTextlineRects,
int *spacingEst,
char *stDebugBaseName){
int w, h;
D_uint8 *pu8;
DProfile prof;
DProfile profSmear;// profile of smeared image
char stTmp[1024];
w = img.width();
h = img.height();
pu8 = img.dataPointer_u8();
for(int y=0, idx=0; y < h; ++y){
for(int x=0; x < w; ++x, ++idx){
if((pu8[idx] > 0) && (pu8[idx] < 255)){
fprintf(stderr, "DTextlineSeparator::getTextlineRects() requires "
"BINARY image with values of 0 or 255!\n");
exit(1);
}
}
}
DProfile profWeightedStrokeDist;
int *rgBlackSpacingHist;
rgBlackSpacingHist=new int[200];
D_CHECKPTR(rgBlackSpacingHist);
memset(rgBlackSpacingHist,0,sizeof(int)*200);
int *rgPeakYs;
int numPeaks;
int *rgValleyYs;
int numValleys;
rgPeakYs = new int[h];
D_CHECKPTR(rgPeakYs);
rgValleyYs = new int[h];
D_CHECKPTR(rgValleyYs);
numPeaks = 0;
numValleys = 0;
{
prof.getImageVerticalProfile(img,false);
prof.smoothAvg(2);
double *pdbl;
pdbl = prof.dataPointer();
for(int j=0; j < h; ++j)
pdbl[j] /= 255; // now the profile is number of white pixels (was GS prof)
unsigned int profMax;
profMax = (unsigned int)prof.max();
//use original image to create histogram of horizontal foreground spacing
//(distance from black pixel to next black pixel) weighted by profile value
//inverse (number of black pixels instead of white pixels)
for(int y=2; y < (h-2); ++y){//ignore 2 on each end (smoothing boundaries)
int lastBlackX;
int runlength;
int x;
int weight;
x=0;
lastBlackX = -1;
runlength = 0;
for(x=0 ; x < w; ++x){
if(pu8[y*w+x] == 0){//black
runlength = x - lastBlackX;
if((runlength >= 2) && (runlength < 200)){
weight = (int)profMax - (int)pdbl[y];//inverse of profile value at y
rgBlackSpacingHist[runlength] += weight;
}
lastBlackX=x;
}
}
}
}
//to get the spacing estimate, get the max, then find the next position
//that is less than 1/3 of the max. Use that as the estimate to determine
//scale
int spacingMax;
int spacingEstimate;
spacingMax = 2;
for(int j=3; j<200; ++j){
if(rgBlackSpacingHist[j] > rgBlackSpacingHist[spacingMax])
spacingMax = j;
}
spacingEstimate = spacingMax;
for(int j=spacingMax+1; j < 200; ++j){
if(rgBlackSpacingHist[j] < (rgBlackSpacingHist[spacingMax] / 3)){
spacingEstimate = j;
break;
}
//.........这里部分代码省略.........
示例15: getSlant_thread_func
void* DSlantAngle::getSlant_thread_func(void *params){
SLANT_THREAD_PARMS *pparms;
int numThreads;
int w, h;
D_uint8 *p8;
int runlen, maxrl; /* maximum slant runlen */
double slantDx;
int lineH;
int slantOffset, slantAngle, angle;
double dblWeight;
DImage *pimg;
int rlThresh;
pparms = (SLANT_THREAD_PARMS*)params;
numThreads = pparms->numThreads;
pimg = pparms->pImgSrc;
rlThresh = pparms->rlThresh;
w = pimg->width();
h = pimg->height();
p8 = pimg->dataPointer_u8();
for(int i=0; i < 120; ++i)
pparms->rgSlantSums[i] = 0;
for(int tl=pparms->threadNum; tl < (pparms->numTextlines); tl+=numThreads){
int x0, y0, x1, y1;
unsigned int rgSlantSums[120];
x0 = pparms->rgRects[tl].x;
y0 = pparms->rgRects[tl].y;
x1 = pparms->rgRects[tl].x + pparms->rgRects[tl].w - 1;
y1 = pparms->rgRects[tl].y + pparms->rgRects[tl].h - 1;
lineH = y1-y0+1;
memset(rgSlantSums, 0, sizeof(int)*120);
dblWeight = 0.;
for(angle = -45; angle <= 60; angle += 1){
/* at each x-position, sum the maximum run length at that angle into the
accumulator */
if(0 == angle) /* vertical, so tangent is infinity */
slantDx = 0.;
else
slantDx = -1.0 / tan(DMath::degreesToRadians(90-angle));
// for(j = slantOffset; j < (hdr.w-slantOffset); ++j){
for(int j = x0; j <= x1; ++j){
maxrl = 0;
runlen = 0;
for(int y = 0; y < lineH; ++y){
int x;
x = (int)(0.5+ j + y * slantDx);
if( (x>=x0) && (x <= x1)){ /* make sure we are within bounds */
int idxtmp;
idxtmp = (y+y0)*w+x;
// imgCoded[idxtmp*3] = 0;
if(0 == p8[idxtmp]){
++runlen;
if(runlen > maxrl){
maxrl = runlen;
}
}
else
runlen = 0;
} /* end if in bounds */
else{
runlen = 0; /* ignore runs that go off edge of image */
}
}
if(maxrl > rlThresh){
rgSlantSums[angle+45] += maxrl*maxrl;
dblWeight += maxrl;
}
} /* end for j */
} /* end for angle */
for(int i=0; i < 120; ++i)
pparms->rgSlantSums[i] += rgSlantSums[i];
if(NULL != (pparms->rgWeights)){
pparms->rgWeights[tl] = dblWeight;
}
if(NULL != (pparms->rgAngles)){
// need to independently figure out the angle for this particular textline
unsigned int rgSlantSumsTmp[120];
//smooth the histogram
rgSlantSumsTmp[0] = (rgSlantSums[0] + rgSlantSums[1]) / 2;
for(int aa = 1; aa < 119; ++aa){
rgSlantSumsTmp[aa]=(rgSlantSums[aa-1]+rgSlantSums[aa]+rgSlantSums[aa+1])/3;
}
// for(int aa = 0; aa < 120; ++aa){
// rgSlantSums[aa] = rgSlantSumsTmp[aa];
// }
//use the smoothed histogram peak as the slant angle
slantAngle = 0;
for(angle = -45; angle <= 60; angle += 1){
if(rgSlantSumsTmp[angle+45] > rgSlantSumsTmp[slantAngle+45]){
slantAngle = angle;
}
} /* end for angle */
pparms->rgAngles[tl] = slantAngle;
}
}
//.........这里部分代码省略.........