Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

axCWIMAQViewer1 overlays

Solved!
Go to solution

Hi,

 

I am working with the axCWIMAQViewer1 where the control image gets updated whenever a new frame from a camera arrives (every 100ms or so). After the control is updated i do a match pattern, then call the DrawPatternMatch and DrawText to draw the pattern found and some additional info. Basically what i am trying to do is a real time pattern matching.

 

Everything works well but the only problem is that everytime a new frame arrives the control gets redrawn and you see a flicker in of the info between frames. I changed the Immedaiteupdates property to false and it seemed to help some, but the flickering is still there.

 

Thanks in advance

 

 

 

 

0 Kudos
Message 1 of 6
(3,927 Views)

Hi MrRojas,

 

Do you see a longer flicker when you set the ImmediateUpdates property to true?  It appears as though this would be the better route because it updates the viewer as soon as possible as opposed to having the container set the update rate.  Also, setting this property to true automatically calls the Refresh method which redraws the CWIMAQViewer immediately.

 

Lynn

National Instruments
Senior Systems Engineer
0 Kudos
Message 2 of 6
(3,908 Views)

Hi Sarci1,

 

yes, and the flicker is shorter when the property is set to true. When i say longer i mean that the added text remains a shorter time on the screen between frames. I think what is happening (since i can only assume) is that the image is being redrawn on the control, the control is being refreshed, and then the text is being drawn on top of it. What i am actually looking for is to actually refresh the control after the text has been added.

 

I am adding some changes to the code and it is getting closer to what i actually want but the flicker is still there; I will post the solution if find one.

 

Thanks for your reply.

 

MrRojas

0 Kudos
Message 3 of 6
(3,903 Views)

Hi MrRojas,

 

Would you be willing to post your code?  I would like to try and replicate it here on my end.

 

Lynn

National Instruments
Senior Systems Engineer
0 Kudos
Message 4 of 6
(3,890 Views)

Hi Lynn,

 

I finally have it working; here is the code in case somebody needs it. I posted part of the code earlier on a different post, but here is the updated code.

I am getting images from a camera up to 30fps and this should work with basically any camera.

 

I could not make it work (for some reason) copying and pasting to and from the clipboard, which i think would work a lot faster; if you know of a way to do this please let me know

 

Thanks for your time.

 

MrRojas

 

 

void Form1_performPatternMatch()
{
//lock (this)
     {
     try
     {
     if (this.axCWIMAQViewer2.Image == null) return;
          matchingPattern = true;

          // Start pattern matching
          CWIMAQMatchPatternOptions MatchOptions = new CWIMAQMatchPatternOptions();

                    CWIMAQRectangle SearchRectangle = new CWIMAQRectangle();

                    // Get match input parameters
                    MatchOptions.MinimumMatchScore = 400;
                    MatchOptions.NumMatchesRequested = 10;
                    MatchOptions.MinimumContrast = 10;
                    MatchOptions.SubPixelAccuracy = false;

                    this.axCWMachineVision1.GetSelectedRectangleFromViewer(this.axCWIMAQViewer1.GetCWIMAQViewer(), SearchRectangle, false, null);
                    
                    
                    //First, do the rotation invariant
                    MatchOptions.MatchMode = CWIMAQMatchModes.cwimaqMatchRotationInvariant;

                    // Get the results
                    this.axCWIMAQVision1.MatchPattern2(this.axCWIMAQViewer1.Image, this.axCWIMAQViewer2.Image,
                                                    MatchOptions, MatchReport_RotationInvariant, SearchRectangle);

                    //Clear previous results
                    this.axCWIMAQViewer1.Image.Overlays.Item(1).Clear();




                    //Display results for the rotation invariant
                    for (int i = 0; i < this.MatchReport_RotationInvariant.Count; i++)
                    {
                        CWIMAQPatternMatchReportItem item = MatchReport_RotationInvariant.Item(i + 1);
                        CWIMAQPoint pt = item.Position;

                        System.Drawing.Color color = System.Drawing.Color.DarkRed;
                        if (item.Score > 100) color = System.Drawing.Color.DarkKhaki;
                        if (item.Score > 400) color = System.Drawing.Color.LightYellow;
                        if (item.Score > 700) color = System.Drawing.Color.DarkGreen;

                        this.axCWMachineVision1.DrawPatternMatch(this.axCWIMAQViewer1.Image.Overlays.Item(1), item, System.Drawing.ColorTranslator.ToOle(color));

                        overlayTextOnImage(item.Score.ToString() + ", " + item.Angle.ToString() + " deg.", item.Position, color);
                        //this.axCWIMAQViewer1.Image.Overlays.Item(1).
                    }

                    //this.lblStatus.Text = "Matches found: " + (MatchReport_ShiftInvariant.Count + MatchReport_RotationInvariant.Count).ToString();

                    this.computationsPerSecond++; //keep a record of the calculated computations
                }
                catch (Exception)
                {
                    //throw;
                }
            }

            matchingPattern = false;
        }




void Form1_imageChanged(Image image)
{
readingImage = true;

try
{
//Clipboard.SetImage(image);
//image.Dispose();

//bool copyOk = false;
//this.axCWIMAQVision1.ReadImageFromClipboard(this.axCWIMAQViewer1.Image, ref copyOk, axCWIMAQViewer1.Palette);

image.Save("C:\\temp\\temp.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
image.Dispose();
this.axCWIMAQVision1.ReadImage(this.axCWIMAQViewer1.Image, "C:\\temp\\temp.jpg", axCWIMAQViewer1.Palette);

this.Form1_performPatternMatch();


}
catch (Exception)
{

}
finally
{
readingImage = false;
}

}
void videoSource_NewFrame(object sender, Video.NewFrameEventArgs eventArgs)
{
if (readingImage == true) return;

try
{

//lock (this)
{
Image b;
b = (Image)eventArgs.Frame.Clone();
this.frameSize = eventArgs.Frame.Size;

Invoke(new imageHandler(this.Form1_imageChanged), b);
}
}
catch (Exception)
{
//throw;
}
}

 

 

0 Kudos
Message 5 of 6
(3,882 Views)
Solution
Accepted by topic author MrRojas

Hey Mr. Rojas,

 

Thank you for the code. I will run through it and also pass it on to Lynn. I saw that you said you fixed your issue. Is this a satisfactory work around, or do you have anymore questions regarding this implementation?

Happy Holidays!

 

Ricky V

National Instruments
Applications Engineer
0 Kudos
Message 6 of 6
(3,872 Views)