Reputation: 25
I want to convert a UMat
to a different type.
I already tried using the UMat
method convertTo
which got me following error:
AttributeError: 'cv2.UMat' object has no attribute 'convertTo'
.
I also tried using the numpy
method np.float32
which appearently doesn't work with UMat
:
TypeError: float() argument must be a string or a number, not 'cv2.UMat'
I would use a numpy array but I need it in the UMat
format for other methods.
This is the code in question:
array255 = cv2.UMat(int(height), int(width), type=cv2.CV_8UC1, s=(255))
...
hsv_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
...
lhsv = cv2.split(hsv_frame)
s = cv2.subtract(array255, lhsv[1])
v = cv2.subtract(array255, lhsv[2])
#s = s.convertTo(cv2.CV_32F)
#v = v.convertTo(cv2.CV_32F)
s = np.float32(s)
v = np.float32(v)
Upvotes: 0
Views: 3559
Reputation: 2201
UMat
has method get()
, returning a numpy.array
. Call it, than use numpy
type conversion methods. E.g.
array255f = array255.get().astype('f')
Than you can convert it back to UMat
:
array255fum = cv2.UMat(array255f)
array255fum
will be of type cv2.CV_32F
.
Upvotes: 2