Hello everyone!
I'm having some very weird issues with the Python bindings of OpenCV. I'm trying to use the dft function (amongst others) to compute correlations between long arrays of 1D data (think >=8192 samples).
If I set up a loop in my program and try to compute the same operations on the same input data several times (according to that loop) I get wildly different results. The correct result is the one that appears most times but still, sometimes it is not even 50% of the attempts (and whatever... it should be 100% same anyway!). It looked systematic at the beginning, but later I noticed that I could get varying degrees of success on different runs.
Trying to track the error, I debugged the code using Pydev and got to a line like this inside the loop (there are many other dfts in the code, this is the first one in the loop):
outputarray = cv2.dft(inputarray,flags=cv2.DFT_COMPLEX_OUTPUT)
Where inputarray
is a constant array of real integers, one that has always the same contents (verified with the Pydev debugger). While the first iteration finishes perfectly fine, in the second iteration of the loop, outputarray
has changed according to Pydev, despite using the same input and flags. Also, its max and min return "nan". It may return correct values in later iterations though.
I cannot post the source as is, but more or less it would be something like:
import numpy
import cv2
for i in nloops:
code
code
#functionA is set up to return always the same 1 channel ndarray
#for debugging of this problem, and it works as intended. (Thanks Pydev!)
inputarray = functionA(...)
#First cv2 operation, which already fails in the second iteration of the main loop:
outputarray = cv2.dft(inputarray,flags=cv2.DFT_COMPLEX_OUTPUT)
#Then another internal loop comes that uses outputarray internally:
for j in rangevector:
operations #More cv2.dft() and other openCV functions appear here
code
code
#end of function
All of this leads to me to thinking this is a bug within OpenCV (or its Python 2 bindings), but I struggle to believe such error flew under the radar during testing of several OpenCV releases (I tried with stock Ubuntu 14.04 and 15.04 64 bits).
Any useful advice? I will provide more information if needed.
Thank you very much!