C++ 如何在OpenCV中从n维数组中获取最大值
我正试图从三维垫子中获取最大值,但minmaxIdx和mixmaxloc都未能做到这一点C++ 如何在OpenCV中从n维数组中获取最大值,c++,opencv,multidimensional-array,max,C++,Opencv,Multidimensional Array,Max,我正试图从三维垫子中获取最大值,但minmaxIdx和mixmaxloc都未能做到这一点 int sz[] = {BIN, BIN, BIN}; Mat accumarray(3, sz, CV_8U, Scalar::all(0)) ; double testMaxval = 0; int minIdx = accumarray.dims ; minMaxIdx(accumarray, NULL, &testMaxval,NULL,minIdx ,NULL) ; cout<<
int sz[] = {BIN, BIN, BIN};
Mat accumarray(3, sz, CV_8U, Scalar::all(0)) ;
double testMaxval = 0;
int minIdx = accumarray.dims ;
minMaxIdx(accumarray, NULL, &testMaxval,NULL,minIdx ,NULL) ;
cout<<testMaxval<<endl ;
intsz[]={BIN,BIN,BIN};
Mat accumarray(3,sz,CV_8U,Scalar::all(0));
双testMaxval=0;
int minIdx=Accumaray.dims;
minMaxIdx(accumarray、NULL和testMaxval、NULL、minIdx、NULL);
cout以下代码适用于我的OpenCV 2.3.1:
int sz[] = {3, 3, 3};
Mat accumarray(3, sz, CV_8U, Scalar::all(0));
accumarray.at<uchar>(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;
intsz[]={3,3,3};
Mat accumarray(3,sz,CV_8U,Scalar::all(0));
在(0,1,2)=20;
双testMaxval;
int-maxIdx[3];
minMaxIdx(accumarray,0和testMaxval,0,maxIdx);
不能对掩码使用Mat()而不是NULL,否则将使用断言掩码。empty()
这个很好用,非常感谢。minIdx应该与accumarray具有相同的维度。我仍然得到:minMaxIdx中的断言失败((cn==1&&(mask.empty()| | mask.type()==CV|8U))| |(cn>=1&&mask.empty()&&!minIdx&&&!maxIdx))。看起来像是您的cn>=1,检查您的minIdx和maxIdx!=一开始为空。
Mat m;
double min, max;
int minInd, maxInd;
cv::minMaxIdx(m, &min, &max, &minInd, &maxInd, Mat());