LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW & MVTec Halcon

Solved!
Go to solution

Hi, everyone!

I'm trying to connect MVTec Halcon 11.0.1 software with LabVIEW 2011 and got one annoying bug. I have created very simple DLL in Visual Studio 2005 (C++) and then inserted it in LV through Call Library Function Node.When I push Run button everything goes ok. But when I try to close current VI or whole LabVIEW, the program just freezes/hangs up and stops responding to any activity. Here are screenshots of Start menu and Tools window:

Tools.jpg

Start.jpg

This is VC++ code:

 

#include "stdafx.h"
#include "TestDLL.h"
#include "HalconCpp.h"

using namespace HalconCpp;

__declspec(dllexport) void __stdcall ReadImg()
{
    HImage neu;
	ReadImage(&neu,"C:/444.png");
}

 I've tested this DLL on Delphi and everything went allright. Maybe the problem is in memory management as I know LabVIEW does inner memory operations liberating users from this task. Halcon also has COM and .NET interfaces and they both work well without any bugs but they are slightly slow. So I'm interested in DLL approach. Can anybody help me?

 

0 Kudos
Message 1 of 63
(15,077 Views)
What you describe is a classic symptom of memory management problems. Is there example code available from the vendor demonstrating how to use their library?

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 2 of 63
(15,048 Views)

 

There's nothing extraordinary. An user should put #include "HalconCpp.h" and using namespace HalconCpp; in order to use VC++ library and that's all. No object disposing is needed (as described in manual). This is done automatically. I post one of examples from Halcon's help:

#include "HalconCpp.h"
int main()
{
using namespace HalconCpp;
HImage Mandrill("monkey"); // read image from file "monkey"
Hlong width,height;
Mandrill.GetImageSize(&width,&height);
HWindow w(0,0,width,height); // window with size equal to image
Mandrill.DispImage(w); // display image in window
w.Click(); // wait for mouse click
w.ClearWindow();
HRegion Bright = Mandrill >= 128; // select all bright pixels
HRegion Conn = Bright.Connection(); // get connected components
// select regions with a size of at least 500 pixels
HRegion Large = Conn.SelectShape("area","and",500,90000);
// select the eyes out of the instance variable Large by using
// the anisometry as region feature:
HRegion Eyes = Large.SelectShape("anisometry","and",1,1.7);
Eyes.DispRegion(w); // display result image in window
w.Click(); // wait for mouse click
}

 This program extracts fragment from whole image. I limited it just to reading an image and it caused memory problems described above. There are more operators for generating new images for instance gen_image1_extern - Create an image from a pointer on the pixels with storage management. This operator also goes to trouble as read_image. I tried changing calling conventions, added image disposing, put pointer to my own clearing procedure and even used LabVIEW memory manager's function ClearMem. The bug is still the same. If there's memory conflict, one of NI's developers could say why it happens.

0 Kudos
Message 3 of 63
(15,033 Views)
Solution
Accepted by dadreamer

I've got solution to the problem. Maybe, someone will consider it useful.

 

One of MVTec's specialists wrote me the following:

 


When using libraries on Windows systems it is not allowed to unload a Dynamic Link Library (DLL)
while unloading another DLL. More explicit, when you load a DLL which then loads another DLL then
you need to make sure that the second DLL is unloaded or at least inactive when unloading the (main)
DLL.

Since Windows may have different dependencies to these libraries it can happen that the process will
run into a dead lock. This is why the second DLL needs to be inactive.

In this case LabVIEW will load the custom library which then loads HALCON. When unloading the custom
library it will also unload HALCON which causes the process to be stuck.

To avoid this situation you need to close running threads in the HALCON library by calling the
following operator BEFORE the custom DLL will be unloaded:
set_system('thread_pool', 'false')

Another option would be to set the global library variable HShutdownThreadPool = FALSE.

Please see the HALCON Programmer's Guide chapter "3.2 Terminate HALCON Library" for more
information.

 




Message 4 of 63
(14,948 Views)

now the latest halcon vesion is v11

careful consideration,do it with your heart
0 Kudos
Message 5 of 63
(14,222 Views)

if you don't use c to package it,how can you use halcon in labview?

careful consideration,do it with your heart
0 Kudos
Message 6 of 63
(14,132 Views)

if you don't use c to package it,how can you use halcon in labview?

careful consideration,do it with your heart
0 Kudos
Message 7 of 63
(14,132 Views)

@ydzheu wrote:

if you don't use c to package it,how can you use halcon in labview?


 

Unless Halcon provides a ready made LabVIEW Library to their DLL, none really.

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 63
(14,121 Views)

 ydzheu

Halcon also has .NET and ActiveX interfaces so you could easily use them in LabVIEW. Take a look at this thread.

Message 9 of 63
(14,116 Views)

anybody please help me and send the Lab VIEW code, DLL for capturing and comparing images in Lab VIEW using Halcon 11

0 Kudos
Message 10 of 63
(13,071 Views)