Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Using OpenCV library in LabVIEW

NI recently released a set of VIs to easily integrate LabVIEW and Vision Development Module with OpenCV. You can download them at this link:

http://sine.ni.com/nips/cds/view/p/lang/en/nid/213723

They contain examples to easily get started.

0 Kudos
Message 41 of 49
(4,430 Views)

Hi everyone, have anybody tried to use the examples from the above link? I am going step by step through the manual, however, when I launch example programs the following error occurs:  The procedure entry point could not be located ?default_num_threads@task_scheduler_init@tbb@@SAHXZ in library C:\Windows\System32\NIVisOCV\opencv_imgproc300.dll.

 

I have no idea how to solve this problem.

0 Kudos
Message 42 of 49
(4,083 Views)

Philippe_RSA wrote:

2) I then had to make use of a tiny app made by Reyn Vlietstra such that the .mat can be used as a pointer to data (there must be a more direct way in LabView.... anyone?) this is called SCM.LabView.Utils.dll (attached).


There is! According to the official documentation for Emgu CV (Working with images -> Accessing the pixels from Mat) there are three ways to obtain pixels data from Mat object. Sadly methods 1 and 2 don't work in LabVIEW - I can't find mat.ToImage in Invoke Node parameters and can't construct a Matrix object to copy into (still no support for Generic types?). But the last method with pinned memory does work!

 

//load your 3 channel bgr image here
Mat m1 = ...; 

//3 channel bgr image data, if it is single channel, the size should be m1.Width * m1.Height
byte[] data = new byte[m1.Width * m1.Height * 3]; 

GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
using (Mat m2 = new Mat(m1.Size, DepthType.Cv8U, 3, handle.AddrOfPinnedObject(), m1.Width * 3))
    CvInvoke.BitwiseNot(m1, m2);
handle.Free();

I translated this code into LV. Here's a simple example, which shows how to load a RGB image from the file, apply some bilateral filtering (just for fun) and read back the image from Mat object into common IMAQ image.

 

Emgu_Load_File_and_Read_Back_LV2011.png

The BD is kinda lengthy but you may wrap it into a SubVI if you want. I should note also that bitwise NOT is required here to restore colors back to normal.

Tested this with the recent version of Emgu - libemgucv-windesktop-3.3.0.2824.exe.

Message 43 of 49
(3,447 Views)

I have just realized that I did a little mistake when connecting rows' and columns' wires to Reshape Array and double For Loop (I was working with a square image). To get it working with any width / height you need to connect the wires like this:

2018-01-02_21-49-35.jpg

Sorry for that. Cat Embarassed

0 Kudos
Message 44 of 49
(3,442 Views)

Are you facing issues in 32bit or 64bit?

Could you please check if you have NIVisOCVTBB folder under System32 or SysWOW64 folders?

Thanks,

Antony 

0 Kudos
Message 45 of 49
(3,416 Views)

@invancea wrote:

Are you facing issues in 32bit or 64bit?

Could you please check if you have NIVisOCVTBB folder under System32 or SysWOW64 folders?

Thanks,

Antony 


If your message was meant for me, then no - I have not come across any issues when playing with Emgu CV or OpenCV in LabVIEW. I didn't try in 32-bit LabVIEW though, x64 only.

In SysWOW64 I don't see such folder, but in System32 I see NIVisOCVTBB symlink, which redirects to C:\Program Files (x86)\National Instruments\NIVision OpenCV Utilities\tbb\x64\bin. Another two there - NIVisOCV (C:\Program Files (x86)\National Instruments\NIVision OpenCV Utilities\opencv\x64\vc110\bin) and NIVisOCVSample (C:\Program Files (x86)\National Instruments\NIVision OpenCV Utilities\nivisionextlib\samples\x64\vc110\bin). Yes, I have NIVision OpenCV Utilities installed. But as I know Emgu doesn't need this or any additional packages. It works "out of box".

0 Kudos
Message 46 of 49
(3,409 Views)

Thanks fot ur nice work. Yet, still i have a question: the version of opencv& EMGU have to be the same?

0 Kudos
Message 47 of 49
(2,565 Views)

the key point now is to convert a 2D int array into a mat, which is the image format in emgucv can be processed in emgucv. I got one idea, that is using the method CvArrToMat in emgucv,see picture 

WeiHu_0-1590043498015.png,

 

but the input arr is a intptr, which can not be wired with a 2D int array. Anyone can give some advice?

0 Kudos
Message 48 of 49
(2,460 Views)

Hi, the  method ByteListToArray is from EMGUCV? Which constructor?

0 Kudos
Message 49 of 49
(2,457 Views)