从给定矩阵中查找最大矩阵和最小矩阵

Find Max matrix & minimum Matrix out of given matrixes

本文关键字:查找      更新时间:2023-10-16

我是c++和opencv的新手。我有3个矩阵,我想从这3个矩阵中找出最大矩阵和最小矩阵,举个例子

A=[12 3] B= [2 4 6] c=[4 8 12]则A为最小值,c为高标量值的矩阵,有什么方法可以找到它吗?

另一方面,我尝试了以下方法,但这是不正确的。

Mat A=imread("") // intialise the mat 1X3
Mat B=  //intialise the mat 1X3
if (A>B) printf("Matrix A greater than B") // this line encounter the Error that is not the correct way of doing that.

嗨,OpenCV有cv::min和max函数为您实现!下面是一个示例用法!希望这对你有帮助!

int _tmain(int argc, _TCHAR* argv[])
{
    //Fill Random Numbers in 3 Mats
    Mat mTest(5,5,CV_8UC3),mMin,mMax;   
    randn(mTest,Scalar::all(125),Scalar::all(100));
    Mat mTest_3[3];
    split(mTest, mTest_3);
    //Find Min and max from 3 Mats!
    mMin=cv::min(mTest_3[0],cv::min(mTest_3[1],mTest_3[2]));
    mMax=cv::max(mTest_3[0],cv::max(mTest_3[1],mTest_3[2]));
    cout<< "Inputs 1: n"<<mTest_3[0]<<"n";
    cout<< "Inputs 2: n"<<mTest_3[1]<<"n";
    cout<< "Inputs 3: n"<<mTest_3[2]<<"n";
    cout<< "Min : n"<<mMin<<"n";
    cout<< "Max : n"<<mMax<<"n";
}