NI Home > Community > NI Discussion Forums

Machine Vision

Reply
Member
bthiam
Posts: 27
0 Kudos

imaqCentroid centroid

I am having problems programming imaqCentroid. What is PointFloat* centroid? I tried declaring a variable/array but it doesn't work. Isn't this suppose to be the X and Y value of the centroid upon return? What do I compute then in the command for this?
Trusted Enthusiast
BruceAmmons
Posts: 2,438

Re: imaqCentroid centroid

Declare a variable of type PointFloat, and pass the pointer to the function. The function will fill the variable with the results.

Bruce
Bruce Ammons
Ammons Engineering
Member
bthiam
Posts: 27
0 Kudos

Re: imaqCentroid centroid

I tried declaring it as one of the following but it's not working for me. Which one should it be and am I doing it wrong?

1 PointFloat* Centroid;
2 Float* Centroid;
3 Float Centroid;
4 Point Centroid;

Calling it as
1 imaqCentroid(image, Centroid, NULL);
2 imaqCentroid(image, &Centroid, NULL);

My error is "Local Centroid is referenced before being initalized"
Trusted Enthusiast
BruceAmmons
Posts: 2,438
0 Kudos

Re: imaqCentroid centroid

Declare it as a normal variable, not a pointer:

PointFloat Centroid;

Then call it using method #2:

imaqCentroid(image, &Centroid, NULL);

This is a pretty standard way for functions to return values in C, especially when there are multiple values to be returned. You always have to declare a regular variable so that the calling program creates space to store the information. You pass the pointer to that space to the function, which fills the space with information during the function call.

Bruce
Bruce Ammons
Ammons Engineering
Member
bthiam
Posts: 27
0 Kudos

Re: imaqCentroid centroid

Bruce,

Thank you for the prompt reply. If I were to display &centroid.x and &centroid.y, they should be in float type? I created a ui to display them and put both in float type, but it generated a run time error "invalid argument type: found 'pointer to float' expected 'float'.
Member
bthiam
Posts: 27
0 Kudos

Re: imaqCentroid centroid

I've resolved this. Thanks alot!!! I really appreciate it.
Member
sawan310
Posts: 2
0 Kudos

centroid of an image

how can i find the centroid of all image one at a time that is captured by usb cam with an interval of 2 sec.

please help