Mat me = (Mat_<float>(4, 4) << 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1); Mat meinv = me.inv(); cout << "me=\n" << me << endl; cout << "meinv=" << endl << meinv << endl << endl; int nonZerosNum = countNonZero(me); cout << "me = " << endl << me << endl; cout << "me中非零元素的個數=" << nonZerosNum << endl; //均值和方差 Mat mean; Mat stddev(1,1,CV_8UC1); meanStdDev(me, mean, stddev); Mat_<uchar>img = stddev;//Mat_是Mat的派生類. //優勢:Mat_對象訪問元素時再也不須要指定元素類型;而Mat類型對象須要在<>中指定元素類型,如用img.at<類型>(i,j)。 img(0,0) = 100; cout << "mean=" << mean << endl << endl; cout << "stddev=" << stddev << endl << endl; cout << "stddev=" <<int(img(0,0)) << endl << endl;