Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to use Mat_ ?

I want to use code like below, how can I work with Mat_?

void diff(Mat_ src, Mat_ tmp)
    {
        int w_s= src.cols;
        int h_s= src.rows;
        int w_t= tmp.cols;
        int h_t= tmp.rows;

        double min_peak=INT_MAX;
        Point pt;
        for(int y=0;y<h_s-h_t+1;++y)
        {
            for(int x=0;x<w_s-w_t+1;++x)
            {
                __int64 sum=0;
                for(int cy=0;cy<h_t;++cy)
                {
                    for(int cx=0;cx<w_t;++cx)
                    {
                        sum+= abs(src[y+cy][x+cx]-tmp[cy][cx]);
                    }
                }
                double diff= (double)sum/(w_t*h_t);

                if (diff<min_peak)
                {
                    pt.x= x;
                    pt.y= y;
                    min_peak=diff;
                }
            }
        }
        cout<<pt.x<<" "<<pt.y<<"\n";
    }

How to use Mat_ ?

I want to use code like below, how can I work with Mat_?

void diff(Mat_ src, Mat_ tmp)
    {
        int w_s= src.cols;
        int h_s= src.rows;
        int w_t= tmp.cols;
        int h_t= tmp.rows;

        double min_peak=INT_MAX;
        Point pt;
        for(int y=0;y<h_s-h_t+1;++y)
        {
            for(int x=0;x<w_s-w_t+1;++x)
            {
                __int64 sum=0;
                for(int cy=0;cy<h_t;++cy)
                {
                    for(int cx=0;cx<w_t;++cx)
                    {
                        sum+= abs(src[y+cy][x+cx]-tmp[cy][cx]);
                    }
                }
                double diff= (double)sum/(w_t*h_t);

                if (diff<min_peak)
                {
                    pt.x= x;
                    pt.y= y;
                    min_peak=diff;
                }
            }
        }
        cout<<pt.x<<" "<<pt.y<<"\n";
    }

so I figure out that I must specify type

void plain_corr(Mat_<uchar> src, Mat_<uchar> tmp)

but what if I want to support, more types?

How to use Mat_ ?

I want to use code like below, how can I work with Mat_?

void diff(Mat_ src, Mat_ tmp)
    {
        int w_s= src.cols;
        int h_s= src.rows;
        int w_t= tmp.cols;
        int h_t= tmp.rows;

        double min_peak=INT_MAX;
        Point pt;
        for(int y=0;y<h_s-h_t+1;++y)
        {
            for(int x=0;x<w_s-w_t+1;++x)
            {
                __int64 sum=0;
                for(int cy=0;cy<h_t;++cy)
                {
                    for(int cx=0;cx<w_t;++cx)
                    {
                        sum+= abs(src[y+cy][x+cx]-tmp[cy][cx]);
                    }
                }
                double diff= (double)sum/(w_t*h_t);

                if (diff<min_peak)
                {
                    pt.x= x;
                    pt.y= y;
                    min_peak=diff;
                }
            }
        }
        cout<<pt.x<<" "<<pt.y<<"\n";
    }

so I figure out that I must specify type

void plain_corr(Mat_<uchar> src, Mat_<uchar> tmp)

but what if I want to support, support more types?