Ask Your Question
0

I'm trying to crop Image using cv2.cuda and I tried cuda_gpumat.adjustroi()

asked 2020-01-29 07:51:05 -0600

Imran B gravatar image

Hi all,

I'm trying to crop image using cv2.cuda. I done crop with cv2.UMat

With UMat

cropped = cv2.UMat(p, [minX, maxX], [minY, maxY])

With cv2.cuda_gpumat.adjustroi()

cropped = p.adjustROI(minX, maxX, minY, maxY)

My Code :

import cv2

#im=cv2.imread('Remap.png')
im = (1024,1024,3)
print(im.shape)
a=(im.shape[0]*2,im.shape[1]*2)
gpu = cv2.cuda_GpuMat()
gpu.upload(im)

b=cv2.cuda.resize(gpu,a)
print(b.size())
maxX=500
maxY=500
minX = 500
minY= 500
b.adjustROI(maxY,minY, minX, maxX)
print("Adjust ROI : ",b.size())
cropped = cv2.UMat(a, [minX, maxX], [minY, maxY])
print("Umat : ",cropped.size())
edit retag flag offensive close merge delete

Comments

2

and the problem is ?

berak gravatar imageberak ( 2020-01-29 07:52:27 -0600 )edit
1

You got wrongly. The 500( maxX and maxY) is too far but depending on sizes of image.

maxX=500
maxY=500
minX = 500
minY= 500

And your problem doesn't showing an error b.adjustROI(maxY,minY, minX, maxX)

supra56 gravatar imagesupra56 ( 2020-01-30 09:25:30 -0600 )edit
1

Do not used multiply operation a=(im.shape[0]*2,im.shape[1]*2). You're setting 2048 x 2048.

supra56 gravatar imagesupra56 ( 2020-01-30 09:31:23 -0600 )edit

I'm trying to resize it and then crop it.

Imran B gravatar imageImran B ( 2020-02-03 01:34:32 -0600 )edit

Does the answer help resizing with cuda and this too

supra56 gravatar imagesupra56 ( 2020-02-03 05:01:59 -0600 )edit
1

Does this work?

a=(im.shape[0]*2,im.shape[1]*2)

to:

a, b=(im.shape[0]*2,im.shape[1]*2)

Then:

b=cv2.cuda.resize(gpu,(a)

to

b=cv2.cuda.resize(gpu, (a,b))
supra56 gravatar imagesupra56 ( 2020-02-03 05:27:13 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-01-29 22:45:23 -0600

Imran B gravatar image

updated 2020-01-29 22:48:09 -0600

Actually I don't know how to use crop but now I got the answer. Thanks for efforts.

Code :

import cv2

im = (1024,1024,3)
print(im.shape)
a=(im.shape[0]*2,im.shape[1]*2)
gpu = cv2.cuda_GpuMat()
gpu.upload(im)

maxX=500
maxY=500
minX = 500
minY= 500

cropped = cv2.cuda_GpuMat(gpu, (minY, minX, maxY,maxX))
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-01-29 07:51:05 -0600

Seen: 3,014 times

Last updated: Jan 29 '20