04-02-2009 09:11 AM
I am snapping an image to a main viewer, drawing a rectangle around a fiducial, and extracting that portion of the image to another viewer for further processing. I tested everthing and all was good until I began to build a wizard to walk the operator through the process and do some things automatically. If I access this method from the mainform thread all runs well. If I access it from the wizards background worker thread it fails and gives the error " you supplied the wrong type of object to the function. Pass a CWIMAQRectangle instead."
public int ExtractToGP1()
{
CWIMAQLearnPatternOptions LearnOptions = new CWIMAQLearnPatternOptions();CWIMAQRectangle RoiRectangle = new CWIMAQRectangle();
int Count, Result;
//Extract region correspoding to the pattern selected in the main viewer
Result = axCWMachineVision1.GetSelectedRectangleFromViewer(axCWIMAQViewer1.GetCWIMAQViewer(), RoiRectangle, true, 1); //<--error here
Result = axCWIMAQVision1.Extract2(axCWIMAQViewer1.Image, axCWIMAQViewer5.Image, RoiRectangle, 0, 0);
I tried using:
axCWMachineVision1.Invoke((MethodInvoker)delegate
{ Result = axCWMachineVision1.GetSelectedRectangleFromViewer(axCWIMAQViewer1.GetCWIMAQViewer(), RoiRectangle, true, 1); });
axCWMachineVision1.Invoke((MethodInvoker)delegate
{ Result = axCWIMAQVision1.Extract2(axCWIMAQViewer1.Image, axCWIMAQViewer5.Image, RoiRectangle, 0, 0); });
but this also only works if the method is called from the main thread.
Solved! Go to Solution.
04-02-2009 09:49 AM
Solved this myself. Not really an NI issue.
I moved
CWIMAQLearnPatternOptions LearnOptions = new CWIMAQLearnPatternOptions();CWIMAQRectangle RoiRectangle = new CWIMAQRectangle();
to my vision class instead of having it in the method, which is in the mainform class
then use Vision.RoiRectangle vs RoiRectangle and Vision.LearnOptions vs LearnOptions.