Passing a matlab array into C# DLL

3 ビュー (過去 30 日間)
John
John 2013 年 2 月 7 日
I have C# interfaces to a proprietary (internal) image processing library.
Interfaces look something like this:
void RGBConvert::ConvertFromRGBToYCbCr(
int ncols,
int nrows,
IntPtr rgb,
IntPtr out)
Where IntPtr is a pointer to the underlying memory. I have called .NET objects many times from Matlab, but passing large data arrays into C# is not something I've done, and am reaching a dead end.
The Matlab manual: http://www.mathworks.com/help/matlab/matlab_external/handling-net-data-in-matlab_bte9oxc-1.html#bte9o7y-1 indicates that IntPtr is not supported. By which I mean, it doesn't covert an array of Unsigned8Bit integers into an IntPtr to pass to the method. (If you construct an IntPtr through some other mechanisms, Matlab will treat it like any other .NET object and pass it around.) So, how do I find a pointer to the Matlab data, and pass it to this method?
Clearly, one approach would be to use the normal Matlab C/C++ interfaces to "trick" matlab into revealing the pointer to the underlying array data structure, and then pass that pointer to the IntPtr constructor. Then pass the IntPtr on. We had hoped to have a "pure" C# implementation, and to not have to have a C/C++ interface in addition to the C# interface.
Another avenue might be to take the Matlab ConvertArray call, to convert a matlab array to a .NET array, but then I still need an IntPtr pointing at the raw data.
I don't mind extraneous memory copies here, this is not performance critical code, this is experimentation code.
Anyone have experience with this issue, and recommendations?
Thoughts?

回答 (1 件)

Conrad
Conrad 2013 年 2 月 8 日
Hi John, what about creating a wrapper method with signature
double[,] RGBConvertWRP(int ncols,
int nrows,
double[,] rgb)
and then using NET.convertArray to pass the rgb variable to this new method? You can then just call your original RGBConvert method from this newly created wrapper method?
Conrad
  1 件のコメント
John
John 2013 年 2 月 12 日
@Conrad the NET.convertArray calls create .NET arrays, and not c++ arrays, which is what an IntPtr points to.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCall MATLAB from .NET についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by