Obtaining opencv UMat shape in python
Is there a direct way to obtain shape (number of cols and rows) of UMat array without converting it first to numpy object in Python?
Try This:
import cv2
img = cv2.UMat(cv2.imread("image.jpg", cv2.IMREAD_COLOR))
imgUMat = cv2.UMat(img)
gray = cv2.cvtColor(imgUMat, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (7, 7), 1.5)
gray = cv2.Canny(gray, 0, 50)
cv2.imshow("edges", gray)
cv2.waitKey()
Asked: 2018-03-22 12:42:06 -0600
Seen: 24,224 times
Last updated: Mar 22 '18
looking at
there clearly is no way to do so, without calling
get()
(which does a copy to a cpu numpy array)but: whatever there is in your UMat, it has been a numpy array before, and you probably should have taken the shape from that earlier on.
Well, not exactly. There are some cases when shape of result is unknown. In my case it is result of function:
cv2.findNonZero()
. I have to repeat this function few hundred times per second and callingUMat.get()
every time cost a lot. It is very inconvenient that UMat class is missing such basic method.well, what about looking at the docs and
safely assume:?(but again i do understand your issue here, it's somewhat inconsistent)Quick test:
src.shape == dst.shape is not true.
ok. your point ;)
pr 13957