Skip to content
Snippets Groups Projects
Commit a6a1363d authored by Thibault Allenet's avatar Thibault Allenet
Browse files

Update tensorOpencv to avoid CopyCast with setDataType

parent aa4a1656
No related branches found
No related tags found
2 merge requests!10Update backend_opencv with modifications from aidge_core,!4Change tensorimpl opencv `future_std::span<cv::Mat>` to `cv::Mat`
...@@ -36,37 +36,39 @@ namespace Aidge { ...@@ -36,37 +36,39 @@ namespace Aidge {
std::vector<DimSize_t> matDims = std::vector<DimSize_t>({static_cast<DimSize_t>(mat.cols), std::vector<DimSize_t> matDims = std::vector<DimSize_t>({static_cast<DimSize_t>(mat.cols),
static_cast<DimSize_t>(mat.rows), static_cast<DimSize_t>(mat.rows),
static_cast<DimSize_t>(mat.channels())}); static_cast<DimSize_t>(mat.channels())});
// Create tensor from the dims of the Cv::Mat Aidge::DataType type;
std::shared_ptr<Tensor> tensor = std::make_shared<Tensor>(matDims);
// Set beackend opencv
tensor->setBackend("opencv");
// Set Data Type
switch (mat.depth()) { switch (mat.depth()) {
case CV_8U: case CV_8U:
tensor->setDataType(Aidge::DataType::UInt8); type = Aidge::DataType::UInt8;
break; break;
case CV_8S: case CV_8S:
tensor->setDataType(Aidge::DataType::Int8); type = Aidge::DataType::Int8;
break; break;
case CV_16U: case CV_16U:
tensor->setDataType(Aidge::DataType::UInt16); type = Aidge::DataType::UInt16;
break; break;
case CV_16S: case CV_16S:
tensor->setDataType(Aidge::DataType::Int16); type = Aidge::DataType::Int16;
break; break;
case CV_32S: case CV_32S:
tensor->setDataType(Aidge::DataType::Int32); type = Aidge::DataType::Int32;
break; break;
case CV_32F: case CV_32F:
tensor->setDataType(Aidge::DataType::Float32); type = Aidge::DataType::Float32;
break; break;
case CV_64F: case CV_64F:
tensor->setDataType(Aidge::DataType::Float64); type = Aidge::DataType::Float64;
break; break;
default: default:
throw std::runtime_error( throw std::runtime_error(
"Cannot convert cv::Mat to Tensor: incompatible types."); "Cannot convert cv::Mat to Tensor: incompatible types.");
} }
// Create tensor from the dims of the Cv::Mat
std::shared_ptr<Tensor> tensor = std::make_shared<Tensor>(matDims,type);
// Set beackend opencv
tensor->setBackend("opencv");
// Cast the tensorImpl to access setCvMat function // Cast the tensorImpl to access setCvMat function
TensorImpl_opencv_* tImpl_opencv = dynamic_cast<TensorImpl_opencv_*>(tensor->getImpl().get()); TensorImpl_opencv_* tImpl_opencv = dynamic_cast<TensorImpl_opencv_*>(tensor->getImpl().get());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment