41 #include <visp3/core/vpMatrix.h>
42 #include <visp3/core/vpTime.h>
46 bool compareMatrix(
const vpMatrix &m,
const double *
const array)
48 for (
unsigned int i = 0; i < m.
getRows(); i++) {
49 for (
unsigned int j = 0; j < m.
getCols(); j++) {
89 double ground_truth[5 * 5] = {16, 50, 9, 22, 39, 69, 66, 59, 96, 50, 29, 88, 89,
90 82, 52, 40, 72, 95, 106, 27, 16, 64, 88, 34, 2};
92 std::cout <<
"A:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, full):\n" << res << std::endl;
94 if (res.
getRows() != 5 || res.
getCols() != 5 || !compareMatrix(res, ground_truth)) {
100 double ground_truth[4 * 4] = {66, 59, 96, 50, 88, 89, 82, 52, 72, 95, 106, 27, 64, 88, 34, 2};
102 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, same):\n" << res << std::endl;
104 if (res.
getRows() != 4 || res.
getCols() != 4 || !compareMatrix(res, ground_truth)) {
110 double ground_truth[3 * 3] = {66, 59, 96, 88, 89, 82, 72, 95, 106};
112 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, valid):\n" << res << std::endl;
114 if (res.
getRows() != 3 || res.
getCols() != 3 || !compareMatrix(res, ground_truth)) {
122 for (
unsigned int i = 0; i < A.getRows(); i++)
123 for (
unsigned int j = 0; j < A.getCols(); j++)
124 A[i][j] = i * A.getCols() + j;
127 for (
unsigned int i = 0; i < B.getRows(); i++)
128 for (
unsigned int j = 0; j < B.getCols(); j++)
129 B[i][j] = i * B.getCols() + j;
133 double ground_truth[5 * 7] = {0, 0, 1, 2, 3, 4, 5, 0, 8, 14, 20, 26, 32, 26, 12, 36, 50, 64,
134 78, 92, 58, 24, 64, 86, 108, 130, 152, 90, 36, 84, 97, 110, 123, 136, 77};
136 std::cout <<
"A:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, full):\n" << res << std::endl;
138 if (res.
getRows() != 5 || res.
getCols() != 7 || !compareMatrix(res, ground_truth)) {
144 double ground_truth[2 * 6] = {36, 50, 64, 78, 92, 58, 64, 86, 108, 130, 152, 90};
146 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, same):\n" << res << std::endl;
148 if (res.
getRows() != 2 || res.
getCols() != 6 || !compareMatrix(res, ground_truth)) {
155 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, valid):\n" << res << std::endl;
164 double ground_truth[5 * 7] = {0, 0, 1, 2, 3, 4, 5, 0, 8, 14, 20, 26, 32, 26, 12, 36, 50, 64,
165 78, 92, 58, 24, 64, 86, 108, 130, 152, 90, 36, 84, 97, 110, 123, 136, 77};
167 std::cout <<
"A:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(B, A, full):\n" << res << std::endl;
169 if (res.
getRows() != 5 || res.
getCols() != 7 || !compareMatrix(res, ground_truth)) {
175 double ground_truth[4 * 2] = {20, 26, 64, 78, 108, 130, 110, 123};
177 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(B, A, same):\n" << res << std::endl;
179 if (res.
getRows() != 4 || res.
getCols() != 2 || !compareMatrix(res, ground_truth)) {
186 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(B, A, valid):\n" << res << std::endl;
226 double ground_truth[6 * 6] = {128, 32, 122, 119, 31, 78, 88, 179, 252, 208, 154, 139,
227 151, 275, 291, 378, 281, 154, 79, 271, 423, 366, 285, 106,
228 48, 171, 248, 292, 230, 31, 16, 92, 194, 167, 39, 2};
230 std::cout <<
"A:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, full):\n" << res << std::endl;
232 if (res.
getRows() != 6 || res.
getCols() != 6 || !compareMatrix(res, ground_truth)) {
238 double ground_truth[4 * 4] = {179, 252, 208, 154, 275, 291, 378, 281, 271, 423, 366, 285, 171, 248, 292, 230};
240 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, same):\n" << res << std::endl;
242 if (res.
getRows() != 4 || res.
getCols() != 4 || !compareMatrix(res, ground_truth)) {
248 double ground_truth[2 * 2] = {291, 378, 423, 366};
250 std::cout <<
"\nA:\n" << A <<
"\nB:\n" << B <<
"\nvpMatrix::conv2(A, B, valid):\n" << res << std::endl;
252 if (res.
getRows() != 2 || res.
getCols() != 2 || !compareMatrix(res, ground_truth)) {
258 std::cout <<
"Catch an exception: " << e.
what() << std::endl;
unsigned int getCols() const
static vpArray2D< double > conv2(const vpArray2D< double > &M, const vpArray2D< double > &kernel, const std::string &mode)
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.