# Process Image for Defects with CogBlobTool

Use CogBlobTool to count the number of blobs (imperfections) in the region you previously defined in the InspectImage task block which ran CogImageConvertTool.

In this step, you'll use CogBlobTool to scan for blobs that your quality-control staff warns have been seen in close proximity to the letter O in the word Jell-O on the Jell-O Box label.

Note: Disclaimer: For this tutorial to be completely accurate with regard to this fictional objective --- to inspect a particular region of a label for a defect --- all images in the sample database would ideally be positioned with the "O" in Jell-O on the right-side of the frame. As you can see from the contents of the sample database used in this example, that is not the case.

Accomplish this task by adding and configuring a VisionPro tool block in your application that counts imperfections or "blobs".

1. In the Task window, verify your work flow looks like the following before continuing. If an Select an Image Source and Acquire Your Image, select the Task window and Run All tasks.

2. Add a VisionPro Tool Block from the Toolbox pane to the Task Window by doing the following:

1. Select the Toolbox tab in the upper-right pane of the Cognex Designer interface if it has not already been selected.
2. From the Toolbox pane, select Vision > VisionPro Tool Block.
3. From the Toolbox pane, drag the VisionPro Tool Block to the Task window, placing it below and between the InspectImage and CalculateResult blocks.

4. Select and drag the CalculateResult block to the right, so you can place the VisionProToolBlock between the InspectImage and CalculateResult blocks. Remember that when ordering blocks in a Task window, it is important to adhere to a left-to-right placement, as tasks execute from left to right.

5. Rename the VisionProToolBlock to reflect the processing this block will perform. While this step is optional, it is good practice and creates a well-documented application. Descriptive block labels make the functionality of your vision application apparent to everyone using your Cognex Designer application, in development or deployment mode.

1. Select the VisionProToolBlock and right-click.
2. Click Rename.
3. Type CogBlobInspect. Click any place in the Task window to rename the block.

3. Pass the OutputImage link from the InspectImage block to the CogBlobInspect block by drawing a connector between the two blocks.
   1. Select the connector on the right-side of the InspectImage block.
   2. Drag (draw) a connector to the connector on the left-side of the CogBlobInspect block. The two blocks are now connected.
4. Configure CogBlobInspect to find defects (blobs) in the image area you defined when you configured CogImageConvertTool as part of this vision application.
   1. In the Task window, double-click the CogBlobInspect block. An instance of VisionPro Quick Build opens in the Sequence Editor. The window is labeled Task.CogBlobInspect.
   2. Run Task.CogBlobInspect by clicking the Run button ().
   3. In the Task.CogBlobInspect window, point your mouse to Inputs > Image. A preview of the select region to be inspected (CogImage8Grey) appears.
5. Select, then drag-and-drop the CogBlobTool from the Toolbox pane to the Task.CogBlobInspect window. After you do, the window should appear as in the figure below.
6. Select [Inputs] > Image. Define the cropped image you created in the CogBlobInspect block as input to CogBlobTool by dragging a connection from Image to CogBlobTool1 > InputImage.
7. Because you want to display number of blobs counted Results.GetBlobs()Count on your HMI, select CogBlobTool1 > Results.getBlobs().Count and drag a connection to [Outputs], creating the link Results_GetBlobs_Count within [Outputs]. You have now defined CogBlobTool's blob count to be an output of the task block you renamed CogBlobInspect.
8. Select the Task window and note that, since you defined an output to the Task.CogBlobInspect block, you now have a connector protruding from the right-side of this block in the Task window, as shown in the following figure. Note the link name Results_GetBlobs_Count (defined as an integer) attached to this connector.

9. Run Task.CogBlobInspect by clicking the Run button (). You should see something similar to the following image displayed as LastRun.CobBlobTool1.InputImage.

10. Select the Task window and click Run All. Point your mouse to the connector protruding from the right-hand side of the CogBlobInspect block. Note the value of the blobs counter, Results_GetBlobs_Count.

In the example above, the value of Results_GetBlobs_Count. is 61. The value of your Results_GetBlobs_Count may vary from this example.

In this step, you configured CogBlobTool to process the image you cropped with CogImageConvertTool and associated the number of blobs counted to the link Results_GetBlobs_Count.

Next, you'll edit the predefined script that comes with a predefined Single Camera project type, to tally the cumulative number of blobs (defects) your vision application finds after you run it multiple times.