CudaMemcpy Image Data with Conversion from Hwc to Chw

Imagine that we have some OpenCV usual image Mat:

cv::Mat usual_image = cv::imread(...)

This image stored as HWC/NHWC array in memory.

If that possible to copy this image as CHW/NCHW (separated channel arrays, in sense) into cuda memory without super high cost cv::split?

Just for visualization HWC and CHW:

2

1 Answer

The fastest way to do this will be to copy the image as-is to the GPU, then write a GPU kernel to split the data into 3 buffers.

A slower alternative would be to use 3 calls to cudaMemcpy2D to copy the data from host to device, one call per plane.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest