Displaying An ImageCognex VisionPro

Use the Cognex Display control to display the images you acquire from a camera, an image database file, or a synthetic image your application might generate.

Adding a Cognex Display Control to a Windows Form

To use a Cognex Display control, perform the following steps:

  1. Select Project->Add Reference in your Visual Studio.NET application and add a reference to the assemblies Cognex.VisionPro and Cognex.VisionPro.Display.Controls.
  2. Open the Toolbox, if necessary, by selecting View->Toolbox.
  3. Select the VisionPro Tool Edit Controls tab of the Toolbox.
  4. Select the CogDisplay control and place the control on the Windows form.

The following figure shows the CogDisplay control:

Display Images Code Walkthrough Display Image Cog Display Icon

The following figure shows a Windows form with a CogDisplay control:

Display Images Code Walkthrough Display Image Empty Cog Display Control

Displaying Images

See any of the following topics for details on acquiring images based on the type of camera you are using:

Use the Image property of the CogDisplay control to display an acquired image.

Tool-Level API

If you use the tool-level API to create a CogAcqFifoTool object, display the image as shown in the following C# statements:

private CogAcqFifoTool myAcqTool;

private void InitializeAcqTool()
{
        // Create a tool
        myAcqTool = new CogAcqFifoTool();
        if (myAcqTool == null) 
                throw new CogAcqCannotCreateFifoException("Unable to create Acquisition Fifo");
}

private void button1_Click(object sender, System.EventArgs e)
{
        myAcqTool.Run();
        cogDisplay1.Image = myAcqTool.OutputImage;
}
Operator-Level API

If you use the operator-level API to create an ICogAcqFifo object, display the image as shown in the following C# statements:

private int tNum;
private CogFrameGrabbers myFrameGrabbers;
private ICogFrameGrabber myFrameGrabber;
private ICogAcqFifo myAcqFifo;

private void InitializeFifo()
{
        const string VIDEO_FORMAT = "Sony XC75 640x480";
        myFrameGrabbers = new CogFrameGrabbers();

        myFrameGrabber = myFrameGrabbers[0];

        myAcqFifo = myFrameGrabber.CreateAcqFifo(VIDEO_FORMAT, 
                Cognex.VisionPro.CogAcqFifoPixelFormatConstants.Format8Grey, 0, false);
}

private void button1_Click(object sender, System.EventArgs e)
{
        cogDisplay1.Image = myAcqFifo.Acquire(out tNum);

}