I am rather new to OpenCV and need to translate some Python code to OpenCV (C++). Given a certain matrix, I need to create a larger matrix with a specific pattern. Suppose the original matrix is a matrix with random integers:
>>> import numpy as np
>>> a = np.random.randint(0, 10, (3,3))
>>> a
array([[2, 7, 0],
[3, 7, 5],
[7, 2, 0]])
Then the Python code uses the repeat
command to construct a larger matrix in the following way:
>>> a.repeat(3, 0).repeat(3,1)
array([[2, 2, 2, 7, 7, 7, 0, 0, 0],
[2, 2, 2, 7, 7, 7, 0, 0, 0],
[2, 2, 2, 7, 7, 7, 0, 0, 0],
[3, 3, 3, 7, 7, 7, 5, 5, 5],
[3, 3, 3, 7, 7, 7, 5, 5, 5],
[3, 3, 3, 7, 7, 7, 5, 5, 5],
[7, 7, 7, 2, 2, 2, 0, 0, 0],
[7, 7, 7, 2, 2, 2, 0, 0, 0],
[7, 7, 7, 2, 2, 2, 0, 0, 0]])
In my C++ code, I am thinking of using OpenCV's Mat
class to store the matrices, because I need to do some operations like transposing, elementwise multiplication, matrix-vector multiplication etc...
I know how to create the smaller matrix, e.g. something like the following:
double data[3][3] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
cv::Mat m = cv::Mat(3, 3, CV_64FC1, &data);
But I haven't figured out a way to construct the larger matrix out of this smaller one. I cannot find an equivalent of NumPy's repeat
command for OpenCV's Mat
class. How could this be done?