How to convert mat to 3D matrix

I am trying to write image rotation code. I can’t use OpenCV’s rotation shortcuts.

I am assuming I need to change the input image from Mat format to 3D matrix format.
I got the error “C2676” which is “binary ‘[’: ‘cv::Mat’ does not define this operator or a conversion to a type acceptable to the predefined operator”

I just want to share my whole code with you. So you can easily try this code on your own computer. I couldn’t solve this problem for a month. If someone can show me to way to do this or give me a working code I will be really glad.

#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
#include <tuple>

using namespace cv;
using namespace std;


std::tuple<Mat, Mat, int, int>  createMatrix(string imgPath) {

	Mat img = imread(imgPath);
	

	int height = img.rows; // 462
	int width = img.cols;  // 623

	img.at<Vec3b>(height, width);
	//cout << height << endl;
	//cout << width << endl;

	//img[height][width][3] = size(img);
	//int OutImage[462][623][3];

	Mat OutImage = Mat::zeros(Size(width, height), CV_8UC3);
	return { OutImage, img, height, width };
}


void main() {

	Mat img;
	Mat returnedOutImage;

	float Xmidpoint, Ymidpoint, Xprime, Yprime;
	int Xdisplacement, Ydisplacement, height, width;
	int angle = 30;

	tie (returnedOutImage,  img, height, width) = createMatrix("Resources/lambo.png");

	Xmidpoint = height / 2;
	Ymidpoint = width / 2;

	//int i, j,k;
	int i, j;
	int pixel;
	returnedOutImage.at<Vec3b>(i, j);

	for (i = 0; i <= height; i++)

	{

		for (j = 0; j <= width; j++) 
		{



			Xdisplacement = i - Xmidpoint;
			Ydisplacement = j - Ymidpoint;

			Xprime = Xdisplacement * cos(angle) + Ydisplacement * sin(angle);
			Yprime = Ydisplacement * sin(angle) + Ydisplacement * cos(angle);

			Xprime = round(Xprime + Xmidpoint);
			Yprime = round(Yprime + Ymidpoint);

			//for (k=0;k<=2;k++) 

			


			if (Xprime >= 1 && Yprime >= 1 && Xprime <= height && Yprime <= width) {

				//returnedOutImage[i][j][k] = img[Xprime][Yprime][k];
				pixel = img[Xprime][Yprime];
				//out_image[i][j]=rgb_image[(Xprime-1)*width +Yprime];
			}



			returnedOutImage[i][j] = pixel;
				waitKey(0);
			

		}
	}

	imshow("Image", returnedOutImage);

	
}

please try NOT to write code like this. it is slow, error-prone, and defeats the purpose of a matrix oriented library.

explain, what you are trying to achieve in the end, then we can help you to make use of opencv’s builtin warping functions.