Can't get the colors right after jetson.utils.cudaToNumpy conversion

Hello,
The main problem i have is accessing the images from cuda memory(İmage pixels) for drawing lines, crop images or ROI…
For the lack of methods in glDisplay( jetson.utils.glDisplay ) i want to use openCv. I converted to cuda memory to np array and it looks like working fine( i still have no idea how much processing it ll cost to me).

After conversion, the image colors are breakdown. I wonder is there any way to fix the showed colors to normal.

img, width, height = camera.CaptureRGBA(zeroCopy=1)
CV2img = jetson.utils.cudaToNumpy(img, width, height, 4)

detections = net.Detect(img, width, height, opt.overlay)

cv2.imshow(“DetectNet”, CV2img / 255)

1 Like

Hi,

OpenCV arrange image with BGR format.
It’s recommended to add a color converter to see if helps first.

Thanks.

Hi,
Thank you it solved the color problem with this conversion as u said.

img, width, height = camera.CaptureRGBA(zeroCopy=1)
CV2imgRGBA = jetson.utils.cudaToNumpy(img, width, height, 4)
CV2img = cv2.cvtColor(CV2imgRGBA, cv2.COLOR_RGBA2BGR);
…
detections = net.Detect(img, width, height, opt.overlay)
…
cv2.imshow(“DetectNet”, CV2img / 255)

Colors get normal but now some raws of image pixels are coming different: Image

1 Like

Hi,

Suppose the original image is RGB rather than RGBA.
Would you mind to give cv2.COLOR_RGB2BGR a try?

Thanks.

Cuda2Cv.py module : it’s working.

import cv2
import jetson.utils

def cuda2cv(cuda_img, width, height):
    CV2imgRGBA = jetson.utils.cudaToNumpy(cuda_img, width, height, 4)
    CV2img = cv2.cvtColor(CV2imgRGBA, cv2.COLOR_RGBA2BGR)
    return (CV2img / 255)

Client side :

from Cuda2Cv import cuda2cv
cv2img = cuda2cv(cuda_img, width, height)
cv2.imshow("cv2_img", cv2img)