Registered Member
|
Hi, I'm wondering why the following function
returns me the following error in compilation phase for the block method.
I want to cast the 3x3 block of a dynamic size matrix to a fixed size 3x3 and then compute the cwiseProduct with another 3x3 fixed size matrix, but it seems not possible. What am I doing wrong? |
Registered Member
|
Solution:
The following code implements a solution but I think a lot of temporaries are involved...
Maybe is useful for others like me... |
Registered Member
|
In the first program, the arguments of conv2d() are declared as DenseBase. This does not work because you cannot mix matrices and arrays in the same expression. Specifically, you cannot take the componentwise product of a matrix with an array. If 'mat' is a matrix (that is, of a subclass of MatrixBase), then "mat.cwiseProduct(other)" compiles only if 'other' is also of a subclass of MatrixBase. In your program, 'kernel' is of type DenseBase, which is not a subclass of MatrixBase, so the program does not compile.
In the second program, the arguments are declared as MatrixBase, so the componentwise product is between two matrices, and everything works. In fact, you can get rid of the casts and temporaries in the body of the double for loop and simply write: O.coeffRef(row,col) = I.block(row,col,KSizeX,KSizeY).cwiseProduct(kernel).sum(); |
Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]