#includeusing namespace cv; Mat mat1 = Mat::zeros(3, 3, CV_8UC1); // a 3x3 matrix filled with zeros of type CV_8UC1 (8 bit unsigned char)
# includeusing namespace std; Mat mat2 = Mat(2, 2, CV_32FC1); // a 2x2 matrix filled with zeros of type CV_32FC1 (32 bit float) // Accessing scalar elements of Mat object mat2.at (0, 0) = 1.23f; mat2.at (0, 1) = 2.34f; mat2.at (1, 0) = 3.45f; mat2.at (1, 1) = 4.56f; // Outputting the elements of the matrix for (int i = 0; i < mat2.rows; i++) { for (int j = 0; j < mat2.cols; j++) { cout << mat2.at (i, j) << " "; } cout << endl; }
1.23 2.34 3.45 4.56These examples use the OpenCV library, which is a computer vision and machine learning library in C++.