12-28-2012 01:32 AM
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:
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?
Solved! Go to Solution.
12-28-2012 03:03 PM
12-28-2012 11:22 PM
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.
01-16-2013 11:28 AM
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.
04-19-2014 10:32 AM
now the latest halcon vesion is v11
05-15-2014 08:51 AM
if you don't use c to package it,how can you use halcon in labview?
05-15-2014 08:51 AM
if you don't use c to package it,how can you use halcon in labview?
05-15-2014 01:19 PM
05-15-2014 01:27 PM
ydzheu
Halcon also has .NET and ActiveX interfaces so you could easily use them in LabVIEW. Take a look at this thread.
05-31-2016 07:47 AM
anybody please help me and send the Lab VIEW code, DLL for capturing and comparing images in Lab VIEW using Halcon 11