Home Create Mat from uint16 pointer
Reply: 0

Create Mat from uint16 pointer

user1284 Published in July 20, 2018, 1:19 am

I am discovering openCV and working on a project in which I have a C# Plugin which call a C++ DLL to do the treatments. C# deals with Mat but my partner send me a pointer to this matrix from C# to C++. So I am trying to use this pointer to create again a matrix because I don't know how to pass a Mat object between two differente langages through a DLL.

For now, my C++ method is :

double CustomData::calculate(LPVOID ptr)
    double sum = 0;
    UINT16* src = (UINT16*)ptr;

    for (int y = 0; y < _height; y++) {
        for (int x = 0; x < _width; x++) {
            sum += src[y*_width + x];
    return sum;

I want to use Mat from openCV now to see if the time of the calculation is faster for a mean, and also because I need to perform more operations on this matrix after. So I need to create a Mat object from the pointer I get. My best try is the next one :

Mat image(_height, _width, CV_16UC1, src);

But I get unsigned char as data of this matrix. I think I am using correctly the constructor so I think the problem is more in the pointer I pass to the function ?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.313776 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO