Jump to content

Creating a shared Object with Opencv


Recommended Posts

I am trying to create to shared library with opencv to acess a picture. I have no experience on this topic.

If anyone have a referece or example-code that can help me develope an understanding  i would be very thankful.

Rigth now i have created a shared libray to display a picture. But i get the error that Mat variable is not defined when it is called in labview.

I will be thankful for any suggestions.

Link to post
Share on other sites

I am using EmguCV.

You need to convert the mat into a bitmap, and if you are using the .NET PictureBox control, you have to create a graphics object, then use the ToBitmap method of the MAT to draw it.

OpenCV Draw mat.png

Edited by Gribo
EmguCV
Link to post
Share on other sites

I'm using labview on Linux, which does not support dotnet. So EmguCv is not an option. I thought about only using the C API in opencv to avoid 

name mangling and undefined variables issues, but the later version of opencv doesn't support C API. i'm now stuck at figuring out how to call the c++ function in 

a c calling conventtion.

example code:

#include <stdio.h>
#include <opencv2/opencv.hpp>


using namespace cv;
using namespace std;

extern "C"{

    int displayimage()
{
    Mat image(400,400, CV_8UC3, Scalar(0,0,255));
    image = imread("/home/ll/Dokumente/cpptest/lena.jpg", 1 );
    if ( !image.data )
    {
        printf("No image data \n");
        return -1;
    }
    namedWindow("Display Image", WINDOW_AUTOSIZE );
    imshow("Display Image", imread("/home/ll/Dokumente/cpptest/lena.jpg", 1 ));
    waitKey(0);
    return 0;
    }

int main(int argc, char** argv){
}

}

 

Link to post
Share on other sites

You can not call C++ objects with the Call Library Node without going into custom assembly programming. C++ is NOT binary compatible between compilers and often not even between compiler versions so there is no common ground on which the Call Library Node could even start to attempt to provide an interface to that.

What you have to do is developing your own shared library wrapper in C++ that exports standard C functions that you can then call with the LabVIEW Call Library Node. In the most simply case you could simply wrap each method of an object with a function like detailed in the labview wiki here: https://labviewwiki.org/wiki/DLL/shared_library

While this is the quickest approach to getting something working it is not the most convinient approach for other potential LabVIEW users of your library since you basically hurdle them with many C++ API intrinsicacies that a typical LabVIEW programmer has no idea about.

 

Link to post
Share on other sites
1 hour ago, Yaw Mensah said:

Thank you very much. Do you know a reference targeting Labview on linux for this matter. Wouldn´t i avoid this whole mess by only using an Opencv version 

with a c api?

Well, OpenCV has various parts which were C++ since a very long time, some of them with C wrappers but not everything. And they moved more and more to a C++ API as that makes writing code easier once the proper ground works are defined.

So for a pure C API you will need to go back quite a bit. Also while I haven't checked recently the OpenCV library did not remove the classic C API last I checked. Maybe they did in the meantime.

But image manipulation is not something you can easily interface to with the Call Library Node anyhow even if the API is pure C. The memory management problems associated with images are complicated enough that trying to directly interface this to LabVIEW is going to be a very painful exercise. LabVIEW is by nature a by value programming environment which would be terribly wasteful to apply to pictures. This means you have to somehow create an interface between the two anyhow that wraps the whole in a way that makes it intuitive to use in LabVIEW without the inherent overhead of treating everything by value. This is best written in C but with LabVIEW specialities in mind, and this is also what quite a big part of IMAQ Vision is actually about. So while you can try to interface to OpenCV directly up to some point, it's not going to make a pretty interface to use, since you will have to bother every user of your library with C specific trivia that a normal LabVIEW user is not used to (or write a huge interface layer in LabVIEW that wraps everything up and uses techniques that would be easier implemented in C(++).

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.