dusty-nv / jetson-utils

C++/CUDA/Python multimedia utilities for NVIDIA Jetson
MIT License
728 stars 287 forks source link

Need to read the stream in only 3 channels i.e. RGB not 4 channels i.e. RGBA. How to do it? #15

Open gopalkalpande opened 4 years ago

gopalkalpande commented 4 years ago

I'm doing object detection using the TensorFlow object detection API. For that, the detection model accepts the input tensor in the shape [<tf.Tensor 'image_tensor:0' shape=(None, None, None, 3) dtype=uint8>]; but after using CudaToNumpy the shape is (None, None, None, 4). I tried to convert 4 channel feed to 3 channel feed but there is a loss of information in that.

Captured by gStreamer, original image with 4 channels: 134

After conversion to 3 channels: 139

Please tell me if there is any way to convert the 4 channels to 3 channels without losing the information.

For this conversion, I have used : img = cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)

and passed the numpy array as img.

ZFTurbo commented 4 years ago

Use img = cv2.cvtColor(img, cv2.COLOR_RGBA2RGB)