ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

using OpenCV FileStorage in LabVIEW

Solved!
Go to solution

I'd like to use the OpenCV's FileStorage function in the LabVIEW. Mainly because I want to transfer a c++ project to a LabVIEW project.

But in this case, i can't load the xml file. 

i tested it in a consolo project, it seems to work.

 

here is the code:

 

 

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace std;
using namespace cv;

class myclass{
public:
FileStorage f;
Mat temp;
int loadfile(){
f.open("C:\\Users\\Silva\\Documents\\results\\text.xml",FileStorage::READ);
if(!f.isOpened())
return -1;
f["count"]>>temp;
return 0;
};
};

myclass temp;

extern "C"{
_declspec (dllexport) int loadfile();
}

_declspec (dllexport) int loadfile(){
int error_code;
error_code = temp.loadfile();
if(error_code!=-1)
return 0;
return -1;
}

0 Kudos
Message 1 of 15
(6,991 Views)

Hello,

 

first, did you try debugging the code?

 

Best regards,

K


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
0 Kudos
Message 2 of 15
(6,988 Views)

Thank you for your kindness.

 

Yes, i wrote it and tryed it as a consolo project, it seems work well. 

but when i change it to a dll project, labVIEW reported an error, 

 

 

0 Kudos
Message 3 of 15
(6,980 Views)

No, I meant debugging the calling .dll in Labview via the Visual Studio, or whatever programing environment you are using...

 

I know you've added the sorce code to the previous post, but can you also attach the .cpp file you are using?

 

Best regards,

K


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
0 Kudos
Message 4 of 15
(6,973 Views)

Thank you ,klemen.

Yes,I debugged it in VS2010,  and it worked well.(OpenCV2.4.8)

But when i call the dll in LabVIEW2011, it reported the error .

As you can see, i attached the cpp file, vi, xml file and dll as a zip file in the fisrt post.

 

0 Kudos
Message 5 of 15
(6,961 Views)

I am really sorry, somehow I missed that...

 

No error with your code here:

 

test.png

 

Best regards,

K


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
0 Kudos
Message 6 of 15
(6,957 Views)

Thank you ,klemen.

I think i choose the wrong version of the dll file.

i chose the release version.

I change it to the debug version and it works!

Thank you.

But I still don't know why the release version don't work.

0 Kudos
Message 7 of 15
(6,951 Views)

Hello,

 

the release build also works here.

 

Best regards,

K


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
0 Kudos
Message 8 of 15
(6,939 Views)

Thank you ,klemen.

I have tested it and it works.

But i have another question.

for example I draw an circle or points on an image . How can i return the image to LabVIEW and display it?

0 Kudos
Message 9 of 15
(6,930 Views)

Hello,

 

have you seen the link in my signature?

 

There you will find some examples on how to pass the image from OpenCV to Labview.

 

Best regards,

K


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
0 Kudos
Message 10 of 15
(6,927 Views)