Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem implementing the ActiveX vision.CalculateCoefficient() function in C++.

Does anyone have any suggestions for correctly using the CalculateCoefficient function that is part of the Vision ActiveX control?

My company just upgraded from CW1.0 to Vision 7.1 and several of the functions we used have been obsoleted. Most of the problems I have fixed except for this one. Before, we used to call a function ParticleCoefficients() that would get passed a VARIANT pointer and would return a 2d array filled with particle coefficients. The implementation was as follows:

COleVariant vResults;
m_imaqVision.ParticleCoefficients(imgResult, CCWSafeArray(lTemp, 2), rep1, vResults);
//The safearray is an array of long parameters and rep1 is a fullparticlereport object

The new function works in a similar fashion but now only takes 1 parameter at a time and returns a 1d array of the particle coefficients:

COleVariant vCenterMassXResults;
m_imaqVision.CalculateCoefficients(imgResult, cwimaqCenterofMassX, rep1, vCenterMassXResults);
//I'm pretty sure that all of the parameters are valid except for the variant

I compile the above code and get no errors... However, when running the code I will receive an unhandled exception error in my program (NIVISION.DLL) Access Violation. I have tried multiple different methods of passing the variant and can get all sorts of errors beyond the exception i.e. memory is locked, bad variable type, type mismatch, value is illegal, etc.

Anyone have any success using this function in C++?
0 Kudos
Message 1 of 12
(4,687 Views)
SEQEng -

Actually, the CalculateCoefficients method has bene obsoleted as well. The new equivalent is ParticleMeasurement, and I think the call you would want to make is:

COleVariant vCenterMassXResults;
m_imaqVision.ParticleMeasurement(imgResult, cwimaqMeasurementCenterMassX, vCenterMassXResults);

If you prefer to use the CalculateCoefficients method, you need to call m_imaqVision.Particle() first, and pass the CWIMAQFullParticleReport from that to the CalculateCoefficients method. However, the ParticleMeasurement and ParticleReport methods support more measurement types, can take calibrated measurements, and are in some cases faster than their obsoleted equivalents.

Greg Stoll
IMAQ R & D
National Instruments
Greg Stoll
LabVIEW R&D
0 Kudos
Message 2 of 12
(4,693 Views)
Thanks Greg,

Actually, I just remembered that I am using version 6.0.6(570) of the controls... not 7.1. When I tried to install the 7.1 VB support through the development module software I was kinda unsuccessful. When I would try to add these controls to my 6.0 C++ project it would crash me out of the development environment (I believe when it was adding the classes for the Vision control). Is the 7.1 version of the controls meant purely for .NET? If not, any suggestions on how I might be installing the software incorrectly?

Do you know of a way to utilize the now obsoleted CalculateCoefficient method? I can still see this function inside the vision class that I am using.

If there is a way to use the 7.1 controls, can I call the ParticleFilter method prior to the ParticleMeasurment function to remove particles that aren't of a deemed size?

THANKS!
0 Kudos
Message 3 of 12
(4,686 Views)
Forgot to mention that I am calling the particle method and creating a fullparticle report that is getting passed to the CalculateCoefficient method.
0 Kudos
Message 4 of 12
(4,682 Views)
Here is all of the image processing that takes place before I actually call the CalculateCoefficients function (note I already have an image grabbing through the imaq and viewer control). Maybe I made a mistake in my particle report generation, filtering etc.

Thanks,
Justin
0 Kudos
Message 5 of 12
(4,676 Views)
Found the problem... If no particles are found this function will create the unhandled exception!!!
0 Kudos
Message 6 of 12
(4,673 Views)
Justin,

There needs to be some form of checking performed before running this function, to ensure that at least one particle exists in the image for the calculations to be performed upon.

To address your previous question regarding the use of Vision 7.1, it should install and be usable with Visual C++ 6.0. The controls and functions are not specific to the .NET languages. While ActiveX controls are usable in C++, they are intended for use in Visual Basic. That may have been the source of the trouble. I would suggest uninstalling all of your Vision software and try performing a custom installation of Vision 7.1. Be sure to specify that you want to install support for Visual C++. That should allow the controls to work properly.

Try that and let me know if the use of ActiveX controls still generates errors in your application.

Regards,
Scott R.
Applications Engineer
National Instruments
Scott Romine
Course Development Engineer
National Instruments
0 Kudos
Message 7 of 12
(4,449 Views)
SEQEng -

As Scott R points out below, the Vision Development Module 7.1 has ActiveX controls as well as .NET assemblies, so it should work with Visual C++.

The CalculateCoefficients method is obsolete in 7.1 (not in 6.0.5), but you can still use it even in 7.1.

Yes, you can call ParticleFilter (or ParticleFilter2 in 7.1) to remove particles before taking measurements on them with ParticleMeasurement.

Greg Stoll
IMAQ R & D
National Instruments
Greg Stoll
LabVIEW R&D
0 Kudos
Message 8 of 12
(4,652 Views)
SEQEng -

I was able to reproduce the unhandled exception here, so we are addressing this issue for the future. Right now, the easy workaround is to check the Count property of the FullParticleReport, and not call CalculateCoefficients if the Count is 0. Thanks for reporting this issue!

Greg Stoll
IMAQ R & D
National Instruments
Greg Stoll
LabVIEW R&D
0 Kudos
Message 9 of 12
(4,650 Views)
I've tried installing with straight C support but that will not work either. I believe that the C support is meant purely for installing the necessary development DLL and header files... Not the ActiveX controls.

As you mentioned, the controls are meant for vb development and thus you must install with vb support. If I install with vb support for NIMAQ 3.0 and the core components of NIMAQ 7.1 then evrything works just fine. If I install WITH OR WITHOUT NIMAQ 3.0 vb support AND NIMAQ 7.1 with support for vb my dev environment will crash when trying to add the classes for the CWVision control.

Any thoughts?

Thanks,
Justin
0 Kudos
Message 10 of 12
(4,636 Views)