# Incorporating VisionPro Deep Learning Graphics in a Cognex VisionPro Record for Display

As described in the Working With Cognex VisionPro Images in VisionPro Deep Learning topic, Deep Learning graphics must be transformed into Image coordinates, converted into VisionPro graphic objects, and then interpreted in the Root coordinate space. In order to display these graphics, they must be added (along with the input image) to a VisionPro Record, which can be consumed by a VisionPro Display. Lastly, these Records must be combined with Records produced by other VisionPro tools in order to show both VisionPro and Deep Learning graphics on one display.

## Converting Into VisionPro Graphics

The coordinate transformations, conversion from Deep Learning types to VisionPro types, and the setting of the SelectedSpaceName are all handled automatically by the wrapper. The conversions are done through three interfaces (ICreateBlueToolGraphics, ICreateRedToolGraphics, and ICreateGreenToolGraphics), so programmatic users can define their own conversions if they'd like to change the color or style of the default graphics. The rectangle graphic representing a View cannot be overridden in the public API as Deep Learning only supports rectangular ROIs. Because the graphics are drawn using pixel values, the default implementations set the SelectedSpaceName to "#" for Pixel space.

Note:

- DefaultBlueToolGraphicsCreator converts Features and Matches from Blue Markings into equivalent ICogGraphic types.
- DefaultRedToolGraphicsCreator converts Regions from Red Markings into equivalent ICogGraphic types, and also creates the Heatmap image.
- DefaultGreenToolGraphicsCreator converts Tags from Green Markings into equivalent ICogGraphic types.

## Adding Graphics to Records

The wrapper also provides classes that convert Deep Learning Markings directly into a hierarchy of VisionPro records. These classes are constructed with a Deep Learning image and a Deep Learning Marking; during construction, these classes use the corresponding ICreateToolGraphics interface to convert the graphics under the hood. Each graphic is added as the Content of its own Record, and a hierarchy mirroring the Marking hierarchy is created from these Records.

For a Blue tool locating two parts in an image, the Marking hierarchy may look like this:

- BlueMarking
  - BlueView
    - Feature
  - BlueView
    - Feature

When this Marking is used to create a BlueToolRecord, the resulting Record hierarchy may look like this:

- BlueTool Record
  - Content = Input Image
  - SubRecords
    - BlueViewRecord
      - Content = ROI Graphic
      - SubRecords
        - FeatureRecord
          - Content = Feature Graphic
    - BlueViewRecord
      - Content = ROI Graphic
      - SubRecords
        - FeatureRecord
          - Content = Feature Graphic

On a VisionPro Display, this record would display the input image, two ROI graphics, and one feature graphic in each ROI graphic.

Note:

- BlueToolRecord converts a BlueMarking into a hierarchy of BlueViewRecords, FeatureRecords, and ModelRecords.
- RedToolRecord converts a RedMarking into a hierarchy of RedViewRecords, RegionRecords, and exposes the Heatmap image.
- GreenToolRecord converts a GreenMarking into a hierarchy of GreenViewRecords and TagRecords.

## Combining Records

While the wrapper provides classes that convert one Marking into one Record, each tool in a Deep Learning application will produce its own Marking. Likewise, each tool in a VisionPro application will produce its own Record. In order to show the graphics for multiple tools, Deep Learning and/or VisionPro, on the same display, the Records must be combined into one.

The procedure for combining Records is as follows:

1. Create a new VisionPro Record.
2. Assign the image to be displayed to the new Record's Content property.
3. For each Deep Learning ToolRecord produced by the wrapper:
   1. Add the ToolRecord to the new Record's SubRecords collection.
4. For each VisionPro tool:
   1. Get the tool's last run Record through CreateLastRunRecord().
   2. Add the last run record to the new Record's SubRecords collection.
5. Pass the new Record to a VisionPro display.

The resulting Record structure should look like this:

- NewRecord
  - Content = Image to display
  - SubRecords
    - RedToolRecord
      - ...
    - PMAlignTool.LastRun
      - ...

## Summary

The results from a Deep Learning Marking can be displayed on a VisionPro Display by creating a ToolRecord with the Marking and the input image. To display multiple ToolRecords and/or multiple VisionPro tool Records, the Records must be added as SubRecords of a new Record containing the image to be displayed.