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

Function ToPython

python/mod_cvcuda/nvcv/Image.cpp:961–996  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

959}
960
961std::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

Callers 1

cudaMethod · 0.70

Calls 2

ToPyBufferInfoFunction · 0.85
emplace_backMethod · 0.45

Tested by

no test coverage detected