cv::Mat A = cv::Mat::ones(3, 3, CV_32FC1); // Create a 3x3 matrix with all values set to 1 float* row = A.ptr(1); // Pointer to the second row of matrix A
cv::Mat A = cv::Mat::eye(4, 4, CV_32FC1); // Create a 4x4 identity matrix for(int i = 0; i < A.rows; i++) { float* row = A.ptrIn this example, we create a 4x4 identity matrix using the `eye` function. We then use a nested for loop to iterate over each row and multiply each element of that row by 2. This example demonstrates how you can use the `ptr` function to access and modify the elements of a matrix row-by-row. C++ mat row is part of the OpenCV library.(i); // Pointer to each row of matrix A for(int j = 0; j < A.cols; j++) { row[j] *= 2; // Multiply each element of the row by 2 } }