Ask Your Question

Revision history [back]

Laplacian output in C++ excludes negative values, but not in Python

Note:

This is a duplicate of my SO question.

Observation

Performing the same Laplacian operation in C++ and Python appears to produce different results. Notably, the C++ variant does not report negative slopes in the result matrix.

Versions

  • OpenCV => C++ 3.4.1 and 4.4, Python 4.1.1
  • Operating System / Platform => Ubuntu 18.04
  • Compiler => g++

Similar issues:

  • There are several SO questions with similar reports, but they all appear to have some unrelated error. I list a few in my SO question.
  • An issue was reported on Github reports a similar platform problem, but it was fixed by not attempting to use the Laplacian function in place. I use clone() in my code to avoid this issue.
  • A question on this site appears almost identical, sadly it has no satisfactory answer.

Source code and files for duplication

Gist link to C++ and Python code

Image used as "tst.png"

Image used as "tst2.png"

Quick description of the code

My code is a pared down segment of a larger program where I want to extract the first derivative of pixel brightness on the points of a detected contour for discriminant analysis. I use two images for this in my sample program above to reduce the amount of code for a MWE.

Question:

Is there some simple issue I am not seeing in my code like the other similar (yet unrelated) questions I mention? I would like to make sure I have covered every possible solution before raising an Issue on Github.