Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opencv: crop image on the GPU side

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?

like image 832
Marek Avatar asked Jan 29 '23 11:01

Marek


1 Answers

After some study of UMat class source code and tests I found this solution:

crop = cv2.UMat(image, [y0, y1], [x0, x1])
like image 165
Marek Avatar answered Jan 31 '23 23:01

Marek