#includeusing namespace cv; int main() { Mat mat1 = Mat::zeros(2, 2, CV_32F); Mat mat2; mat1.copyTo(mat2); std::cout << "mat1: " << mat1 << std::endl; std::cout << "mat2: " << mat2 << std::endl; return 0; }
#includeThis example is similar to the first, but introduces the concept of a region of interest (ROI). In this case, a single element (at position [0,0]) is selected from mat1 as the ROI. The copyTo function is then called with mat2 as the argument, which copies the single element of mat1 into the corresponding position in mat2. Finally, both matrices are printed to the console to verify that only one element was changed. Both of these examples use the OpenCV package library, which provides a variety of computer vision functions and algorithms.using namespace cv; int main() { Mat mat1 = Mat::zeros(2, 2, CV_32F); Mat mat2 = Mat::ones(2, 2, CV_32F); Mat roi = mat1(Rect(0, 0, 1, 1)); roi.copyTo(mat2); std::cout << "mat1: " << mat1 << std::endl; std::cout << "mat2: " << mat2 << std::endl; return 0; }