Updated by Andrey Kamaev about 13 years ago

When applied to 3D histograms, @cv2.calcBackProject@ fails with the error message
<pre>
OpenCV Error: Assertion failed (rsz == dims*2 || (rsz == 2 && _1d) || (rsz == 0 && images.depth(0) == CV_8U)) in unknown function, file C:\slave\WinInstallerMegaPack\src\opencv\modules\imgproc\src\histogram.cpp, line 1358
Traceback (most recent call last):
File "backproject.py", line 17, in <module>
ranges=ranges, scale=1)
cv2.error: C:\slave\WinInstallerMegaPack\src\opencv\modules\imgproc\src\histogram.cpp:1358: error: (-215) rsz == dims*2 || (rsz == 2 && _1d) || (rsz == 0 && images.depth(0) == CV_8U)
</pre>
The following example allows to reproduce the problem using the Windows version of OpenCV 2.3.1, Python 2.7 and numpy 1.6.1.
<pre><code class="python"> <pre>
import cv, cv2
import numpy as np

image = cv2.cvtColor(np.zeros((480, 640), dtype=np.uint8), cv.CV_GRAY2BGR)
roi = cv2.cvtColor(np.empty((100, 100), dtype=np.uint8), cv.CV_GRAY2BGR)

roi[:] = 255

dims = 3 # cv2.calcBackProject works if dims is set to a value less than 3
channels = list(xrange(dims))
size = [4] * dims
ranges = [0, 255] * dims

hist = cv2.calcHist([roi], channels=channels, mask=None, histSize=size, ranges=ranges)
projection = cv2.calcBackProject([image], channels=channels, hist=hist, ranges=ranges, scale=1)
</code></pre> </pre>

Back