| 658 | // sets the tensor data to the value of data, but honors strides. |
| 659 | template<typename DT> |
| 660 | static 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 | |
| 688 | template<typename DT> |
| 689 | void SetCvDataTo(TensorImageData &cvImg, DT data, Size2D region, uint8_t chFlags) |