Ask Your Question

Opencv cuda Merge returns Numpy array not GpuMat

asked 2020-03-02 03:13:56 -0500

Imran B gravatar image

Hi all, I'm trying to adjust hsv in images with cv2.cuda. while trying when I use cv2.cuda.merge it returns numpy array and not GpuMat type.

my code :

import cv2
import numpy as np

img =  cv2.imread('test.png')
imgMat = cv2.cuda_GpuMat(img)
imgSat = cv2.cuda.cvtColor(imgMat,cv2.COLOR_BGR2HSV)
print("Before Merge type : ",type(imgSat))
h,s,v = cv2.cuda.split(imgSat)
size_s = s.size()
w_s = cv2.cuda_GpuMat(size_s[1],size_s[0], s.type(), [30])
s = cv2.cuda.add(s, w_s)
te = cv2.cuda.merge([h,s,v])
print("After merge type : ",type(te))

Output :

Before Merge type :  <class 'cv2.cuda_GpuMat'>
After merge type :  <class 'numpy.ndarray'>

Anyone facing same scenario?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2020-03-03 05:04:41 -0500

Unfortunately merge currently needs to be modified to correctly return a GpuMat(). Try

cuImgMerge = cv2.cuda_GpuMat(imgSat.size(),imgSat.type())
cv2.cuda.merge([h,s,v],cuImgMerge )
print("After merge type : ",type(cuImgMerge))
edit flag offensive delete link more


Sure cudawarped .I'll use this method ,but is it affect performance?

Imran B gravatar imageImran B ( 2020-03-03 05:41:41 -0500 )edit

No, it improves performance if you pass in the dst arrays. If you don't a new GpuMat() will be allocated for dst every time the function is called.

cudawarped gravatar imagecudawarped ( 2020-03-03 05:52:40 -0500 )edit

Thank you cudawarped. It worked !!!

Imran B gravatar imageImran B ( 2020-03-12 05:39:47 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2020-03-02 03:13:56 -0500

Seen: 136 times

Last updated: Mar 03