tcsantini / EyeRecToo

Mirror to https://es-git.cs.uni-tuebingen.de/santini/EyeRecToo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect calls to cv::Sobel() in PuRe?

steven807 opened this issue · comments

It is hard to be sure with C++ being as unsafe as it is, but it looks like the two calls to cv::Sobel() take one too few arguments. They look like:

Sobel(blurred, dx, dx.type(), 1, 0, 7, 1, BORDER_REPLICATE);
Sobel(blurred, dy, dy.type(), 0, 1, 7, 1, BORDER_REPLICATE);

but the interface to cv::Sobel() is:

Sobel( InputArray src, OutputArray dst, int ddepth,
                         int dx, int dy, int ksize = 3,
                         double scale = 1, double delta = 0,
                         int borderType = BORDER_DEFAULT );

Note that the borderType parameter is in the 8th position, but the calls in PuRe.cpp put it at the 7th position. I'm guessing that there is a missing delta parameter. In OpenCV (3.4.2 at least), BORDER_DEFAULT is 1 (which means the value of delta being used here is 1), and the borderType being used is BORDER_DEFAULT, not BORDER_REPLICATE.

You are most definitely right: The delta parameter is missing, and as a result, the value 1 (the BORDER_REPLICATE macro) is being used for it and BORDER_DEFAULT for borderType.
Great spotting, thanks!

The consequence is a constant value being added to all the pixels, which doesn't really have any meaningful effect for our case. The fix is just adding delta as zero, i.e.:
Sobel(blurred, dx, dx.type(), 1, 0, 7, 1, 0, BORDER_REPLICATE);
Sobel(blurred, dy, dy.type(), 0, 1, 7, 1, 0, BORDER_REPLICATE);

C++ is not to blame though; blame me for my inattentiveness and OpenCV for not using a proper scoped enumeration for the parameter :-)