本文整理汇总了C++中DImage::height方法的典型用法代码示例。如果您正苦于以下问题:C++ DImage::height方法的具体用法?C++ DImage::height怎么用?C++ DImage::height使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DImage
的用法示例。
在下文中一共展示了DImage::height方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: genInImageMask
void OpticalFlow::genInImageMask(DImage &mask, const DImage &flow,int interval)
{
int imWidth,imHeight;
imWidth=flow.width();
imHeight=flow.height();
if(mask.matchDimension(flow.width(),flow.height(),1)==false)
mask.allocate(imWidth,imHeight);
else
mask.reset();
const _FlowPrecision *pFlow;
_FlowPrecision *pMask;
pFlow = flow.data();;
pMask=mask.data();
double x,y;
for(int i=0;i<imHeight;i++)
for(int j=0;j<imWidth;j++)
{
int offset=i*imWidth+j;
y=i+pFlow[offset*2+1];
x=j+pFlow[offset*2];
if(x<interval || x>imWidth-1-interval || y<interval || y>imHeight-1-interval)
continue;
pMask[offset]=1;
}
}
示例2: convertDImageToMat
void convertDImageToMat(DImage& dimg, Mat* mat)
{
*mat = Mat_<unsigned char>(dimg.height(),dimg.width());
unsigned char* dataD = dimg.dataPointer_u8();
unsigned char* dataM = mat->data;
for (int i=0; i< dimg.width() * dimg.height(); i++)
{
dataM[i]=dataD[i];
}
}
示例3: DImageToMat
Mat DImageToMat(const DImage& src)
{
Mat img(src.height(),src.width(),CV_8U);
unsigned char* data1 = src.dataPointer_u8();
unsigned char* data0 = img.data;
for (int i=0; i< src.height() * src.width(); i++)
{
data0[i]=data1[i];
}
return img;
}
示例4: GetWccWithOF
void GetWccWithOF(DImage vx, DImage vy, int t_Norm, int t_Dir, cv::Mat& Wcc,int type)
{
int Width = vx.width();
int Height = vx.height();
int length = Width*Height;
Wcc.create(Height,Width,type);
float Norm[length];
float Dir[length];
double Avg_Norm = 0;
double Avg_Dir = 0;
for(int i = 0; i < length; i++)
{
Norm[i] = sqrt(vx.pData[i]*vx.pData[i] + vy.pData[i]*vy.pData[i]);
Dir[i] = atan2(vy.pData[i],vx.pData[i]);
Avg_Norm += Norm[i];
Avg_Dir += Dir[i];
}
Avg_Norm /= length;
Avg_Dir /= length;
for(int i = 0; i < length; i++)
{
//float a = fabs(Dir.pData[i] - Avg_Dir);
if (Norm[i] > t_Norm * Avg_Norm && fabs(Dir[i] - Avg_Dir) > t_Dir)
Wcc.data[i] = 0;
else
Wcc.data[i] = 255;
}
}
示例5: if
//---------------------------------------------------------------------------------------
// function to convert image to feature image
//---------------------------------------------------------------------------------------
void OpticalFlow::im2feature(DImage &imfeature, const DImage &im)
{
int width=im.width();
int height=im.height();
int nchannels=im.nchannels();
if(nchannels==1)
{
imfeature.allocate(im.width(),im.height(),3);
DImage imdx,imdy;
im.dx(imdx,true);
im.dy(imdy,true);
_FlowPrecision* data=imfeature.data();
for(int i=0;i<height;i++)
for(int j=0;j<width;j++)
{
int offset=i*width+j;
data[offset*3]=im.data()[offset];
data[offset*3+1]=imdx.data()[offset];
data[offset*3+2]=imdy.data()[offset];
}
}
else if(nchannels==3)
{
DImage grayImage;
im.desaturate(grayImage);
imfeature.allocate(im.width(),im.height(),5);
DImage imdx,imdy;
grayImage.dx(imdx,true);
grayImage.dy(imdy,true);
_FlowPrecision* data=imfeature.data();
for(int i=0;i<height;i++)
for(int j=0;j<width;j++)
{
int offset=i*width+j;
data[offset*5]=grayImage.data()[offset];
data[offset*5+1]=imdx.data()[offset];
data[offset*5+2]=imdy.data()[offset];
data[offset*5+3]=im.data()[offset*3+1]-im.data()[offset*3];
data[offset*5+4]=im.data()[offset*3+1]-im.data()[offset*3+2];
}
}
else
imfeature.copyData(im);
}
示例6: 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())
}
示例7: 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);
}
示例8: 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];
}
}
示例9: 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())
}
示例10: 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);
}
示例11: 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())
}
示例12: 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;
}
示例13: 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;
}
示例14: 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...
//.........这里部分代码省略.........
示例15: estimateAvgHeight
///assumes that the image is BINARY with bg=255
int DTextlineSeparator::estimateAvgHeight(DImage &imgBinary,
int ROIx0, int ROIy0,
int ROIx1, int ROIy1,
char *stDebugBaseName){
DImage imgROI;
int w, h;
D_uint8 *pu8;
DProfile prof;
if(-1 == ROIx1)
ROIx1 = imgBinary.width()-1;
if(-1 == ROIy1)
ROIy1 = imgBinary.height()-1;
imgBinary.copy_(imgROI,ROIx0,ROIy0,ROIx1-ROIx0+1,ROIy1-ROIy0+1);
char stTmp[1024];
sprintf(stTmp, "%s_roi.pgm",stDebugBaseName);
imgROI.save(stTmp);
w = imgROI.width();
h = imgROI.height();
pu8 = imgROI.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!\n");
exit(1);
}
}
}
prof.getImageVerticalProfile(imgROI,true);
DImage imgTmp;
imgTmp = prof.toDImage(100,true);
sprintf(stTmp,"%s_prof.pgm",stDebugBaseName);
imgTmp.save(stTmp);
prof.smoothAvg(2);
imgTmp = prof.toDImage(100,true);
sprintf(stTmp,"%s_prof_smooth.pgm",stDebugBaseName);
imgTmp.save(stTmp);
prof.getVertAvgRunlengthProfile(imgROI,0x00,false);
imgTmp = prof.toDImage(100,true);
sprintf(stTmp,"%s_prof_rle.pgm",stDebugBaseName);
imgTmp.save(stTmp);
prof.smoothAvg(2);
imgTmp = prof.toDImage(100,true);
sprintf(stTmp,"%s_prof_rle_smooth.pgm",stDebugBaseName);
imgTmp.save(stTmp);
// find a radiusX that gives a good histogram from the TCM
// (we want the TCM to give responses of about
printf(" *creating TCM histograms...\n");fflush(stdout);
int rgHists[40][256];
memset(rgHists,0,sizeof(int)*40*256);
for(int rx = 10; rx < 400; rx +=10){
DImage imgTCM;
D_uint8 *p8;
int max = 0;
int ry;
ry = rx/6;
if(ry < 1)
ry = 1;
DTCM::getImageTCM_(imgTCM, imgROI, rx,ry, false,NULL);
p8 = imgTCM.dataPointer_u8();
for(int y = 0, idx=0; y < h; ++y){
for(int x = 0; x < w; ++x,++idx){
rgHists[rx/10][p8[idx]] += 1;
}
}
rgHists[rx/10][0] = 0;
max = 0;
for(int i=0;i<256;++i)
if(rgHists[rx/10][i] > max)
max =rgHists[rx/10][i];
for(int i=0;i<256;++i){//scale from 0 to 255
if (max!=0)
rgHists[rx/10][i] = rgHists[rx/10][i] * 255 / max;
}
}
//now save the histograms as an image
DImage imgTCMhists;
imgTCMhists.create(256,40,DImage::DImage_u8);
D_uint8 *p8;
p8 = imgTCMhists.dataPointer_u8();
for(int y=0, idx=0; y < 40; ++y){
for(int x=0; x < 256; ++x, ++idx){
p8[idx] = (D_uint8)(rgHists[y][x]);
}
}
sprintf(stTmp, "%s_tcmhist.pgm",stDebugBaseName);
imgTCMhists.save(stTmp);
printf(" *done creating TCM histograms...\n");
//.........这里部分代码省略.........