From 3220c1b35d09fa89cd392aeabc76224d4e1da924 Mon Sep 17 00:00:00 2001 From: Abhishek Gola Date: Fri, 9 Oct 2026 15:34:49 +0530 Subject: [PATCH] python: warn once when ml_dtypes is missing and bfloat16 / float8 are widened to float32 Signed-off-by: Abhishek Gola --- modules/python/src2/cv2_convert.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/python/src2/cv2_convert.cpp b/modules/python/src2/cv2_convert.cpp index e84287cc5a..dbd238234a 100644 --- a/modules/python/src2/cv2_convert.cpp +++ b/modules/python/src2/cv2_convert.cpp @@ -369,6 +369,9 @@ PyObject* pyopencv_from(const cv::Mat& m) if( PyArray_Descr* descr = mlDtypeDescrForCvDepth(m.depth()) ) return pyopencv_from_mldtype(m, descr); // Without ml_dtypes NumPy cannot name these; widen to float32 (lossless). + CV_LOG_ONCE_WARNING(NULL, "Python bindings: ml_dtypes package is not found, " + "bfloat16 / float8 arrays are returned as float32. " + "Install ml_dtypes to keep the exact dtype."); cv::Mat m32f; ERRWRAP2(m.convertTo(m32f, CV_32F)); return pyopencv_from(m32f);