Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

set template options with vision development module

hi,

i have a created a Geometric Template in my C#-Application.

Now i want to give this Template the necessary  options

The current problem is that i get no error message when i save the template with the vision infos, but when i use it to search a picture, the template isn't found.

 

this is my method (i know it's a bit much code, but i don't know what you need):

 


CWIMAQLearnGeometricPatternOptions TemplateOptions = new CWIMAQLearnGeometricPatternOptions();
            string FileName = Application.StartupPath + @"..\..\..\..\Templates\" + TemplateName.Text + ".png";

            if (comboExtractionMode.Text == "Normal" )
                TemplateOptions.CurveOptions.ExtractionMode = CWIMAQExtractionModes.cwimaqExtractionModeNormal;
            if (comboExtractionMode.Text == "Uniform Regions" )
                TemplateOptions.CurveOptions.ExtractionMode = CWIMAQExtractionModes.cwimaqExtractionModeUniformRegions;
            if (comboExtractionMode.Text == "" )
                MessageBox.Show("Choose an ExtractionMode!" ) ;
            TemplateOptions.CurveOptions.Threshold = (int)System.Convert.ToSingle(EdgeThreshold.Value);
            if (comboEdgeFilterSize.Text == "Fine" )
                TemplateOptions.CurveOptions.FilterSize = CWIMAQEdgeFilterSizes.cwimaqEdgeFilterFine;
            if (comboEdgeFilterSize.Text == "Normal" )
                TemplateOptions.CurveOptions.FilterSize = CWIMAQEdgeFilterSizes.cwimaqEdgeFilterNormal;
            if (comboEdgeFilterSize.Text == "" )
                  MessageBox.Show("Choose an EdgeFilterSize!" );
            TemplateOptions.CurveOptions.MinLength = (int)System.Convert.ToSingle(MinimumLenght.Value);
            TemplateOptions.CurveOptions.RowStepSize = (int)System.Convert.ToSingle(RowSearchStepSize.Value);
            TemplateOptions.CurveOptions.ColumnStepSize = (int)System.Convert.ToSingle(ColumnSearchStepSize.Value);

             axCWIMAQVision1.LearnGeometricPattern(Create_Viewer_Template.Image, TemplateOptions, Create_Viewer_Template.Image);
             axCWIMAQVision1.WriteImageAndVisionInfo(Create_Viewer_Template.Image, Application.StartupPath + @"..\..\..\..\Templates\" + TemplateName.Text + ".png", Create_Viewer_Template.Palette);
}

 


i hope somebody can help me

 

 

 

 

Message Edited by kumi on 12-18-2008 09:18 AM
0 Kudos
Message 1 of 11
(5,614 Views)

Im creating an application using c# also, maybe I can help you. Sometimes its a pain to use the VB.net examples as a reference coz some function parameters in VB.net cant be of the same signature in C#...especially when C# forces you to use out and ref keywords. VisualStudios intellisence is of great help for me...

 

Anyways, Whats the error message your getting?

 

Did you use the ReadImageAndVisionInfo function before using the template?

 

Riscoh

0 Kudos
Message 2 of 11
(5,605 Views)

hallo,

first happy new year and sorry that i'm a bit late to respond, but i wasn't here over the holidays.

So to the error-message i get:

 

"invalid geometric matching template image."

 

But i don't understand why.

In my oppinion i have set all the right template options....

And yes: i used ReadImageAndVisionInfo to load the Template File into the program.

 

kumi

0 Kudos
Message 3 of 11
(5,526 Views)

I have encountered the same error message with color pattern matching and it turns out the images are not of the same type.

LearnGeometricPattern and MatchGeometricPattern uses U8 images as per imaq help file might wanna double check.

 

Riscoh

0 Kudos
Message 4 of 11
(5,518 Views)

thanks for the advice.

i tried it with this function:

 

Create_Viewer_Template.Image.Type = CWIMAQImageTypes.cwimaqImageTypeU8;

 

but i don't know where to use it.

i tried it in the method

 - when i save the template

 - when i load the picture from which the template is made

 - when i extract the template in another viewer

 

where have you put it?

0 Kudos
Message 5 of 11
(5,453 Views)

MatchGeometricPattern Method

You also have to change the image type of the image you are tying to inspect not just the template

 

SearchImage.Type = CWIMAQImageTypes.cwimaqImageTypeU8

CWIMAQVision.MatchGeometricPattern(SearchImage, Template, MatchGeometricOptions, GeometricPatternMatchReport ,  Regions)

 

 

If the image you are trying to inspect is already loaded onto the viewer you can change the type like this

viewer.Image.Type =  CWIMAQImageTypes.cwimaqImageTypeU8 before calling the MatchGeometricPattern function

 

It would be better to post your code where you have the MatchGeometricPattern function so I could try and figure out whats going on with your code....

0 Kudos
Message 6 of 11
(5,446 Views)

i´ve tried your advice but it didn't worked Smiley Sad

 

here is my code (i put the whole method here, don't know what is really important for you):

 

---------------------------------------------------------------

private void MatchTemplate_Click(object sender, EventArgs e)
        {
            Match_Viewer_Picture.Regions.RemoveAll();
            CWIMAQMatchGeometricPatternOptions MatchOptions = new CWIMAQMatchGeometricPatternOptions();
            CWIMAQGeometricPatternMatchReport MatchReport = new CWIMAQGeometricPatternMatchReport();
            CWIMAQRegions Regions = new CWIMAQRegions();
           
            MatchOptions.CurveOptions.ExtractionMode = CWIMAQExtractionModes.cwimaqExtractionModeUniformRegions;
            MatchOptions.CurveOptions.FilterSize = CWIMAQEdgeFilterSizes.cwimaqEdgeFilterNormal;           
            MatchOptions.MinimumMatchScore = (float)System.Convert.ToSingle(MinMatchScore.Value);
            MatchOptions.NumMatchesRequested = (int)System.Convert.ToSingle(MinNrMatches.Value);
           
            if( Occlusion.Checked)
                MatchOptions.MatchMode = CWIMAQGeometricMatchModes.cwimaqGeometricMatchOcclusionInvariant;
            if (Rotation.Checked)
            {
                MatchOptions.MatchMode = CWIMAQGeometricMatchModes.cwimaqGeometricMatchRotationInvariant;
                MatchOptions.RotationAngleRanges.Add(1);
                MatchOptions.RotationAngleRanges.Initialize((int)System.Convert.ToSingle(RotatedMin.Value), (int)System.Convert.ToSingle(RotatedMax.Value));
            }
            if (Scale.Checked)
            {
                MatchOptions.MatchMode = CWIMAQGeometricMatchModes.cwimaqGeometricMatchScaleInvariant;
                MatchOptions.ScaleRange.Min = (int)System.Convert.ToSingle(ScaledMin.Value);
                MatchOptions.ScaleRange.Max = (int)System.Convert.ToSingle(ScaledMax.Value);
            }

            Match_Viewer_Template.Image.Type = CWIMAQImageTypes.cwimaqImageTypeU8;
            Match_Viewer_Picture.Image.Type = CWIMAQImageTypes.cwimaqImageTypeU8;

            try
            {
                axCWIMAQVision1.MatchGeometricPattern(Match_Viewer_Picture.Image, Match_Viewer_Template.Image, MatchOptions, MatchReport, Regions);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            Match_Viewer_Picture.Image.Overlays.Item(1).Clear();

            for (int i = 0; i < MatchReport.Count; i++)
                DrawGeometricPatternMatch(Match_Viewer_Picture.Image.Overlays.Item(1), MatchReport.Item(i+1), System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LawnGreen));

            MatchesFound.Text = (String)System.Convert.ToString(MatchReport.Count);
        }

-------------------------------------------------

kumi

0 Kudos
Message 7 of 11
(5,433 Views)

Could you also post the images(template and the image to be inspected) I'll try and create an application to see if we get the same result...

 

Match_Viewer_Picture.Regions.RemoveAll(); 

 

The only potential problem I see on the code is there are no regions although you defined a CWIMAQRegions object but it doesnt contain any  CWIMAQRegion object. CWIMAQRegions object must contain exactly one rectangle or one rotated rectangle region as per help file...

 

But I doubt if you would get this  "invalid geometric matching template image."  error message if there arre no regions defined.

 

Riscoh

0 Kudos
Message 8 of 11
(5,419 Views)
hello, i attached the pictures & the class with my methods
Download All
0 Kudos
Message 9 of 11
(5,406 Views)

Ive tested the images on Vision assitant and the template didnt work I created a new template using the default values and it worked right away

 

You get this "invalid geometric matching template image." error message when you try to inspect an image using a template that does not contain enough features for geometric matching... 

 

try use the template Ive used and see what happens... Also I would suggest to just use pattern matching for this application coz I think the results are more repeatable...

 

and forget about the image type the viewer defaults to U8 images...

 

Riscoh

0 Kudos
Message 10 of 11
(5,393 Views)