Commit 82c212ce authored by Patrik Huber's avatar Patrik Huber

Replaced dtype comparison with isinstance()

Apparently the dtype comparison compared pointer addresses, so it must've worked just by chance. Scary!
parent b84bb1a7
...@@ -143,19 +143,18 @@ struct type_caster<cv::Mat> ...@@ -143,19 +143,18 @@ struct type_caster<cv::Mat>
if (!buf) if (!buf)
return false; return false;
auto pyarray_dtype = buf.dtype();
// Todo: We should probably check that buf.strides(i) is "default", by dividing it by the Scalar type or something. // Todo: We should probably check that buf.strides(i) is "default", by dividing it by the Scalar type or something.
int opencv_depth; int opencv_depth;
if (pyarray_dtype == pybind11::dtype::of<std::uint8_t>()) if (pybind11::isinstance<pybind11::array_t<std::uint8_t>>(buf))
{ {
opencv_depth = CV_8U; opencv_depth = CV_8U;
} }
else if (pyarray_dtype == pybind11::dtype::of<float>()) else if (pybind11::isinstance<pybind11::array_t<float>>(buf))
{ {
opencv_depth = CV_32F; opencv_depth = CV_32F;
} }
else if (pyarray_dtype == pybind11::dtype::of<double>()) else if (pybind11::isinstance<pybind11::array_t<double>>(buf))
{ {
opencv_depth = CV_64F; opencv_depth = CV_64F;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment