To speed up some operations I transfered image to GPU memory. After some processing I have to crop some area:
image = cv2.UMat(image)
...
crop = image[y1:y2,x1:x2]
The problem is that it is not possible to slice image inside GPU memory. Above code will raise error: "UMat object is not subscriptable". The solution I found is to transfer image back to numpy object, than slice it, and transfer back to GPU:
image = cv2.UMat(image)
...
image = image.get()
crop = image[y1:y2,x1:x2]
crop = cv2.UMat(crop)
...
But above solution looks costly, as transferring data to/from GPU memory takes time. I have a feeling that there is a way to crop an image within GPU memory. Any hints?
After some study of UMat class source code and tests I found this solution:
crop = cv2.UMat(image, [y0, y1], [x0, x1])
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