cv::Mat image = cv::imread("image.jpg"); // read image file cv::Mat grayImage; cvtColor(image, grayImage, cv::COLOR_BGR2GRAY); // convert image to grayscale grayImage.setTo(cv::Scalar(255)); // sets all elements to white
cv::Mat mat = cv::Mat::zeros(3,3,CV_32FC1); // create a 3x3 matrix filled with zeros mat.setTo(cv::Scalar(1)); // sets all elements to 1In this example, the setTo function is used to set all elements in the matrix to 1. Overall, the setTo function is useful for quickly and easily setting all the elements in a matrix or array to a specified value.