| 959 | } |
| 960 | |
| 961 | std::vector<py::object> ToPython(const nvcv::ImageData &imgData, std::optional<nvcv::TensorLayout> userLayout, |
| 962 | py::object owner) |
| 963 | { |
| 964 | std::vector<py::object> out; |
| 965 | |
| 966 | auto pitchData = imgData.cast<nvcv::ImageDataStrided>(); |
| 967 | if (!pitchData) |
| 968 | { |
| 969 | throw std::runtime_error("Only images with pitch-linear formats can be exported"); |
| 970 | } |
| 971 | |
| 972 | for (const auto &[info, layout] : ToPyBufferInfo(*pitchData, userLayout)) |
| 973 | { |
| 974 | if (pitchData->cast<nvcv::ImageDataStridedCuda>()) |
| 975 | { |
| 976 | // TODO: set correct device_type and device_id |
| 977 | out.emplace_back(ExternalBuffer::Create( |
| 978 | DLPackTensor{ |
| 979 | info, |
| 980 | {kDLCUDA, 0} |
| 981 | }, |
| 982 | owner)); |
| 983 | } |
| 984 | else if (pitchData->cast<nvcv::ImageDataStridedHost>()) |
| 985 | { |
| 986 | // With no owner, python/pybind11 will make a copy of the data |
| 987 | out.emplace_back(py::array(info, owner)); |
| 988 | } |
| 989 | else |
| 990 | { |
| 991 | throw std::runtime_error("Buffer type not supported"); |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | return out; |
| 996 | } |
| 997 | |
| 998 | } // namespace |
| 999 |
no test coverage detected