This topic contains the following sections.
The Image Sharpness tool calculates a measure of the relative sharpness of an input image. This topic shows an example Visual Studio.NET application that uses an Image Sharpness tool to aid the user in determining the best focus setting from a live display.
See any of the following topics for details on acquiring images based on the type of camera you are using:
- Acquiring Images with a CCD Camera and Frame Grabber
- Acquiring Images with a CDC Camera and Frame Grabber
- Acquiring Images with a Line Scan Camera
In addition, see the topic Displaying An Image for more information on using a Cognex Display control.
The following figure shows the Windows form for a Visual Studio.NET application that uses an Image Sharpness tool:

The form contains the following elements:
- A CogDisplay control, CogDisplay1, to display a live image
- button1 to start a live image display in CogDisplay1
- button2 to stop a live image display
- button2 to acquire an image from the live display and pass the image to an Image Sharpness tool
- A progress bar, progressBar1, to graphically display the level of image sharpness of the last image
The Visual Studio.NET application uses references to the assemblies Cognex.VisionPro, Cognex.VisionPro.Core, Cognex.VisionPro.Display.Controls, and Cognex.VisionPro.ImageProcessing.
The following C# statements show how the application functions:
using Cognex.VisionPro;
using Cognex.VisionPro.ImageProcessing;
private int tNum;
private CogFrameGrabbers myFrameGrabbers;
private ICogFrameGrabber myFrameGrabber;
private ICogAcqFifo myAcqFifo;
private CogImageSharpnessTool myImageSharp;
private Double sharpScore;
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 InitializeImageSharpness()
{
myImageSharp = new CogImageSharpnessTool();
myImageSharp.RunParams.Mode = CogImageSharpnessModeConstants.AutoCorrelation;
progressBar1.Maximum = 10;
}
private void GetSharp()
{
myImageSharp.Run();
sharpScore = myImageSharp.Score * 1000;
label2.Text = sharpScore.ToString();
if (sharpScore > progressBar1.Maximum)
{
progressBar1.Maximum = (int)sharpScore + 2;
}
progressBar1.Value = (int)sharpScore;
}
private void button1_Click(object sender, System.EventArgs e)
{
cogDisplay1.StartLiveDisplay(myAcqFifo, false);
}
private void button2_Click(object sender, System.EventArgs e)
{
cogDisplay1.StopLiveDisplay();
progressBar1.Value = 1;
}
private void button3_Click(object sender, System.EventArgs e)
{
myImageSharp.InputImage = (CogImage8Grey)myAcqFifo.Acquire(out tNum);
GetSharp();
}