cv::Mat mat = cv::Mat::ones(3, 3, CV_8UC1); // create a 3x3 matrix of ones cv::Mat column = mat.col(1); // get the second column (index 1)
cv::Mat mat = cv::Mat::ones(3, 3, CV_8UC1); // create a 3x3 matrix of ones cv::Mat column = mat.col(1); // get the second column (index 1) column.setTo(cv::Scalar(255)); // set all the elements in the column to 255 std::cout << mat << std::endl; // print the original matrix, which now has a column of 255s
cv::Mat mat = cv::Mat::ones(3, 3, CV_32FC1); // create a 3x3 matrix of ones cv::Mat column = mat.col(1); // get the second column (index 1) cv::Mat newMat = cv::Mat::zeros(mat.rows, 1, CV_32FC1); // create a new 3x1 matrix of zeros column.copyTo(newMat.col(0)); // copy the second column from the original matrix to the new matrix std::cout << newMat << std::endl; // print the new matrix, which has a single column of 1s