Yaw Mensah Posted November 18, 2020 Report Share Posted November 18, 2020 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. Quote Link to comment
JKSH Posted November 18, 2020 Report Share Posted November 18, 2020 (edited) There are some examples and discussions on the NI forum: https://forums.ni.com/t5/Machine-Vision/Using-OpenCV-library-in-LabVIEW/td-p/648429?profile.language=en https://forums.ni.com/t5/LabVIEW/Creating-a-dll-in-Visual-Studio-2015-to-pass-an-image-through/m-p/3334086?profile.language=en Edited November 18, 2020 by JKSH Quote Link to comment
Gribo Posted November 18, 2020 Report Share Posted November 18, 2020 (edited) 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. Edited November 18, 2020 by Gribo EmguCV Quote Link to comment
Yaw Mensah Posted November 25, 2020 Author Report Share Posted November 25, 2020 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){ } } Quote Link to comment
Yaw Mensah Posted November 25, 2020 Author Report Share Posted November 25, 2020 Calling a function or use of a datatype from <opencv2/opencv.hpp> result in a name mangling or undefined variable issues. Quote Link to comment
Yaw Mensah Posted November 27, 2020 Author Report Share Posted November 27, 2020 Does anyone know the exact version when opencv droped the c api. Quote Link to comment
Rolf Kalbermatter Posted November 27, 2020 Report Share Posted November 27, 2020 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. Quote Link to comment
Yaw Mensah Posted November 27, 2020 Author Report Share Posted November 27, 2020 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? Quote Link to comment
Rolf Kalbermatter Posted November 27, 2020 Report Share Posted November 27, 2020 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(++). Quote Link to comment
Yaw Mensah Posted December 8, 2020 Author Report Share Posted December 8, 2020 Thanks for all your suggestion and the recommended references. Due to your help i was able to make a wrapper for some function in opencv 3.2. It is possible to use both c and c++ elements. Just needed to handle the name mangling and compile with a c++ compiler. Thank you all very much. 1 Quote Link to comment
Neil Pate Posted December 8, 2020 Report Share Posted December 8, 2020 16 minutes ago, Yaw Mensah said: Thanks for all your suggestion and the recommended references. Due to your help i was able to make a wrapper for some function in opencv 3.2. It is possible to use both c and c++ elements. Just needed to handle the name mangling and compile with a c++ compiler. Thank you all very much. Ah Lena, bet you never expected such fame. A little bit of light reading here. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.