Up | CircleFinder2D - 165 | EasyOCR - 78 | PolygonMatch2 - 84 | GCPS -110 | HeightMap3D - 111 | ImageExtrema - 129 | PCA3D - 140 | CameraPose3D - 148 | MonoPose3D - 149 | ImagePicker3D - 145 | ExternalCoordinates3D - 157 | MaMa3D - 152 | CircleSegmentor - 153 | PolygonMatch3 - 160

Release Notes
 

  

 
PolygonMatch2 - 84

Preliminary

PolygonMatch2 is an improved PolygonMatch. PolygonMatch2 adds a preprocessing stage, making it possible to search quickly over a large area for an object. With the exception of the preprocessing, the tool (and this description) is the same as PolygonMatch.

PolygonMatch is an optimal way to locate objects with subpixel accuracy. Multiple polygons defines the shape or model of the object. Using the model the same shapes are extracted from the images and fitted to the original model with the highest possible accuracy. 

Below a valve which located using two polygons - a circle and a straight line. A model can consist of any number of polygons.

        

The tool is very powerful tool and can be used to locate an object of any size or shape with sub-pixel resolution.

The next example corrects the location of a printed circuits by 0.05 mm with accuracy better than 1/10 a pixel.

        

Other important application areas are shape verification.


Setup

Reference - Reference system selection

Trace lines

  • Use Traceline Count - selects to specify the traceline count
    • Count - number of trace lines
    • Step length - distance between traceline
      • Ref coord
      • Pixels
  • Start point - position of starting point on trace line given in reference coordinates
  • End point - position of end point on trace line given in reference coordinates
    • Inverted the sign of start and stop point will change the direction of the trace comb
  • Trace step (pixels) - normally 1 - given in pixels
  • Line width (pixels) - 0 - trace line is not averaged - a higher value will average N pixels perpendicular to the trace comb

Edge detection

  • Smooth base - 3 is normally a good value
  • Smooth counter - 1 default - given i pixels
    • The smoothing increasing with higher values
  • Differentiation
    • 0 - give threshold
    • 1 - 1. order differentiation - the derivative - default normally used
    • 2 - 2. order differentiation
  • Threshold - the threshold or sensitivity of the edge detector - a lower value increases the sensitivity
    • % activates adaptive - threshold is set to N % of maximum values of edges
    • Minimum treshold define minimum value of threshold to accept when adaptive treshold is active
  • Polarity - All transitions | Light to dark | Dark to light
  • Mode - Peak | Threshold
  • Edge choice - First | Largest | Last | Nearest - Largest is default and normally the best choice

Child reference base

  • Active - activate child reference base
  • Origin.X
  • Origin.Y
  • Rotation

Note : Child reference base is used to fix the model to the object when need

 


Advanced.Match

Polygon match

  • Parameters to adjust

    • Translation, rotation - default

    • Translation, scale

    • Translation, rotation, scale, skew

      • Note: good image quality and an increased Repeat Count is needed to get a good fit

      • Note: the shape of the polygon must contain information to be able to calculate all degrees of freedom

    • Translation, rotation, perspective

      • Note: good image quality and an increased Repeat Count is needed to get a good fit

      • Note: the shape of the polygon must contain information to be able to calculate all degrees of freedom

    • Translation, rotation, scale

      • Note: this is done by iterating translation/rotation and translation/scale. The first iteration is always run with translation/rotation; if final fit is selected, it is always run using translation/scale.

  • Repeat count - the number of iteration to fitting the polygons

    • 2 is default but higher values will normally increase the accuracy

    • Lower values will save image processing time

  • Keep best points - the percentage of edge points used in iteration

    • 95 percentage is default

    • A lower value will normally be more robust

  • Stop if fewer than (%) - stops matching process if less than % edge points is located - used to save time

  • Perform final fit with distance constraints - default on - added to be able to investigate polygon matching in detail

    • Final fit max distance - can be given in pixels or reference coordinates

Result acceptance ( constraints )

  • Min match percentage - any of these constraints may make a match invalid

  • Max RMS value

  • Max angle (abs)

  • Max distance

  • Max offsetX (abs)

  • Max offsetY (abs)

  • Hide polygon match items if not accepted - only show polygons if a match is found

The result acceptance is reflected in the OK result - can be use to easily validate the found polygon.

Trace line samples dialog - a helper window to set trace line filter parameters and thresholds

  • Middle - show the middle traceline
  • Middle+edges - shows the first, middle and last traceline
  • Selection - show the selected tracelines
  • Line indices - traceline selection
    • example: 2,3,12-15
    • example: 1 3 5 7
  • Show trace line popup - activates a modeless traceline window

        
         Example tracelines - Middle+edges is selected

Include in description

Include in the onscreen description of valid/invalid match

  • Percent
  • Offset
  • Angle
  • Scale

String results

Create Python tuples describing the fitted model:

  • Fitted points - the edge points
  • Fitted model - the changedmodel


Advanced.Initial Search

On this page you can create a set of preprocessing polygon sets from the original - scaled, rotated and moved. During processing, this set is scanned, and the best fit is taken further to be processed completely.

Scale

  • Set a range of scales to test, making your polygons smaller or larger

Rotation

  • Set a range of angles to test, rotating your polygons

Positions

  • Set a range of positions to test, moving your polygons across the image to find a match

Regular grid

  • Helps create a regular grid of positions

Rotation /scale center

  • To rotate or scale a polygon, a center is needed. You most likely want to do this automatically by using the center of gravity (default).

Result string

  • Gives insight in the preprocessing step by returning Python dictionaries with all preprocessing results


Matching a rectangle

A rectangle can be matched using PM.

This rectangle is matched using Rotation and Translation. The angle is estimated correctly but the center of gravity is moved due to the fact that the model is too long.

The same rectangle is matched using Translation, Rotation and Scale. Both size, rotation and position is correctly and estimated due to the fact that the model is fitted to the object.

The same rectangle is matched using Translation and Scale. The model is not accepted - the red rectangle is the original not accepted model. The green rectangle is the fitted rectangle with size, rotation and position errors.


Polygons

Line definition file - The paths to be searched are initially read from a text file (see the StrVec format). The name of that file is also stored, for possible future reload. The path information, however, is stored directly in the system, without need for the external file.
You can browse for or manually edit the filename; by clicking "Load", the file is read and its contents stored internally. 

  • Always read file at startup (overwrite SPB) - With this selection, the file is always loaded at startup.

Polygon properties

  • Closed polygons - Select this box if the polygons are closed by default. Individual polygons can be customised separately.

Search area

  • Numbered list - ordered list of polygons. Each polygon can be made active/inactive by clicking the checkbox in front of the number
  • Contents - the points of the selected polygon
  • New - add polygon
  • Delete - remove selected polygon
  • Up - moves polygon up in list
  • Down - moved polygon down in list
  • Paste new - creates a new polygon, pastes the polygon from the clipboard and presses apply  - this is the quickest way to create many polygons
  • Highlight selection - highlights the selected polygon in the image
    • used to identify a polygon in the image
  • Copy - copies the selected polygon to the clipboard
  • Paste - pastes the clipboard to the selected polygon - will overwrite an existing polygon
    • Copy can be used to transfer polygon to the image for editing and modification. The edited polygon is pasted back to the tool using Paste. More on Point and Click Operations
  • Snap to model - this will replace all active polygons with the fitted versions. Useful for fine-tuning the polygons to a good picture (model). - Note:  To improve accuracy Snap to model may be executed a number of times - Snap and Apply and Snap again.

Vector mouse menu - activate by right mouse clicking in the Vector list

  • New - creates a new vector
  • Delete - deletes the selected vector
  • Custom... - open dialog to define settings for a single polygon
  • Set defaults - remove custom settings for a polygon and revert to defaults
  • Paste new - paste clipboard as new polygon
  • Up - moves polygon up in list
  • Down - moved polygon down in list
  • Grid... - activate dialog for defining polygon grid
  • Delete all - removes all polygons from list
  • Delete empty vectors - remove all empty polygons


Autofit - Polygon Model Wizard

Using the Polygon Model Wizard Scorpion helps you create optimal edge polygons for Polygonmatch.

  • Autofit polygons
    • When active Ctrl LMouse will make a edge contour along a path or an object

The traceline settings are defined under the Setup tab except:

  • Step length
  • Start and End of trace lines

Visualize will display the trace line - see image to the right

Note: If Edge trace is difficult - verify wizard settings - long trace lines may cause problems around edge or in corners.

Polygon properties dialog - vector list Custom choice:

Each polygon can have its own settings, overriding the default values. The custom settings include open/closed, tracelines and edge detection.

Hint: Use individual polygon traceline setting to improve the model

        

Trace lines

  • Use Traceline Count - selects to specify the traceline count
    • Count - number of trace lines
    • Step length - distance between traceline
      • Ref coord
      • Pixels
  • Start point - position of starting point on trace line given in reference coordinates
  • End point - position of end point on trace line given in reference coordinates
    • Inverted the sign of start and stop point will change the direction of the trace comb
  • Trace step (pixels) - normally 1 - given in pixels
  • Line width (pixels) - 0 - trace line is not averaged - a higher value will average N pixels perpendicular to the trace comb

Edge detection

  • Smooth base - 3 is normally a good value
  • Smooth counter - 1 default - given i pixels
    • The smoothing increasing with higher values
  • Differentiation
    • 0 - give threshold
    • 1 - 1. order differentiation - the derivative - default normally used
    • 2 - 2. order differentiation
  • Threshold - the threshold or sensitivity of the edge detector - a lower value increases the sensitivity
    • % activates adaptive - threshold is set to N % of maximum values of edges
    • Minimum treshold define minimum value of threshold to accept when adaptive treshold is active
  • Polarity - All transitions | Light to dark | Dark to light
  • Mode - Peak | Threshold
  • Edge choice - First | Largest | Last | Nearest - Largest is default and normally the best choice


Add polygon

Rectangle and Circle can be added as polygon using this tab. This is valuable when working with these shapes.

        

Point & Click Support

Two points will define a circle - first point is circle center and the seconds defines the radius. Four points will define a rectangle. Ctrl-Z will paste the clipboard to the tool. Ctrl-A will add the object to the polygon vector list


Visualisation

Description

Description of accepted polygon (see Advanced page)

Description (invalid)

Description of non-accepted polygon (see Advanced page)

EdgePoints

Edge points, final iteration

EdgePointsOrig

Edge points, first iteration

FittedPoints

Fitted points final iteration

FittedPointsOrig

Fitted points first iteration

MatchedPolygon The best fitted polygon

MissingPoints

Tracelines without edgepoints, final iteration

MissingPointsOrig

Tracelines without edgepoints, first iteration

NonAcceptedPolygon The original model is visualised when no match
OriginalPolygon The original model

OutlierPoints

Points too far from polygon, final iteration

OutlierPointsOrig

Points too far from polygon, first iteration

PreEdgePoints Edge points from preprocessing step
PreprocessedPolygon Preprocessed polygons for match
PreTraceLines Trace lines from preprocessing step
TraceLines Tracelines, final iteration
TraceLinesOrig Tracelines, first iteration


Results
 

Iterations

Number of performed iterations (less than specified if no match)

Fit percent

Percent of tracelines that has a point that is accepted

RMS RMS value of the fitted polygons
OK 1 if fit OK, 0 otherwise

Offset X

Movement of fitted polygon, x

Offset Y

Movement of fitted polygon, y

Distance Total movement of fitted polygon

Angle

Rotation of fitted polygon

Scale X

Scaling of fitted polygon, x

Scale Y

Scaling of fitted polygon, y

Skew

Axis skew

Preprocess scales Python dictionary: all scales used
Preprocess rotations Python dictionary: all angles used
Preprocess positions Python dictionary: all positions used
Preprocess results Python dictionary: match result for all preprocess combinations
Best scale Best scale used
Best rotation Best angle used
Best position.x Best position used, x
Best position.y Best position used, y
Origin.x Position of base, x
Origin.y Position of base, y
Fitted points The final fitted edge points
Fitted model The original model, moved to best position


ExecuteCmd support
(see also executeCmd)

Command

Parameters

Return values

Comments

Set Object=ROI;Value=<polygon> ok,None Sets the first ROI polygon. See Copy/paste ROIs for details. (*)
Set Object=ROI;Number=<number>;
Value=<polygon>
ok,None Sets the numbered ROI polygon. See Copy/paste ROIs for details. (*)
Add Object=ROI;Value=<polygon> ok,None Adds ROI polygon to the end of the list. See Copy/paste ROIs for details.
Get Object=ROI;Number=<number> ok,<polygon> Gets numbered polygon, as Scorpion polygon (StrArr format).
Get Object=Tuple;Number=<number> ok,<tuple> Gets numbered polygon, as Python tuple
Clear Object=ROI;Number=<number> ok,None Clears numbered polygon (makes empty)
DeleteAll - ok,None Deletes all polygons
SnapToModel - ok,None Replaces active polygons with the best fit in the image. OK to run also when the tool dialog is open.

(*) Note: Polygon properties are not supported by these methods, although existing properties will be kept when the SET command is used.


Example 1: Copy a polygon from the clipboard

tool =  GetTool('PM')
tool.executeCmd('Set','Object=ROI;Number=1;source=clipboard')


Example 2: Copy a polygon to the clipboard

tool =  GetTool('PM')
tool.executeCmd('Get','Object=ROI;Number=1;destination=clipboard')


Example 3: Add model from Clipboard and Snap the model

pm=GetTool('StickerPosition')
pm.executeCmd('Set','Object=ROI;Number=1;source=clipboard')
ExecuteCmd('InspectExecute','')  # inspection needed for SnapToModel
pm.executeCmd ('SnapToModel','')
ExecuteCmd('InspectExecute','')


Keyboard shortcuts
- More information

Shortcut

Command

Comments

Ctrl-Z Set ROI Sets the selected polygon to points marked in the image. If only a single point is marked, the polygon is moved, centered around the point.
If the tool dialog is not open, the first polygon is set.
Ctrl-P Snap to model Replaces active polygons with the best fit in the image. OK to run also when the tool dialog is open.
Ctrl-1 - Ctrl-0 Set polygon 0-10 Sets the numbered polygon to points marked in the image. If only a single point is marked, the polygon is moved, centered around the point. If a new polygon is defined this way, any missing polygons in between are set as empty.
Ctrl-Shift-1 - Ctrl-Shift-0 Clear polygon 0-10 Clears the numbered polygon (sets empty).

 


Scorpion Vision Version XII : Build 646 - Date: 20170225
Scorpion Vision Software® is a registered trademark of Tordivel AS.
Copyright © 2000 - 2017 Tordivel AS.