04-07-2020 05:33 PM
Hi everyone. I am trying to create a DLL in C++ using OpenCV but I do not know how to read an image in my DLL. The inputs for the DLL are:
- An image RGB (ImageSrc) that was taken by a camera.
- An image (ImageF) which I would use to save the grayscale image of ImageSrc.
The function I use for my DLL is the following:
DLLIMPORT int HelloWorld(void* ImageSrc, void* ImageF)
{
cv::Mat colorMat = cv::Mat(488, 648, CV_8UC3, ImageSrc);
cv::Mat greyMat = cv::Mat(488, 648, CV_8UC1, ImageF);
cv::cvtColor(colorMat, greyMat, cv::COLOR_RGB2GRAY);
int k = 0;
return k;
}
But LabView crashes when I use the DLL. How could I process the image?.
Note: I know LabView could convert an RGB image to grayscale but I want to try if this DLL could be faster.
04-08-2020 01:26 AM - edited 04-08-2020 01:35 AM
Image manipulation isn't trivial. Each software uses its own memory representation for an image. That is true for IMAQ Vision as well as for OpenCV and the formats are generally never ever the same between two software packages.
OpenCV is more than complex enough that you can't really hope to adapt LabVIEW to its DLL interface with only using the Call Library Node. You will have to bite the sour apple and use an intermediate DLL written in C++ to convert between LabVIEW friendly datatypes and what the OpenCV library needs. Also much of the modern OpenCV API is actually using C++ classes and that is something you simply can't interface to with the Call Library Node.
Now writing that library would be a major effort, but fortunately some souls out there have done most of that work already for you. There are several libraries around in GIT repos that have made a start in this. In the best case you just can use them, worst case you may have to extend them a little to support a specific function you want to use. There is also an unofficial (unsupported) Toolkit from NI itself which you can download as VIPM package.
But because of the adaption necessary to convert images between the MAQ Vision format and the OpenCV format back and forth you won't really be able to see any speed improvement for single operations. It only potentially starts to pay off if you can place a whole chain of image analysis routines into OpenCV. Also OpenCV isn't necessarily faster than IMAQ Vision although there are certainly examples where it is as it may use different algorithms (with different actual results too). Another reason to use OpenCV might be if it provides a specific function that is not present in IMAQ Vision.