Ask Your Question
0

How to use Mat_ ?

asked 2012-12-19 09:02:22 -0600

mrgloom gravatar image

updated 2012-12-19 09:08:33 -0600

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2012-12-20 05:06:04 -0600

vaaksiainen gravatar image

updated 2012-12-20 05:11:23 -0600

Write as a template:

template< class _Type > class Foo {
public:
    static void Diff( cv::Mat_<_Type> &a, cv::Mat_<_Type> &b);
private:
    Foo(){}
    ~Foo(){}
};
edit flag offensive delete link more

Comments

please provide example how to use it.

mrgloom gravatar imagemrgloom ( 2012-12-20 07:42:00 -0600 )edit

Question Tools

Stats

Asked: 2012-12-19 09:02:22 -0600

Seen: 435 times

Last updated: Dec 20 '12