You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
In the current implementation of MxArray, when passing some of the templated OpenCV data types back to MATLAB from a MEX file, the conversion ignores the template type and creates a double array no matter what. Example:
create_point.cpp
#include "mexopencv.hpp"
using namespace std;
using namespace cv;
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
Point_<int> p(1,2);
plhs[0] = MxArray(p);
}
MATLAB
>> p = create_point();
>> class(p) % this is double
This implicit conversion can show up in unexpected places.. For example cv.approxPolyDP that takes a vector of int points, returns the approximated points as type double.
From what I can tell, this applies to Point_<T>, Point3_<T>, Size_<T>, Rect_<T>, Scalar_<T>, and possibly other places...
Do you think this should be fixed, or is this by design (possibly because some code depends on it somewhere else)?
Here is what I had in mind to fix the constructor:
Yes, this is by design. The reason is that the default numeric type is double in matlab, and also integer arithmetic in matlab sucks. In my opinion, returning integer types is benefitial only for large arrays, such as pixels. Other than that, it's probably better to return values as double.
In the current implementation of
MxArray
, when passing some of the templated OpenCV data types back to MATLAB from a MEX file, the conversion ignores the template type and creates adouble
array no matter what. Example:create_point.cpp
MATLAB
This implicit conversion can show up in unexpected places.. For example
cv.approxPolyDP
that takes a vector ofint
points, returns the approximated points as typedouble
.From what I can tell, this applies to
Point_<T>
,Point3_<T>
,Size_<T>
,Rect_<T>
,Scalar_<T>
, and possibly other places...Do you think this should be fixed, or is this by design (possibly because some code depends on it somewhere else)?
Here is what I had in mind to fix the constructor:
where
ClassIDOf
is the same map defined inMxArray.cpp
that translates opencv types to matlab typesThe text was updated successfully, but these errors were encountered: