Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I've come across the same problem using the cv2.compareHist function in the Python API (which basically calls the same code as the C++ function once data structures have been wrapped / converted). I tried a minor modification - using a 2D array rather than a 3D array - and it worked. I think there is a bug in compareHist in histogram.cpp - as the error message says, it asserts:

H1.type() == H2.type() && H1.type() == CV_32F

but I think that H1.type() == CV_32F returns false if it's a 3D histogram, as H1.type() is no longer CV_32F - it might be something like CV_32FC3 or CV_32FC4, which is stored as a different number (see CV_MAKE_TYPE macro). I believe it could be fixed by using CV_MAT_DEPTH(H1.type()) == CV_32F, although I haven't checked the code. I'll see if I can find a suitable place to file a bug.

I've come across the same problem using the cv2.compareHist function in the Python API (which basically calls the same code as the C++ function once data structures have been wrapped / converted). I tried a minor modification - using a 2D array rather than a 3D array - and it worked. I think there is a bug in compareHist in histogram.cpp - as the error message says, it asserts:

H1.type() == H2.type() && H1.type() == CV_32F

but I think that H1.type() == CV_32F returns false if it's a 3D histogram, as H1.type() is no longer CV_32F - it might be something like CV_32FC3 or CV_32FC4, which is stored as a different number (see CV_MAKE_TYPE macro). I believe it could be fixed by using CV_MAT_DEPTH(H1.type()) == CV_32F, although I haven't checked the code. I'll see if I can find a suitable place to file a bug.

EDIT: I've sent a pull request to change H1.type() to H1.depth(). If this gets accepted and merged, the issue should be fixed in future OpenCV versions.