【问题标题】:Find Max matrix & minimum Matrix out of given matrixes从给定的矩阵中找到最大矩阵和最小矩阵
【发布时间】:2016-10-15 02:21:30
【问题描述】:

我是 c++ 和 opencv 的新手。我有 3 个矩阵,在这三个矩阵中我想找到最大矩阵和最小矩阵,例如

A=[ 1 2 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.

【问题讨论】:

  • 您究竟何时认为一个矩阵大于另一个矩阵?
  • @Nico Schertler 我不知道具体的做法,但我需要找到小矩阵
  • 也许比较平均值?
  • 但在此之前,您至少应该查看有关如何迭代 Opencv mat 像素的文档!

标签: c++ opencv matrix


【解决方案1】:

嗨,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";

}

【讨论】:

    最近更新 更多