Filter2D Differences Between OpenCV 1 and Later Versions

I’m having issues porting some old OpenCV 1 code (or rather, it’s compiled with OpenCV but it uses the OpenCV1 api) to modern OpenCV 4.5.4. The Filter2D seems to be doing something weird. So this is moving from cvFilter2D to cv::filter2D.

I’ve confirmed the input matrices/images are the same between both versions.

The input source and kernel are both 32F images with values between -1 and 1. The kernel is quite large, over 100x100 in size. When running the filter, the old code produces what I’d expect - however, the newer version appears to be giving me -INF/+INFs only.

I’ve looked at the docs, and I don’t know if this is actually a difference or not or whether the OpenCV 1 docs weren’t well described. All it mentions is: “Convolves an image with the kernel. " The later versions state that " The function uses the DFT-based algorithm in case of sufficiently large kernels (~ 11 x 11 or larger) and the direct algorithm for small kernels.”, which would certainly be the case, but I don’t know if the old version does this or not. If it is a difference, then I don’t know what the way would be to run the direct algorithm if that’s what the original did.

Does anyone have any thoughts? Thanks.

Ok… think I solved it. It appears that somehow NaNs had entered the Mats in the calculations in the newer versions, whereas that didn’t happen with the old APIs. I read somewhere that it’s a difference in the way the divide works.

To think I spent all day working on this and this is what it was…

1 Like