#includeint main() { cv::Mat mat(3, 3, CV_8UC1, cv::Scalar(0)); // Initializing a 3x3 matrix with zeros for (int i = 0; i < mat.cols; i++) { *mat.ptr (0, i) = i + 1; // Setting pixel values of the first row to 1, 2, 3 } std::cout << mat << std::endl; // Output the modified matrix return 0; }
#includePackage library: OpenCVint main() { cv::Mat mat(3, 3, CV_8UC1, cv::Scalar(0)); // Initializing a 3x3 matrix with zeros for (int i = 0; i < mat.cols; i++) { *mat.ptr (0, i) = i + 1; // Setting pixel values of the first row to 1, 2, 3 } int sum = 0; uchar* row_ptr = mat.ptr (0); // Get a pointer to the first row for (int i = 0; i < mat.cols; i++) { sum += *(row_ptr + i); // Summing up the pixel values of the first row } std::cout << "Sum of the first row: " << sum << std::endl; return 0; }