user3369663
user3369663

Reputation: 35

How do you open a custom kernel with opencv?

All I want to do is apply a custom convolution matrix (kernel) to an image (mat or any other format is fine) in opencv.

I think there is some built in function that does it but I don't really understand it from the places I have seen it, and it seems that there are more than one possible ways to do it in opencv.

Does anyone know of a good/fast/efficient way of tackling this problem?

Upvotes: 2

Views: 5565

Answers (1)

Janco de Vries
Janco de Vries

Reputation: 204

If you have for example a 5x5 kernel:

Mat kern = (Mat_<char>(5, 5) << -1, -1, -1, -1, -1,
                                -1, -1, -1, -1, -1,
                                -1, -1, 24, -1, -1,
                                -1, -1, -1, -1, -1,
                                -1, -1, -1, -1, -1);

then you can use de filter2D function: http://docs.opencv.org/2.4/modules/imgproc/doc/filtering.html#filter2d

example for applying the custom kernel:

filter2D(src_image, dst_image, src_image.depth(), kern);

Hope it helps. :)

Upvotes: 3

Related Questions