I'm working with a new version of a facetracker which provides some headerfiles which I used to write a dll file. This file is later used with Unity 3D. Because my Unity version just works with c# I had to write a Wrapper and that is where the trouble started. I don't know why the company from the facetracker decided to change some functions in a way that it is more complicated to work with as with the version before.
Here is the declaration of one specific function from the c++ header:
virtual bool SetFromRawBuffer(const unsigned char * rawImageData, Format format, int width, int height, Origin origin) = 0;
cpp file:
C_API bool IImage_SetFromRawBuffer(IImage *pObj, const unsigned char* rawImageData, IImage::Format format, int width, int height, IImage::Origin origin) {
if(pObj) {
return pObj->SetFromRawBuffer(rawImageData, format, width, height, origin);
}
return false;
}
c#: (Because I didn't know how to handle the enums I just copied them from the original header to my own enumeration.cs.)
[DllImport(@"C:\Users\mad1Z\Desktop\LiveDriverNativeWrapper NEW\LiveDriveNativeWrapper_packed\Release\LiveDriverNativeWrapper.dll")]
static private extern bool IImage_SetFromRawBuffer(IntPtr pObj, byte[] data, Enumerations.Format format, int width, int height, Enumerations.Origin origin);
definition c#:
public bool SetFromRawBuffer(byte[] data, Enumerations.Format format, int width, int height, Enumerations.Origin picorigin)
{
return IImage_SetFromRawBuffer(m_pObj, data, format, width, height, picorigin);
}
and here is the function call which crashes Unity 3D:
if (inputFrame.SetFromRawBuffer(data, Enumerations.Format.BGRX8888, 640, 480, Enumerations.Origin.TopLeft))
I'm also not sure if I'm using the correct format. I just get imagedata from my webcam and store it in a buffer (data) which is then send to the FaceTracker.
here the Format definition from the original header file:
/// @brief Each member of the following Format enum represents the order the channels
/// are encountered as one walks the memory, byte by byte, from lower to higher addresses.
///
/// So for example, RGBX8888 means that walking the memory byte by byte from lower to higher addresses,
/// one would expect to encounter R first, G next, and B and X afterwards. Equivalently, on little endian
/// machines, if the data is read in word-sized chunks, one would expect to find R in bits 0-7, B in 8-15,
/// G in 16-23, and X in 24-31.
///
/// Often you will see documentation stating that images are RGB. On Windows, however, these are actually laid
/// out in memory as BGR. For instance Windows bitmap BI_RGB format actually has data laid out as BGR in memory.
/// Similarly, in DirectShow, when the webcam format is RGB, the data is laid out BGR.
///
/// Finally, BGRX8888 is the preferred format performance-wise, as all code paths are heavily optimized internally
/// with that layout in mind. For best performance, prefer to provide images in BGRX8888 over other supported formats.
/// @if LIVE_DRIVER_SDK_FACEPAINT
/// In addition, all face painting operations happen on BGRX888 data. Therefore, the image returned to you in
/// IOutputFrameFacePaint::GetFacePaintImage will be in BGRX888 format.
/// @endif
enum Format
{
// RGB formats
BGRX8888,
RGBX8888,
BGR888,
RGB888,
// Grayscale formats
Intensity8,
// YUV 4:2:2 formats
YUV_UYVY, // YUV_Y422, YUV_UYNV
YUV_YUY2, // YUV_YUYV, YUV_YUNV
YUV_YVYU,
// YUV 4:2:0 formats
YUV_NV12,
YUV_NV21, // YUV_420sp
YUV_YV12, // YUV_420p
YUV_IYUV, // YUV_I420
FormatCount,
FORMATERROR = 0
};
If you need some more Information please let me know.