39 #include <visp3/core/vpMatrix.h>
40 #include <visp3/core/vpTime.h>
42 #ifdef ENABLE_VISP_NAMESPACE
48 bool compareMatrix(
const vpMatrix &m,
const double *
const array)
50 for (
unsigned int i = 0; i < m.
getRows(); i++) {
51 for (
unsigned int j = 0; j < m.
getCols(); j++) {
91 double ground_truth[5 * 5] = { 16, 50, 9, 22, 39, 69, 66, 59, 96, 50, 29, 88, 89,
92 82, 52, 40, 72, 95, 106, 27, 16, 64, 88, 34, 2 };
94 std::cout <<
"A:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, full):\n" << res << std::endl;
96 if (res.
getRows() != 5 || res.
getCols() != 5 || !compareMatrix(res, ground_truth)) {
102 double ground_truth[4 * 4] = { 66, 59, 96, 50, 88, 89, 82, 52, 72, 95, 106, 27, 64, 88, 34, 2 };
104 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, same):\n" << res << std::endl;
106 if (res.
getRows() != 4 || res.
getCols() != 4 || !compareMatrix(res, ground_truth)) {
112 double ground_truth[3 * 3] = { 66, 59, 96, 88, 89, 82, 72, 95, 106 };
114 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, valid):\n" << res << std::endl;
116 if (res.
getRows() != 3 || res.
getCols() != 3 || !compareMatrix(res, ground_truth)) {
124 for (
unsigned int i = 0; i < A.getRows(); i++)
125 for (
unsigned int j = 0; j < A.getCols(); j++)
126 A[i][j] = i * A.getCols() + j;
129 for (
unsigned int i = 0; i < B.getRows(); i++)
130 for (
unsigned int j = 0; j < B.getCols(); j++)
131 B[i][j] = i * B.getCols() + j;
135 double ground_truth[5 * 7] = { 0, 0, 1, 2, 3, 4, 5, 0, 8, 14, 20, 26, 32, 26, 12, 36, 50, 64,
136 78, 92, 58, 24, 64, 86, 108, 130, 152, 90, 36, 84, 97, 110, 123, 136, 77 };
138 std::cout <<
"A:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, full):\n" << res << std::endl;
140 if (res.
getRows() != 5 || res.
getCols() != 7 || !compareMatrix(res, ground_truth)) {
146 double ground_truth[2 * 6] = { 36, 50, 64, 78, 92, 58, 64, 86, 108, 130, 152, 90 };
148 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, same):\n" << res << std::endl;
150 if (res.
getRows() != 2 || res.
getCols() != 6 || !compareMatrix(res, ground_truth)) {
157 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, valid):\n" << res << std::endl;
166 double ground_truth[5 * 7] = { 0, 0, 1, 2, 3, 4, 5, 0, 8, 14, 20, 26, 32, 26, 12, 36, 50, 64,
167 78, 92, 58, 24, 64, 86, 108, 130, 152, 90, 36, 84, 97, 110, 123, 136, 77 };
169 std::cout <<
"A:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(B, A, full):\n" << res << std::endl;
171 if (res.
getRows() != 5 || res.
getCols() != 7 || !compareMatrix(res, ground_truth)) {
177 double ground_truth[4 * 2] = { 20, 26, 64, 78, 108, 130, 110, 123 };
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;
228 double ground_truth[6 * 6] = { 128, 32, 122, 119, 31, 78, 88, 179, 252, 208, 154, 139,
229 151, 275, 291, 378, 281, 154, 79, 271, 423, 366, 285, 106,
230 48, 171, 248, 292, 230, 31, 16, 92, 194, 167, 39, 2 };
232 std::cout <<
"A:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, full):\n" << res << std::endl;
234 if (res.
getRows() != 6 || res.
getCols() != 6 || !compareMatrix(res, ground_truth)) {
240 double ground_truth[4 * 4] = { 179, 252, 208, 154, 275, 291, 378, 281, 271, 423, 366, 285, 171, 248, 292, 230 };
242 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, same):\n" << res << std::endl;
244 if (res.
getRows() != 4 || res.
getCols() != 4 || !compareMatrix(res, ground_truth)) {
250 double ground_truth[2 * 2] = { 291, 378, 423, 366 };
252 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, valid):\n" << res << std::endl;
254 if (res.
getRows() != 2 || res.
getCols() != 2 || !compareMatrix(res, ground_truth)) {
261 std::cout <<
"Catch an exception: " << e.
what() << std::endl;
unsigned int getCols() const
unsigned int getRows() const
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
const char * what() const
static bool equal(double x, double y, double threshold=0.001)
Implementation of a matrix and operations on matrices.
static vpMatrix conv2(const vpMatrix &M, const vpMatrix &kernel, const std::string &mode)