CogCalibImageCorrector ClassCognex VisionPro
The CogCalibImageCorrector, when trained, will produce a corrected image at run time. This class contains both inputs and outputs for training.
Inheritance Hierarchy

System Object
  System MarshalByRefObject
    Cognex.VisionPro.Implementation CogObjectBase
      Cognex.VisionPro.Implementation CogSerializableObjectBase
        Cognex.VisionPro.Implementation CogSerializableChangedEventBase
          Cognex.VisionPro.CalibFix CogCalibImageCorrector

Namespace: Cognex.VisionPro.CalibFix
Assembly: Cognex.VisionPro.CalibFixPlus (in Cognex.VisionPro.CalibFixPlus.dll) Version: 65.1.0.0
Syntax

[SerializableAttribute]
public class CogCalibImageCorrector : CogSerializableChangedEventBase, 
	IDeserializationCallback, IDisposable

The CogCalibImageCorrector type exposes the following members.

Constructors

  NameDescription
Public methodCogCalibImageCorrector 
Default construct a CogCalibImageCorrector.
Public methodCogCalibImageCorrector(CogCalibImageCorrector)
Copy constructs a CogCalibImageCorrector object. This is a deep copy.
Protected methodCogCalibImageCorrector(SerializationInfo, StreamingContext)
Serialization construct a CogCalibImageCorrector object.
Top
Methods

  NameDescription
Public methodCreateObjRef
Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
(Inherited from MarshalByRefObject.)
Public methodDispose 
Destruct this CogCalibImageCorrector.
Protected methodDispose(Boolean)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodExecute
This method corrects inputImage to remove distortion. The corrected image is provided as the output and the corrected space is added to its coordinate tree. The non-qualified name is determined by the value of CorrectedSpaceName supplied within runParams and the selected space name of the returned image is determined by the SpaceToOutput supplied within runParams.
Protected methodFinalize
Finalize this CogCalibImageCorrector.
(Overrides Object Finalize .)
Protected methodGetAttributes
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetClassName
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetComponentName
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Public methodGetComputedUncorrectedRootFromCorrectedTransform
If Trained is true, this method returns the 2-D, minimum squared error transformation that maps points from the (adjusted) corrected space into uncorrected root space. Otherwise, it returns Nothing.
Protected methodGetConverter
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Public methodGetCorrectedRootFromCorrectedTransform
Returns the 2-D transformation that maps points from corrected space into the root (@) space of the corrected image, if it has been computed. Otherwise, returns Nothing. The transform is computed by calling Train.
Protected methodGetDefaultEvent
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetDefaultProperty
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetEditor
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetEvents 
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetEvents( Attribute )
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetLifetimeService
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
(Inherited from MarshalByRefObject.)
Protected methodGetObjectData
Implements the GetObjectData method of the ISerializable interface.
(Inherited from CogSerializableObjectBase.)
Protected methodGetProperties 
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetProperties( Attribute )
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Protected methodGetPropertyOwner
Implements the corresponding member of the ICustomTypeDescriptor interface. May be overridden in derived classes to provide custom type information.
(Inherited from CogObjectBase.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodGetUncorrectedPixelFromCorrectedPixelTransform
Returns a 2-D correction transform that maps points from pixel space of a corrected image - one created by calling Execute with the current params - into pixel space of the given input image. Returns Nothing if this object is untrained.
Public methodInitializeLifetimeService
Obtains a lifetime service object to control the lifetime policy for this instance.
(Inherited from MarshalByRefObject.)
Protected methodMemberwiseClone 
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodMemberwiseClone(Boolean)
Creates a shallow copy of the current MarshalByRefObject object.
(Inherited from MarshalByRefObject.)
Protected methodOnChanged(Int64)
This method should be called internally whenever the object's state may have changed.
(Inherited from CogSerializableChangedEventBase.)
Protected methodOnChanged(CogChangedEventArgs)
This method may be called internally whenever a derived object's state may have changed and the derived object expresses this change via a derived CogChangedEventArgs class.
(Inherited from CogSerializableChangedEventBase.)
Public methodOnDeserialization
Perform post-deserialization setup for this CogCalibImageCorrector.
Public methodResumeAndRaiseChangedEvent
Re-enables raising of the Changed event after SuspendChangedEvent has been called, and raises the Changed event if the ChangedEventSuspended count is reduced to zero and any changes were made while events were suspended. Must be called once for each call to SuspendChangedEvent.
(Inherited from CogSerializableChangedEventBase.)
Public methodSuspendChangedEvent
Temporarily suspends the raising of the Changed event. May be called more than once, and a corresponding call to ResumeAndRaiseChangedEvent must be made for each call to SuspendChangedEvent.
(Inherited from CogSerializableChangedEventBase.)
Public methodToString
Returns a String that represents the current Object.
(Inherited from Object.)
Public methodTrain
Computes the mapping to corrected space using the current TrainingImage and related parameters. If successful, set the Trained property to True, updates the computed transforms, and makes the object ready to run via the Execute method.
Public methodUntrain
Eliminates the current mapping to corrected space. This method also sets the Trained property to False, sets the computed transforms to Nothing, and renders the object unable to run via the Execute method.
Top
Fields

  NameDescription
Public fieldStatic memberSfCorrectedImageMask
This bit will be set in the EventArgs of a Changed event every time the value returned by CorrectedImageMask may have been changed.
Public fieldStatic memberSfCorrectedOriginSpace
This bit will be set in the EventArgs of a Changed event every time the value returned by CorrectedOriginSpace may have been changed.
Public fieldStatic memberSfCorrectedOriginX
This bit will be set in the EventArgs of a Changed event every time the value returned by CorrectedOriginX may have been changed.
Public fieldStatic memberSfCorrectedOriginY
This bit will be set in the EventArgs of a Changed event every time the value returned by CorrectedOriginY may have been changed.
Public fieldStatic memberSfCorrectedPixelRotation
This bit will be set in the EventArgs of a Changed event every time the value returned by CorrectedPixelRotation may have been changed.
Public fieldStatic memberSfCorrectedPixelScaling
This bit will be set in the EventArgs of a Changed event every time the value returned by CorrectedPixelScaling may have been changed.
Public fieldStatic memberSfCorrectedTrainingImage
This bit will be set in the EventArgs of a Changed event every time the value returned by CorrectedTrainingImage may have been changed.
Public fieldStatic memberSfCorrectedTrainingImageMask
This bit will be set in the EventArgs of a Changed event every time the value returned by CorrectedTrainingImageMask may have been changed.
Public fieldStatic memberSfCorrectedXAxisRotation
This bit will be set in the EventArgs of a Changed event every time the value returned by CorrectedXAxisRotation may have been changed.
Public fieldStatic memberSfCorrectedXAxisRotationSpace
This bit will be set in the EventArgs of a Changed event every time the value returned by CorrectedXAxisRotationSpace may have been changed.
Public fieldStatic memberSfDestinationRectangle
This bit will be set in the EventArgs of a Changed event every time the value returned by DestinationRectangle may have been changed.
Public fieldStatic memberSfGetComputedUncorrectedRootFromCorrectedTransform
This bit will be set in the EventArgs of a Changed event every time the value returned by GetComputedUncorrectedRootFromCorrectedTransform may have been changed.
Public fieldStatic memberSfGetCorrectedRootFromCorrectedTransform
This bit will be set in the EventArgs of a Changed event every time the value returned by GetCorrectedRootFromCorrectedTransform may have been changed.
Public fieldStatic memberSfMaxErrorInPixels
This bit will be set in the EventArgs of a Changed event every time the value returned by MaxErrorInPixels may have been changed.
Protected fieldStatic memberSfNextSf
Public fieldStatic memberSfSwapCorrectedHandedness
This bit will be set in the EventArgs of a Changed event every time the value returned by SwapCorrectedHandedness may have been changed.
Public fieldStatic memberSfTrained
This bit will be set in the EventArgs of a Changed event every time the value returned by Trained may have been changed.
Public fieldStatic memberSfTrainingImage
This bit will be set in the EventArgs of a Changed event every time the value returned by TrainingImage may have been changed.
Public fieldStatic memberSfUncorrectedRootFromRawCorrectedTransform
This bit will be set in the EventArgs of a Changed event every time the value returned by UncorrectedRootFromRawCorrectedTransform may have changed.
Top
Properties

  NameDescription
Public propertyChangedEventSuspended
If nonzero, indicates that the raising of the Changed event has been suspended. This value is incremented when SuspendChangedEvent is called and decremented when ResumeAndRaiseChangedEvent is called.
(Inherited from CogSerializableChangedEventBase.)
Public propertyCorrectedImageMask
Returns the corrected image mask, if it has been computed and contains any "Don't Care" pixels. Otherwise returns Nothing. "Don't Care" pixels (value = 0) in this mask identify unfilled locations locations in the runtime corrected image.
Public propertyCorrectedOriginSpace
Specifies whether the CorrectedOriginX and CorrectedOriginY properties are expressed in uncorrected space, or in raw corrected space.
Public propertyCorrectedOriginX
The desired X position of the corrected space origin, expressed in the coordinate space specified by CorrectedOriginSpace. Corrected space will be adjusted so that its origin appears at this X position when corrected.
Public propertyCorrectedOriginY
The desired Y position of the corrected space origin, expressed in the coordinate space specified by CorrectedOriginSpace. Corrected space will be adjusted so that its origin appears at this Y position when corrected.
Public propertyCorrectedPixelRotation
Specifies the rotation, in radians, of the corrected image. It is the pixel-space angle from the x-axis of the corrected image to the x-axis of raw corrected space. This property allows you to rotate the image during correction.
Public propertyCorrectedPixelScaling
Specifies an additional scaling factor to be applied during correction. For example, a value of 2 means that the corrected image will be approximately twice as high and twice as wide as the input image.
Public propertyCorrectedTrainingImage
Returns the corrected training image, if it has been computed. Otherwise, returns Nothing. This image is produced by correcting the entire training image (ignoring the DestinationRectangle).
Public propertyCorrectedTrainingImageMask
Returns the corrected training image mask, if it has been computed and contains any "Don't Care" pixels. Otherwise, returns Nothing. "Don't Care" pixels (value = 0) in this mask identify unfilled locations in the corrected training image.
Public propertyCorrectedXAxisRotation
The desired x-axis rotation of the corrected space, expressed in the coordinate space specified by CorrectedXAxisRotationSpace. Corrected space will be adjusted so that its x-axis appears at this angle (in radians).
Public propertyCorrectedXAxisRotationSpace
Specifies whether the CorrectedXAxisRotation property is expressed in uncorrected space, or in raw corrected space.
Public propertyDestinationRectangle
Rectangle of the corrected training image that specifies what pixels will be present in the corrected image. If the rectangle is Nothing, all the pixels of the corrected image will be output. It must be in '.', '@', or '#' space.
Public propertyHasChanged (Inherited from CogSerializableChangedEventBase.)
Public propertyMaxErrorInPixels
The maximum error allowed during image correction, measured in pixels of the training image. It limits the error between a mathematically perfect correction and the (much faster) one implemented by this object. Smaller values yield more accurate correction.
Public propertyStateFlags
Returns the complete set of state flags supported on this object. The flags may be indexed by name as shown in the following C# code snippet: if (changedObject.StateFlags["Color"] & eventArgs.StateFlags) { ... }
(Inherited from CogSerializableChangedEventBase.)
Public propertySwapCorrectedHandedness
Specifies the handedness of the corrected space. When SwapCorrectedHandedness is false, the corrected space will have the same handedness as the raw (unadjusted) corrected space. Otherwise, it will have the opposite handedness.
Public propertyTrained
True if all of the computed outputs of this object are meaningful, and were computed using the current object properties. This can only happen if the Train method is called and none of the object properties are changed afterwards.
Public propertyTrainingImage
Get or set the training image.
Public propertyUncorrectedRootFromRawCorrectedTransform
Get or set the transform that maps from RawCorrected to UncorrectedRoot.
Top
Events

  NameDescription
Public eventChanged
This event is raised when one or more parts of the object's state may have changed.
(Inherited from CogSerializableChangedEventBase.)
Top
Remarks

Images:

Uncorrected training image: CogCalibImageCorrector.TrainingImage. It is used as the trainingimage in CogCalibImageCorrector.Train.

Corrected training image: CogCalibImageCorrector.CorrectedTrainingImage. It is produced by correcting the training image after CogCalibImageCorrector is trained.

Uncorrected runtime image: The input image for CogCalibImageCorrector.Execute(ICogImage). The uncorrected runtime image must have the same root (@) space as the uncorrected training image.

Corrected runtime image: The output image of CogCalibImageCorrector.Execute(ICogImage);

Space names:

Root space of an image (@): See coordinate space names in VisionPro User's Guide.

Pixel space of an image (#): See coordinate space names in VisionPro User's Guide.

Uncorrected Root: The root (@) space of the uncorrected training image. Note that the uncorrected runtime images must use the same root space. The only difference allowed between the uncorrected training image's PixelFromRootTransform and the uncorrected runtime image's PixelFromRootTransform, is a whole pixel shift i.e TrainingImage.PixelFromRootTransform * RuntimeImage.PixelFromRootTransform.Invert has only a whole-pixel shift.

UncorrectedPixel: The pixel (#) space of the uncorrected runtime image.

CorrectedPixel: The pixel (#) space of the corrected runtime image. It is affected by CogCalibImageCorrector.CorrectedPixelScaling, CogCalibImageCorrector.CorrectedPixelRotation, and CogCalibImageCorrector.DestinationRectangle. Note that CorrectedPixel space has a linear transform from RawCorrected space.

CorrectedRoot: The root (@) space of the corrected runtime image. The PixelFromRootTransform of the corrected runtime image is identity. Thus, CorrectedRoot space is identical to CorrectedPixel space.

Corrected: A physical space which has a rigid plus handedness transform from RawCorrected space, and the transform is decided by CogCalibImageCorrector.CorrectedOriginSpace, CorrectedOriginX, CorrectedOriginY, CorrectedXAxisRotationSpace, CorrectedXAxisRotation, SwapCorrectedHandedness. Note that the transform between CorrectedRoot space and Corrected space is a linear transform.

Usage examples:

Simple Usage

Examples

// Step 1:  Set the training image and the transform of camera calibration

CogCalibImageCorrector corrector = new CogCalibImageCorrector();
CogCalibImageCorrectorRunParams  runParams = new CogCalibImageCorrectorRunParams();

// The training image does not need to be a calibration image (such as a checkerboard image),  
// and we recommend you use an acquired image from your run time setup as the training image.
corrector.TrainingImage = trainImage; 

// Set the camera calibration 
corrector.UncorrectedRootFromRawCorrectedTransform  = handEyeCalibResult.GetRaw2DFromCamera2D(); 
// Where handEyeCalibResult is a CogHandEyeCalibrationResult object   

// Step 2:  Train the imageCorrector using all the default values of the remaining properties 

corrector.Train();

// After successfully training, you can check the corrected training image and the associated image  
// mask.  The mask image indicates the pixels in the corrected training image that are unfilled. 

ICogImage correctedTrainingImage = corrector.CorrectedTrainingImage;
ICogImage correctedTrainingImageMask = corrector.CorrectedTrainingImageMask;


// Step3:  Run the image corrector on an input image (uncorrected runtime image) to get the  
// corrected runtime image and the associated corrected image mask, etc.

ICogImage  correctedImage = corrector.Execute(inputImage, runParams);
// Note that inputImage must use the same @ space as the training image, and the transform from  
// pixel space of training image to the pixel space of inputImage can only have a whole pixel shift.  
// Otherwise, Execute() will  throw. 
// The correctedImage will have a "Corrected" space name for the corrected space.  The selected space 
//  name of the correctedImage will be "Corrected".  

// Get the associated mask image for the corrected runtime image.
ICogImage correctedImageMask = corrector.CorrectedImageMask;

Advanced Usages

Change train properties (Need retraining after property change)

  1. You can specify a destination rectangle, so as to reduce the number of unfilled values in the corrected runtime image.

    By default, all the pixels of the uncorrected runtime image will be present in the corrected runtime image.

    The following example uses a destination rectangle to remove the boundary pixels in creating the corrected runtime image:

    Examples

    CogRectangle rect = new CogRectangle();   
    rect.SetXYWidthHeight(
      corrector.CorrectedTrainingImage.Width * 0.1,
      corrector.CorrectedTrainingImage.Height * 0.1,
      corrector.CorrectedTrainingImage.Width* 0.8,
      corrector.CorrectedTrainingImage.Height * 0.8);
    corrector.DestinationRectangle = rect;
    
    corrector.Train();

    Note that DestinationRectangle is specified using the corrector.CorrectedTrainImage.

  2. Add scaling and rotation when generating the corrected pixels.

    By default, the corrected image has approximately the same size as the uncorrected image. The following code changes the corrected image to be approximately twice as high and twice as wide as the uncorrected image:

    Examples

    corrector.CorrectedPixelScaling = 2.0;
    corrector.Train();

    By default, the x-axis of the corrected image aligns with the x-axis of the RawCorrected space. The following code specifies 90 degrees rotation from the corrected image's x-axis to the RawCorrected x-axis:

    Examples

    corrector.CorrectedPixelRotation = CogMisc.DegToRad(90);
    corrector.Train();

  3. Adjust the linear transform between Corrected space and CorrectedRoot space (but does not change the CorrectedRoot space).
    • Change the origin of the Corrected space:

      By default, the origin of the Corrected space is at the origin of the RawCorrected space.

      The following example uses (10, 20) in the training image's root space as the origin of the Corrected space:

      Examples

      corrector.CorrectedOriginSpace =
        CogCalibImageCorrectorAdjustmentSpaceConstants.UncorrectedRoot;
      corrector.CorrectedOriginX = 10;
      corrector.CorrectedOriginY = 20;
      corrector.Train();

      If corrector.CorrectedOriginSpace is UncorrectedRoot, CorrectedOriginX and CorrectedOriginY are defined in UncorrectedRoot space.

      If corrector.CorrectedOriginSpace is RawCorrected, CorrectedOriginX and CorrectedOriginY are defined in RawCorrected space.

    • Change the rotation of the Corrected space:

      By default, the x axis of the Corrected space aligns with the x axis of the RawCorrected space.

      The following example makes the x axis of the Corrected space appear at 45 degree angle in UncorrectedRoot space:

      Examples

      corrector.CorrectedXAxisRotationSpace =
        CogCalibImageCorrectorAdjustmentSpaceConstants.UncorrectedRoot;
      corrector.CorrectedXAxisRotation = CogMisc.DegToRad(45.0);
      corrector.Train();

      If CorrectedXAxisRotationSpace is UncorrectedRoot, CorrectedXAxisRotation is defined in UnCorrectedRoot space.

      If CorrectedXAxisRotationSpace is RawCorrected, CorrectedXAxisRotation is defined in RawCorrected space.

    • Change the handedness of the Corrected space.

      By default, the Corrected space has the same handedness as the RawCorrected space. The following example makes the Corrected space have the opposite handedness as the RawCorrected space:

      Examples

      corrector.SwapCorrectedHandedness = true;
      corrector.Train();

      After changing the above properties and training, you can get back and check the transform between Corrected space and CorrectedRoot space:

      Examples

      CogTransform2DLinear linearTransform =                      
        corrector.GetCorrectedRootFromCorrectedTransform();

Change the run parameters (CogCalibImageCorrectorRunParams)

  1. Change the coordinate space name in the corrected runtime image's coordinate space tree.

    By default, the name of the Corrected space in the corrected runtime image's coordinate space tree is "Corrected". You can change it to a new name:

    Examples

    runParams.CorrectedSpaceName = "NewCorrectedSpaceName";

    The corrected runtime image's coordinate space tree will use this space name for the Corrected space.

  2. Change the setting for the SelectedSpaceName of the corrected runtime image.

    By default, the selected space of the corrected runtime image is the Corrected space, you can change it to CorrectedRoot space by using the following:

    Examples

    runParams.SpaceToOutput =
      CogCalibImageCorrectorSpaceToOutputConstants.CorrectedRoot;

  3. Change the pixel values for the unfilled pixels in the corrected runtime image.

    By default, all the unfilled pixels in the corrected runtime image are set to a value of 128. The following example will set all the unfilled pixels in the corrected runtime image to a value of 0:

    Examples

    runParams.UnfilledPelValueEnabled = true;
    runParams.UnfilledPelValue = 0;

Get the various transforms between the uncorrected images and the corrected images

After training, you can get the transform between the pixel space of the uncorrected image and the pixel space of the corrected image:

Examples

ICogTransform2D uncorrectedPixelFromCorrectedPixel =
  corrector.GetUncorrectedPixelFromCorrectedPixelTransform(inputImage);

After training, you can also get the transform between the root space of the uncorrected image and the Corrected space of the corrected runtime image:

Examples

ICogTransform2D  uncorrectedRootFromCorrected = 
  corrector.GetComputedUncorrectedRootFromCorrectedTransform();

See Also