MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / GetImageVectorFromTensor

Function GetImageVectorFromTensor

tests/common/TensorDataUtils.hpp:660–686  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

658// sets the tensor data to the value of data, but honors strides.
659template<typename DT>
660static void GetImageVectorFromTensor(const TensorData &tensorData, int sample, std::vector<DT> &outData)
661{
662 Optional<TensorDataAccessStridedImage> tDataAc = nvcv::TensorDataAccessStridedImage::Create(tensorData);
663
664 if (!tDataAc)
665 throw std::runtime_error("Tensor Data not compatible with pitch access.");
666 if (tDataAc->infoLayout().isChannelFirst())
667 return GetImageVectorFromTensorPlanar<DT>(tensorData, sample, outData);
668
669 if (tDataAc->numSamples() <= sample || sample < 0)
670 throw std::runtime_error("Number of samples smaller than requested sample.");
671
672 int elements = tDataAc->numRows() * tDataAc->numCols() * tDataAc->numChannels();
673
674 // Make sure we have the right size.
675 outData.resize(elements);
676
677 if (cudaSuccess
678 != cudaMemcpy2D(outData.data(), tDataAc->numCols() * sizeof(DT) * tDataAc->numChannels(),
679 tDataAc->sampleData(sample), tDataAc->rowStride(),
680 tDataAc->numCols() * sizeof(DT) * tDataAc->numChannels(), tDataAc->numRows(),
681 cudaMemcpyDeviceToHost))
682 {
683 throw std::runtime_error("CudaMemcpy failed");
684 }
685 return;
686}
687
688template<typename DT>
689void SetCvDataTo(TensorImageData &cvImg, DT data, Size2D region, uint8_t chFlags)

Callers 3

verifyOutputFunction · 0.85
TEST_PFunction · 0.85
TEST_PFunction · 0.85

Calls 9

isChannelFirstMethod · 0.80
numSamplesMethod · 0.45
numRowsMethod · 0.45
numColsMethod · 0.45
numChannelsMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45
sampleDataMethod · 0.45
rowStrideMethod · 0.45

Tested by 3

verifyOutputFunction · 0.68
TEST_PFunction · 0.68
TEST_PFunction · 0.68