I've been getting the following ambiguous error when trying to use cv2.calcHist()
>>> img
array([ 1., 2., 3., 4., 5.])
>>> cv2.calcHist( [img], channels = [0], mask = np.ones(img.size), histSize = [6], ranges = [(0,6)])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
SystemError: error return without exception set
The error is so generic that I have absolutely no way of knowing what could be going wrong. You can find the function documented here. I am currently running OpenCV v2.3.1 as installed through MacPorts.
Thanks!
I find the online documentation a bit sparse for the Python interface.
One resource I find invaluable are the samples (OpenCV-2.3.x/samples/python2
), in which you can find example use of almost all the functions in the Python interface.
However looking at the documentation:
mask
argument must be 8-bit (mask.astype('uint8')
)img
should be CV_8U
or CV_32F
(so img.astype('uint8')
or img.astype('float32')
)And from looking at the python2
samples (camshift.py
,color_histogram.py
):
ranges
argument doesn't need to be a tuple, just a list (although the documentation suggests it should be a list of lists or array of arrays...)So:
cv2.calcHist( [img.astype('float32')], # <-- convert to float32
channels=[0],
mask=np.ones(img.size).astype('uint8'), # <-- convert to uint8
histSize=[6],
ranges=[0,6] ) # <-- flat list
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With