41 #include <visp3/core/vpMatrix.h> 42 #include <visp3/core/vpTime.h> 45 bool compareMatrix(
const vpMatrix &m,
const double *
const array) {
46 for (
unsigned int i = 0; i < m.
getRows(); i++) {
47 for (
unsigned int j = 0; j < m.
getCols(); j++) {
62 A[0][0] = 16; A[0][1] = 2; A[0][2] = 3; A[0][3] = 13;
63 A[1][0] = 5; A[1][1] = 11; A[1][2] = 10; A[1][3] = 8;
64 A[2][0] = 9; A[2][1] = 7; A[2][2] = 6; A[2][3] = 12;
65 A[3][0] = 4; A[3][1] = 14; A[3][2] = 15; A[3][3] = 1;
68 B[0][0] = 1; B[0][1] = 3;
69 B[1][0] = 4; B[1][1] = 2;
73 double ground_truth[5*5] = {16, 50, 9, 22, 39,
79 std::cout <<
"A:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, full):\n" << res << std::endl;
81 if (res.
getRows() != 5 || res.
getCols() != 5 || !compareMatrix(res, ground_truth)) {
87 double ground_truth[4*4] = { 66, 59, 96, 50,
92 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, same):\n" << res << std::endl;
94 if (res.
getRows() != 4 || res.
getCols() != 4 || !compareMatrix(res, ground_truth)) {
100 double ground_truth[3*3] = { 66, 59, 96,
104 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, valid):\n" << res << std::endl;
106 if (res.
getRows() != 3 || res.
getCols() != 3 || !compareMatrix(res, ground_truth)) {
114 for (
unsigned int i = 0; i < A.getRows(); i++)
115 for (
unsigned int j = 0; j < A.getCols(); j++)
116 A[i][j] = i*A.getCols()+j;
119 for (
unsigned int i = 0; i < B.getRows(); i++)
120 for (
unsigned int j = 0; j < B.getCols(); j++)
121 B[i][j] = i*B.getCols()+j;
125 double ground_truth[5*7] = { 0, 0, 1, 2, 3, 4, 5,
126 0, 8, 14, 20, 26, 32, 26,
127 12, 36, 50, 64, 78, 92, 58,
128 24, 64, 86, 108, 130, 152, 90,
129 36, 84, 97, 110, 123, 136, 77};
131 std::cout <<
"A:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, full):\n" << res << std::endl;
133 if (res.
getRows() != 5 || res.
getCols() != 7 || !compareMatrix(res, ground_truth)) {
139 double ground_truth[2*6] = { 36, 50, 64, 78, 92, 58,
140 64, 86, 108, 130, 152, 90};
142 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, same):\n" << res << std::endl;
144 if (res.
getRows() != 2 || res.
getCols() != 6 || !compareMatrix(res, ground_truth)) {
151 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, valid):\n" << res << std::endl;
160 double ground_truth[5*7] = { 0, 0, 1, 2, 3, 4, 5,
161 0, 8, 14, 20, 26, 32, 26,
162 12, 36, 50, 64, 78, 92, 58,
163 24, 64, 86, 108, 130, 152, 90,
164 36, 84, 97, 110, 123, 136, 77};
166 std::cout <<
"A:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(B, A, full):\n" << res << std::endl;
168 if (res.
getRows() != 5 || res.
getCols() != 7 || !compareMatrix(res, ground_truth)) {
174 double ground_truth[4*2] = { 20, 26,
179 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(B, A, same):\n" << res << std::endl;
181 if (res.
getRows() != 4 || res.
getCols() != 2 || !compareMatrix(res, ground_truth)) {
188 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(B, A, valid):\n" << res << std::endl;
198 A[0][0] = 16; A[0][1] = 2; A[0][2] = 3; A[0][3] = 13;
199 A[1][0] = 5; A[1][1] = 11; A[1][2] = 10; A[1][3] = 8;
200 A[2][0] = 9; A[2][1] = 7; A[2][2] = 6; A[2][3] = 12;
201 A[3][0] = 4; A[3][1] = 14; A[3][2] = 15; A[3][3] = 1;
204 B[0][0] = 8; B[0][1] = 1; B[0][2] = 6;
205 B[1][0] = 3; B[1][1] = 5; B[1][2] = 7;
206 B[2][0] = 4; B[2][1] = 9; B[2][2] = 2;
210 double ground_truth[6*6] = { 128, 32, 122, 119, 31, 78,
211 88, 179, 252, 208, 154, 139,
212 151, 275, 291, 378, 281, 154,
213 79, 271, 423, 366, 285, 106,
214 48, 171, 248, 292, 230, 31,
215 16, 92, 194, 167, 39, 2};
217 std::cout <<
"A:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, full):\n" << res << std::endl;
219 if (res.
getRows() != 6 || res.
getCols() != 6 || !compareMatrix(res, ground_truth)) {
225 double ground_truth[4*4] = { 179, 252, 208, 154,
230 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, same):\n" << res << std::endl;
232 if (res.
getRows() != 4 || res.
getCols() != 4 || !compareMatrix(res, ground_truth)) {
238 double ground_truth[2*2] = { 291, 378,
241 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, valid):\n" << res << std::endl;
243 if (res.
getRows() != 2 || res.
getCols() != 2 || !compareMatrix(res, ground_truth)) {
249 std::cout <<
"Catch an exception: " << e.
what() << std::endl;
Used to indicate that a value is not in the allowed range.
Implementation of a matrix and operations on matrices.
static vpMatrix conv2(const vpMatrix &M, const vpMatrix &kernel, const std::string &mode="full")
static bool equal(double x, double y, double s=0.001)
error that can be emited by ViSP classes.
unsigned int getCols() const
const char * what() const
unsigned int getRows() const