Ask Your Question
0

OpenCV Python: can not pass UMat to calcHist

asked 2018-11-13 03:15:43 -0600

Daniel Sakhapov gravatar image

Hello, everyone!

I'm trying to pass cv2.UMat object to cv2.calcHist function:

a = np.arange(10, dtype=np.uint8)
b = cv2.UMat(a)
cv2.calcHist([b], [0], None, [10], [0, 10])

and I'm getting the error

TypeError: images is not a numpy array, neither a scalar

but it seems like cpp version of OpenCV allows using UMat as source image.

Is it me doing something wrong or python OpenCV doesn't allow using UMat as source image for calcHist?

edit retag flag offensive close merge delete

Comments

which opencv version, exactly ?

berak gravatar imageberak ( 2018-11-13 05:05:10 -0600 )edit

hmm, looks like a bug to me !

error is from here

and it seems, we need a UMat counterpart for this

would you be able to rebuild the cv2 bindings locally ?

berak gravatar imageberak ( 2018-11-13 05:50:27 -0600 )edit

hi there, the version is 3.4.3. I've installed opencv using pip package opencv-python, do you think it can be the case?

Daniel Sakhapov gravatar imageDaniel Sakhapov ( 2018-11-13 09:00:13 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-11-13 07:02:05 -0600

supra56 gravatar image

Change this:

a = np.arange(10, dtype=np.uint8)

to

a = np.arange(0, 10, dtype=np.uint8)
edit flag offensive delete link more

Comments

no cigar here, sorry. (how does it solve anything ? and there is no difference at all)

(but maybe we should try with a real image (like the opencv logo above, converted to gray))

berak gravatar imageberak ( 2018-11-13 07:04:56 -0600 )edit

@berak. Take alook at this lcv2.UMATt

supra56 gravatar imagesupra56 ( 2018-11-13 07:36:08 -0600 )edit

yea, and it works fine with single UMat's. just not with arrays of it.

(which is the problem in the question, no ?)

berak gravatar imageberak ( 2018-11-13 07:52:44 -0600 )edit

@berak I don't understand " it works fine with single UMat's."

img = cv2.imread("c:/lib/opencv/samples/data/baboon.jpg")
b=cv2.UMat(img)
h1= cv2.calcHist(img, [0], None, [10], [0, 10])
h2=cv2.calcHist(b,[0],None,[10],[0,10])

Error :

Traceback (most recent call last):
  File "C:\Users\laurent\Documents\cours\TFcours\Python\ExemplePython\ChapitreIII\test.py", line 6, in <module>
    h2=cv2.calcHist(b,[0],None,[10],[0,10])
SystemError: <built-in function calcHist> returned NULL without setting an error
LBerger gravatar imageLBerger ( 2018-11-13 08:51:53 -0600 )edit

img = cv2.UMat(cv2.imread("c:/lib/opencv/samples/data/baboon.jpg"", cv2.IMREAD_COLOR))

supra56 gravatar imagesupra56 ( 2018-11-13 09:50:45 -0600 )edit

@LBerger: x = cv2.cvtColor(cv2.UMat(y), cv2.COLOR_BG2GRAY) works fine, and returns another UMat.

the arrays are the problem

berak gravatar imageberak ( 2018-11-13 09:58:14 -0600 )edit
1

HOk result Ok hNotOk result is not OK ! :

img = cv.imread("g:/lib/opencv/samples/data/baboon.jpg")
b=cv.UMat(img)
xisUmat = cv.cvtColor(b, cv.COLOR_BGR2GRAY)
hOK= cv.calcHist(img, [0], None, [10], [0, 10])
hOK= cv.calcHist([img], [0], None, [10], [0, 10])
hnotOK=cv.calcHist(b,[0],None,[10],[0,10])

and my cv2.cpp is here

LBerger gravatar imageLBerger ( 2018-11-13 11:15:05 -0600 )edit

does anyone have build/modules/python_bindings_generator/pyopencv_generated_funcs.h around ? we'd need to take a look at the wrapper for calcHist there.

berak gravatar imageberak ( 2018-11-14 03:59:32 -0600 )edit
1
1

lol, all 25k locs of it ;) but thanks, a ton ;)

i see a vector_Mat here, where a vector_UMat would be required. so i think, there are 2 problems: gen2.py generates the wrong type, and there is no correct pyopencv_to() overload for vector_UMat

berak gravatar imageberak ( 2018-11-14 06:40:16 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-11-13 03:15:43 -0600

Seen: 1,099 times

Last updated: Nov 13 '18