Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

How we can use dlib's image data (parts & rect points) from c++ to c# using PInvoke method?

I am using Dlib - Face_detection_landmark.cpp in my c++ project.

my .cpp code as below :

__declspec(dllexport) char* FaceDetection( const wchar_t* filename)
{
    std::wstring ws(filename);
    String path(ws.begin(), ws.end());
    array2d<unsigned char> img;
    load_image(img, path);
    pyramid_up(img);
     
    frontal_face_detector detector = get_frontal_face_detector();

    // Now tell the face detector to give us a list of bounding boxes
    // around all the faces it can find in the image.
    std::vector<dlib::rectangle> dets = detector(img);
    std::string imageRect = "" + std::to_string(dets[0].left()) + 
                                  std::to_string(dets[0].left());

    char* pchr = (char*)imageRect.c_str();
    return pchr;
 }
}

And my c# code is :

[DllImport("FaceDetector.dll", 
           CallingConvention = CallingConvention.Cdecl, 
           CharSet = CharSet.Unicode)]
static extern string FaceDetection(string filename);

void main()
{
     string filename = "some path";
     string s = "";
     s = FaceDetection(filename);
}
     

Error : value of string s is null.

Anyone can help on this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...