Ask Your Question
0

how to use template <typename T> with different Mat.depth

asked 2016-11-01 07:13:55 -0600

azdoud.y gravatar image

updated 2016-11-01 07:19:52 -0600

I'm trying to get back same values from Mat object in different cv::Mat types I've wrote a function that works with CV_32F type my goal is writing a generic function that operates with the other types (CV_8U | CV_16U | CV_16S | CV_32S | CV_64F)

please no Simple IF Statements

void MaxMin(cv::Mat& m){
    float max, min;
    for(int i=0;i<m.rows;i++){
        for(int j=0;j<m.cols;j++){
            if(max < m.at<float>(i,j)){
                max = m.at<float>(i,j);
            }
            if(min > m.at<float>(i,j)){
                min = m.at<float>(i,j);
            }
        }
    }
    std::cout<<"Max "<<max<<" Min "<<min<<std::endl;
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-11-01 07:24:18 -0600

berak gravatar image

updated 2016-11-01 07:25:46 -0600

please do not write loops like that at all, instead use the builtin minMaxLoc

edit flag offensive delete link more

Comments

okey #berak thank you again

azdoud.y gravatar imageazdoud.y ( 2016-11-01 07:28:17 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-11-01 07:13:55 -0600

Seen: 49 times

Last updated: Nov 01 '16