Merge pull request #29360 from abhishek-gola:exotic_cast_operations

Support ONNX Cast/CastLike for FP8/FP4/INT4/UINT4/E8M0 dtypes - #29360

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Abhishek Gola
2026-08-31 11:35:29 +05:30
committed by GitHub
parent 1e0a222d11
commit 0627765f01
12 changed files with 645 additions and 226 deletions

View File

@@ -315,8 +315,8 @@ bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo& info)
template<>
PyObject* pyopencv_from(const cv::Mat& m)
{
// NumPy has no bfloat16 dtype: widen CV_16BF to float32 (lossless).
if( m.depth() == CV_16BF )
// NumPy has no bfloat16 or float8 dtype: widen these to float32 (lossless).
if( m.depth() == CV_16BF || m.depth() == CV_8F_E4M3FN || m.depth() == CV_8F_E4M3FNUZ )
{
cv::Mat m32f;
ERRWRAP2(m.convertTo(m32f, CV_32F));