01-27-2022 12:30 AM
Can i use Open_CV C++ library with CVI??
01-27-2022 12:27 PM
As LabWindows/CVI is an ANSI C programming environment and as such doesn't support C++, no not easily.
OpenCV version 1.x had a C-interface API. Most things added since OpenCV version 2.0 are however fully C++ and generally do not have a C wrapper interface available.
So if you need very basic OpenCV functionality you may be able to get away with the old standard C API and call it from LabWindows/CVI, but you very quickly run into problems that the OpenCV APIs use C++ objects and template classes as parameters. At that point your exercise quickly ends.
If you are really determined you could use a C++ compiler to create standard C wrappers around specific OpenCV C++ classes and use that from LabWindows/CVI but it really quickly gets a major project if you need to access many different APIs from OpenCV.
Some people tried it before and got it to work here and here, but that is very old information and the OpenCV API has since only gotten more C++ specific so I would expect the header massaging to be more involved nowadays.
01-27-2022 11:48 PM
Hi rolfk,
Thank you for your responce,
One more question can we use Opencv with labView, as labView is also written on top of C++??
01-28-2022 01:54 AM - edited 01-28-2022 02:12 AM
Yes there exist some OpenCV interfaces for LabVIEW, but the fact that LabVIEW is written itself in C++ (and some C from older parts from last century) is not relevant here.
LabVIEW allows to call external libraries through the Call Library Node which calls into shared libraries (DLL, so). But this interface only supports calling C functions too, since the C++ ABI is different between compilers and even sometimes compiler versions. Also LabVIEW does not have anything in its functionality that could easily map to C++ classes (yes it has classes but they work considerably different under the hood than C++ and would not be a good match). LabVIEW also allows to call ActiveX Automation servers and .Net assemblies which would be how LabVIEW would have to interface to C++ DLLs, except that C++ DLLs do not contain any interface description resources that LabVIEW could read to create such an interface and no, C++ headers are NOT a proper interface description, just as C headers are not really a proper interface description and that is the reason why the Import Library Wizard in LabVIEW so often can NOT create proper LabVIEW interface libraries automatically. C++ interfaces however are a magnitude or two more complex than C interfaces and hence there is not even dreaming about coming up with such an Import Wizard and the according Call Library Node configuration would be so complex that really nobody could handle it, the current Call Library Node configuration is already to complex for at least 95% of LabVIEW users, since they do usually not really understand C programming specifics.
The NI Vision library for LabVIEW has built in support to interface to OpenCV which is the most easy way but of course requires the NI Vision Development Module license. If the whole purpose of this exercise is in the first place to get rid of this license you have to go with a different solution. NI has in the past published some non-official libraries (NI Labs licensed, meaning here is an example of how things can be done and it is a good start to develop further on but if it was a complete product we would have made one out of it and would be selling it for money) that allows calling OpenCV routines from LabVIEW. The way that works is that someone wrote a wrapper DLL (usually in Visual C++) that translates between the OpenCV C/C++ interface into a more LabVIEW friendly C interface that can be called by the Call Library Node. There are also community provided similar libraries but they are either not free or even less complete than the NI Labs version. After all creating such an interface is A LOT of work and most people do not have the time and luxury to spend months of their time in writing such libraries to just give them away for free for others to use in commercial projects.
I have come across many posts from people on these forums crying foul and mordio that there wasn't a specific library available for free for their specific problem, but when prompted to write one and publish it for free not a single one of them has ever responded in doing just that!
But don't cry victory to early just yet. That wrapper DLL does provide a standard C type interface but it is very much LabVIEW tailored as LabVIEW uses very specific data types for arrays and strings and you also need an easy manageable element in LabVIEW to represent an image. Due to this the according wrapper DLL would still not be easily consumable by a CVI program as you would have to try to emulate those specific LabVIEW data types somehow in LabWindows/CVI and that would quickly end up being at least as much effort as to write your own LabWindows/CVI specific wrapper DLL (in Visual C++) that converts the OpenCV classes into pointers and exports one C wrapper function for each method and property that you want to access from these objects.