sepFilter2d on a ROI reading out of bounds?

asked 2014-02-25 22:19:50 -0600

updated 2014-02-26 01:54:21 -0600

berak gravatar image

Hi, I'm having a very strange problem with sepFilter2d. It is repeatable, but it's in a large application and I've been unable to make a simple case fail.

I am given varying sized rectangles in a video which I need to process. The first step is to do color conversion and then do some filtering. If I allocate a new Mat the exact size of the rectangle, which I copy the input data into, everything works fine.

What I'd like to do is to create a larger Mat which I can reuse, by creating a Mat myROI (largerMat, Range(0, h), Range (0, w)). If I get a new image in which is larger than my Mat, I destroy and reallocate a larger one.

However, sepFilter2d does not seem to like working with a cropped image. It gives me NAN in the results. If I set all the pixels outside of the ROI to 0, it does not give me any NANs, but the results are not correct. I'm certain my allocation technique is working, as every other operation I do on these images works perfectly fine (output of color conversion looks good).

This is on opencv (win7, x64, vs2012, TBB enabled), but I believe 2.4.8 also exhibits this behavior.

Has anyone come across this before? Any suggestions for how to work around this, other than creating and destroying a brand new Mat of the exact size on each frame? The goal is to do this as quickly as possible, shaving every millisecond counts here and it's not just one image I want to preallocate but approx 300 per frame.

edit retag flag offensive close merge delete