Measure

cancel
Showing results for 
Search instead for 
Did you mean: 

Defining Centroid with Vision AI in VB

I'm usnig NI Vision Automated Inspection.  Any centroid related help that I've found references the centoid function for the development software.  
Can anyone point me in the right direction for using NI Vision AI to write VB code to acccomplish this? 


I've already gotten the acquisition up and running. 

Thanks, 
Bryan 

0 Kudos
Message 1 of 7
(6,824 Views)

Hi baxsy,

 

Could you please clarify what you mean by using NI Vision AI to write VB code?  Are you trying to do something in Visual Basic or are you just trying to figure out how to find a centroid in Vision Builder?

0 Kudos
Message 2 of 7
(6,816 Views)

It sounds like you're using Vision Builder AI. If this is the case, the Detect Objects step returns the center of mass for all objects detected. It is added to the results for the step, which you could access in subsequent steps to created regions of interest, set coordinate systems, etc.

Hope this helps,

Brad

0 Kudos
Message 3 of 7
(6,814 Views)

Gentlemen, 
Thanks for the replies.

 

I have Vision Builder AI installed, but I'm in Visual Studio coding in VB.  Version 2008 I believe.

 

Brad, 

I'm not familiar with the function you're calling out.  Is this in Vision? I'm working with VB

 

I'm operating at a very base level of understanding here so please bare with me.  

Since my last post, I've managed to add the IMAQ functions in to the toolbox of Visual Studio.  I've found the "IMAQ hardware example" and have confirmed that my frame grabber/camera is functioning.  

 

It took me awhile to figure out that the function from toolbox had to be dragged onto the design form before associated functions would be available to call in the code.

 

The general gist of what I'm trying to accomplish is this: 

I found a reference to " CWIMAQVision1.Centroid2()" in a manual and upon using it, VS seems to acknowledge that function (manuals weren't clear as to if this function was unique only to the developer version of vision). 

I'm currently trying to figure out the syntax to grab a frame of a continuously running acquisition, save it to a variable that I dim as new cwimaq.image, then have the centroid2 function operate on said image, dump the coordinates in a label on the form. 

 

I'm getting stuck on declaring the variable as new cwimaq.image as detailed in the manual.  cwimaq.image does not show up in the drop down menu as I type which would lead me to believe that I somehow did not make the appropriate Visual Studio references?  I've also tried repoplulating the toolbox with Vision functions but have not found anything that would enable cwimaq.image. Ideas?

 

Also, the centroid function is dimmed as a point- is this just a 1x2 array? how will it display? 

 

I've found manuals referencing the process, but not without explicit lines of code detailing syntax- that seems to be where I'm falling down .

Thanks

-Bryan

 

0 Kudos
Message 4 of 7
(6,809 Views)

Hi Bryan,

 

The CWIMAQVision.Centroid2 function does seem to require the Vision Development Module. I'm including a blurb from the NI Vision for Visual Basic Reference Help (cwimaq.chm) that enumerates the arguments for this function. In Windows 7, this help file can be found at C:\Program Files\National Instruments\Vision\Documentation if you have Vision Development Module installed.

 

centroid2.png

0 Kudos
Message 5 of 7
(6,787 Views)

Drew, 

I've spoken to two application engineers who could not find anything comparable to what you've included in your post. 

 

Do you have analagous documentation for Vision Builder AI in VB?  I would not mind hobbling together my own centroid function.  The problem is that the manuals i've found are ambiguous as to which version of Vision it applies to and it does not go into the detail regarding syntax and function of the document you provided. 

 

Thanks, 
Bryan 

0 Kudos
Message 6 of 7
(6,783 Views)

It sounds like there is some confusion about Vision Builder AI and the Vision Development Module (where Centroid2 can be used). Vision Builder AI is a configurable environment for designing Vision applications. It has a step called Detect Objects that allows you to specify threshold parameters and particle filtering data to remove unwanted objects and it returns data for all the resulting objects found (including the center of mass). You can control a Vision Builder AI engine that is running on your local machine or on a remote target using the Vision Builder AI API. We recently released C support for this API in Vision Builder AI 2011, which includes a dot net example for C# and VB. This would allow you to retrieve the results for the detect object step, but the algorithm would run in the Vision Builder AI engine. Using this method would tyopically mean that all your image processing/acquisition happen within Vision Builder AI, and you just use Visual Basic to control when the Vision Builder AI engine acquires an image and processes it, but you couldn't control which algorithms it runs since this can only be defined from within the Vision Builder AI environment when you create an inspection.

 

The Vision Development Module is a set of vision algorithms that are meant to be called from programming languages like LabVIEW, CVI, VB, MSVC, etc. It sounds like you are using this library in Visual Basic, and if this is the case, you don't need Vision Builder AI to do the detect object step since this will go through many other layers of SW to accomplish what you want, and calling the Vision Development algorithms directly will be much more direct. Is there a reason you want to use Vision Builder AI instead of the Vision Development Module algorithms included in the ActiveX control it sounds like you are using? To get help on the ActiveX Vision Analysis library, you can go to Start>> Programs>>National Instruments>>Vision>>Documentation>>NI Vision and open the cwimaq.chm.

 

If all you're doing is trying to find the center of mass, using the Vision Development Module is much more straight forward than trying to create a Vision Builder AI inspection, which you control from Visual Basic and get the resuls of the inspection to figure out the center of mass from one of the steps in the inspections.

 

Hope this helps,

Brad

0 Kudos
Message 7 of 7
(6,779 Views)