How to get the max value from n dimensional array in OpenCV

后端 未结 2 1828
没有蜡笔的小新
没有蜡笔的小新 2021-02-10 15:02

I am trying to get max value from a 3-d Mat, but minmaxIdx and mixmaxloc both failed to do this.

int sz[] = {BIN, BIN, BIN};
Mat accumarray(3, sz, CV_8U, Scalar         


        
2条回答
  •  闹比i
    闹比i (楼主)
    2021-02-10 15:38

    Following code works for me with OpenCV 2.3.1:

    int sz[] = {3, 3, 3};
    Mat accumarray(3, sz, CV_8U, Scalar::all(0));
    accumarray.at(0, 1, 2) = 20;
    double testMaxval;
    int maxIdx[3];
    minMaxIdx(accumarray, 0, &testMaxval, 0, maxIdx);
    cout << testMaxval << endl ;
    cout << maxIdx[0] << ", " << maxIdx[1] << ", " << maxIdx[2] << endl;
    

提交回复
热议问题