Hi Alexander,
It looks like Mat has a constructor like this:
Mat(int rows, int cols, int type, void* data, size_t step=AUTO_STEP);
If you had a type defined as
immutable Mat
handle::Ptr{Void}
end
for interoperability with OpenCV (this is your opaque type), then
schematically you could create it from an Image or Array like this:
function Mat(img::AbstractArray)
c = coords_spatial(img)
Mat(ccall((:libopencv, :Mat), Ptr{Void}, (Cint, Cint, Cint, Ptr{Void},
Csize_t), size(img, c[1]), size(img, c[2]), ??, pointer(data(img)), ??)
end
The ?? mean parts you'd have to fill in. I'm not sure what the step parameter
is for, but I suspect it's the stride along the color dimension. (Which must
be first, I guess?) If so, you'd want to check that the image is in color-first
order using colordim(img). While you might permute it if necessary, in my
opinion perhaps it would be better to force the user to do so explicitly, so
you don't encourage silent inefficient conversions.
This constructor would share the same underlying buffer between Julia and
OpenCV, so it is zero-copy.
--Tim