This is my first time making a DLL and programming in C++, so please bear with me if I had made some fundamental mistakes.
I have made a DLL that reads images and performs Canny edge detection using the OpenCV libraries.
So I made a very simple LabVIEW program to test it --> [see attached image]
It worked fine, as long as the file was still open, so I saved and quit.
HOWEVER, when I restarted LabVIEW again and ran the same program, it stopped working and generated error 1097:
----
Error 1097 occurred in Call Library Function Node in Canny.dll:
An exception occurred within the external code called by the Call Library Function Node.
The exception may have corrupted LabVIEW's memory.
Save any work to a new location and restart LabVIEW.
----
The only way I got it to work again was to copy and paste the program contents into a new file, save and run.
It worked once again, as long as the file was open.
I also made a C++ program that calls the DLL, and it works fine, regardless of when it was called.
I have a feeling that it might have to do with memory allocation, but I'm not sure.
Any help would be appreciated.
ps. I am not permitted to upload .cpp, .dev, or .dll files for some reason.
#include "getpathdll.h"#include // C++ includes#include //#include // already included in getpathdll.h// OpenCV includes#include #include //#include //#include #define LoThresh 160#define HiThresh 160#define ApertureSize 3 // 1,3,5,7extern "C"{DLLIMPORT int cvApplyCanny();
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
return TRUE;
}
DLLIMPORT int cvApplyCanny ()
{
//Initialize error log? also line 93
char* LoadImagePath = fnGetPath("original", "01-11089.jpg");
IplImage* iniImage = cvLoadImage(LoadImagePath);
//Create a temporary and final image
IplImage* grayImage = cvCreateImage(cvSize(iniImage->width, iniImage->height), IPL_DEPTH_8U, 1);
IplImage* edgeImage = cvCreateImage(cvSize(iniImage->width, iniImage->height), IPL_DEPTH_8U, 1);
//Convert image to grayscale
cvCvtColor(iniImage, grayImage, CV_BGR2GRAY);
//Perform Canny edge detection
cCanny(grayImage, edgeImage, LoThresh, HiThresh, ApertureSize);
char* SaveImagePath = fnGetPath("canny", "YayWorked.jpg");
cvSaveImage(SaveImagePath, edgeImage);
// Destroy the images
cvReleaseImage(&iniImage);
cvReleaseImage(&grayImage);
cvReleaseImage(&edgeImage);
}
#undef DLLIMPORT