#include#include #include using namespace cv; int main() { Mat img = imread("example.jpg", IMREAD_GRAYSCALE); // Read image threshold(img, img, 128, 255, THRESH_BINARY); // Apply thresholding imshow("Thresholded Image", img); // Show image waitKey(0); // Wait for key press return 0; }
#includeThis example creates a 3x3 matrix of float values using Mat class, assigns values to each element using at function, and prints the matrix using cout function. Package/library: OpenCV#include using namespace cv; using namespace std; int main() { Mat mat(3, 3, CV_32F); // Create a 3x3 matrix of float values for (int i = 0; i < mat.rows; i++) { for (int j = 0; j < mat.cols; j++) { mat.at (i, j) = i + j; // Assign values to each element } } cout << "Matrix Elements: " << endl << mat << endl; // Print matrix return 0; }