C ++编程中的问题 [英] problem in c++ programing

查看:66
本文介绍了C ++编程中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在处理一个图像处理项目.我可以理解matlab程序,但是C ++存在一些问题.
我找到了一个用于计算直方图的C ++程序,但是我不理解其中的某些指令,例如:

int index = x + y *(texture.Ptr()-> width);

curTextureHist [index] .r [i] = 0;

curTextureHist [index] .r [texture(y + j,x + i,2) ] ++;
...
您知道它们的意思吗?



在此程序中.

  void 直方图(RgbImage& Texture,TextureHistogram * curTextureHist)
{
    // 计算2 * REGION_R正方形内的直方图
     for ( int  y = REGION_R + TEXTURE_R; y <  texture.Ptr()-> height-REGION_R-TEXTURE_R; ++ y)
    {
         for ( int  x = REGION_R + TEXTURE_R; x ><  texture.Ptr()-> width-REGION_R-TEXTURE_R; ++ x)
        {
             int  index = x + y *(texture.Ptr()-> width);

            // 清除直方图
             for ( int  i =  0 ; i <  NUM_BINS; ++ i)
            {
                curTextureHist [index] .r [i] =  0 ;
                curTextureHist [index] .g [i] =  0 ;
                curTextureHist [index] .b [i] =  0 ;
            }

            // 计算直方图
             for ( int  j = -REGION_R; j ><  = REGION_R; ++ j)
            {
                 for ( int  i = -REGION_R; i ><  = REGION_R; ++ i)
                {
                    curTextureHist [index] .r [texture(y + j,x + i, 2 )] ++;
                    curTextureHist [index] .g [texture(y + j,x + i, 1 )] ++ ;;
                    curTextureHist [index] .b [texture(y + j,x + i, 0 )] ++ ;;
                }
            }
        }
    }
} 

解决方案

报价:

int index = x + y *(texture.Ptr()-> width);

将(一维)index设置为(二维)位置(x,y).那是i = x + y * width;.

报价:

curTextureHist [index] .r [i] = 0;

设置index中位于index处的curTextureHinst对象等于零.

报价:

curTextureHist [index] .r [texture(y + j,x + i,2)] ++;

递增具有curTextureHinst对象的索引等于texture(y+j,x+i,2)(其中texture是函数)的r分量(r=r+1;).


Hi
I am working on a image processing project.I can understand matlab program but i have some problem with C++.
I found a C++ program for calculating histogram.But i don''t understand some of instruction in it.for example:

int index = x+y*(texture.Ptr()->width);
and
curTextureHist[index].r[i] = 0;
or
curTextureHist[index].r[texture(y+j,x+i,2)]++;
...
do u know the mean of them.



in this program.

void Histogram(RgbImage& texture, TextureHistogram* curTextureHist)
{
    // calculate histogram within a 2*REGION_R square
    for(int y = REGION_R+TEXTURE_R; y < texture.Ptr()->height-REGION_R-TEXTURE_R; ++y)
    {
        for(int x = REGION_R+TEXTURE_R; x < texture.Ptr()->width-REGION_R-TEXTURE_R; ++x)
        {
            int index = x+y*(texture.Ptr()->width);

            // clear histogram
            for(int i = 0; i < NUM_BINS; ++i)
            {
                curTextureHist[index].r[i] = 0;
                curTextureHist[index].g[i] = 0;
                curTextureHist[index].b[i] = 0;
            }

            // calculate histogram
            for(int j = -REGION_R; j <= REGION_R; ++j)
            {
                for(int i = -REGION_R; i <= REGION_R; ++i)
                {
                    curTextureHist[index].r[texture(y+j,x+i,2)]++;
                    curTextureHist[index].g[texture(y+j,x+i,1)]++;
                    curTextureHist[index].b[texture(y+j,x+i,0)]++;
                }
            }
        }
    }
}

解决方案

Quote:

int index = x+y*(texture.Ptr()->width);

sets the (unidimensional) index to (bidimensional) position (x,y). That is i = x + y * width;.

Quote:

curTextureHist[index].r[i] = 0;

Sets the r[i] (red RGB component) of the curTextureHinst object at index equal to zero.

Quote:

curTextureHist[index].r[texture(y+j,x+i,2)]++;

Increments the r component (r=r+1;), having index equal to texture(y+j,x+i,2),(where texture is a function) of the curTextureHinst object.


这篇关于C ++编程中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆