CV-CUDA icon indicating copy to clipboard operation
CV-CUDA copied to clipboard

[QUESTION] : Must the shape of the output tensor for warp_affine_into be same with its input tensor?

Open xxmiprai opened this issue 1 year ago • 5 comments

In opencv's warpAffine,we can specify the size of the output image through the dsize parameter. In cvcuda,if I want specify the size of the output image, I tried to specify the output tensor's shape,I want to know if it is correct approach. The following code snippet, I want to affine from a large image to obtain a small image:

# opencv
warped_img_cv2 = cv2.warpAffine(image, mat, (256, 256), borderValue=0.0)

#cvcuda
inverted_mat = cv2.invertAffineTransform(mat)
warped_img_cvcuda = cvcuda.Tensor((256, 256, 3), np.uint8,"HWC")
cvcuda.warp_affine_into(
                    dst=nvcv_img256,
                    src=image,
                    xform=inverted_mat,
                    flags=cvcuda.Interp.LINEAR,
                    border_mode=cvcuda.Border.CONSTANT,
                    border_value=[0])

xxmiprai avatar May 09 '23 08:05 xxmiprai

same question

cucdengjunli avatar Jun 05 '23 08:06 cucdengjunli

兄弟,我决定再接一个constomcrop,自己裁剪

cucdengjunli avatar Jun 06 '23 07:06 cucdengjunli

用warpaffineinfo这个函数可以搞定size问题,我有空的时候贴清晰的代码上来

cucdengjunli avatar Jun 07 '23 03:06 cucdengjunli

You have to set dst dimension as you desire. This work for me.

dst = torch.empty((h, w, c), device='cuda').to(torch.uint8)
dst = cvcuda.as_tensor(dst, 'HWC')

jarun-title avatar Jul 16 '24 04:07 jarun-title

用warpaffineinfo这个函数可以搞定size问题,我有空的时候贴清晰的代码上来

老哥,可以瞅瞅你的代码不,我试了个不同尺寸的输出,会报内存对齐问题

sqhuang avatar Sep 29 '24 10:09 sqhuang