Detect and Fit a Line
Basic Concepts
-
Caliper
In image processing, a virtual measurement tool detects edges within a specified region. Adjusting its count, width, and length affects the accuracy and stability of edge detection.
-
Edge polarity
It refers to the direction of grayscale change across an edge, e.g., dark-to-light or light-to-dark.
Workflow
The process of configuring this Step is shown below:
-
Configure the input. Connect the Step ports in the graphical programming workspace or select the input under Input in the parameter configuration panel.
-
Complete the ROI Settings.
-
Set other parameters.
-
Confirm the output items in the Output section.
-
Run the Step, and view output.
Input Description
| Input item | Description |
|---|---|
Image |
The image used for detecting a straight edge. |
Alignment Parameter Group |
This Step is used to adjust the pose of the ROI synchronously according to the pose transformation of the target object. |
Parameter Description
| Parameter | Description |
|---|---|
ROI Settings |
You can draw a rectangular ROI. The system extracts multiple columns of pixels according to the caliper settings, and the detected edge points in each column will be used for line fitting.
|
Fitted Line Direction |
Select an appropriate option from the drop-down list to determine the direction vector of the fitted line, thus determining the direction of the fitted line.
|
Edge Polarity |
This parameter specifies the direction in which the grayscale values change at the edges. Value list:
|
Filter Window Size |
Specify the window size to be used when filtering each column of pixels in its direction. Filtering can reduce noise and improve the stability of edge detection results. |
Edge Mode |
Define the edge types to be retained in edge detection. Value list: Best, First, Last. |
Grayscale Change Threshold |
This parameter specifies the minimum grayscale variation between adjacent pixels at the edge of an extracted pixel column required for edge point detection. Setting this parameter value properly can effectively filter out weak edges and noise. |
Use Relative Threshold |
Once selected, an edge point is detected only if the grayscale variation between adjacent pixels at the edge of a pixel column meets or exceeds the specified percentage of the maximum variation in that column. Once this parameter is selected, set Relative Threshold. |
Outlier Fraction |
The percentage of outlier points to be removed during line fitting. |
Output Description
Select the output item(s) to add the output port(s) to the Step, and the corresponding data will be output after the Step is run. You can select the output according to the actual measurement requirements.
| If you select an expandable output item, you should expand it by clicking ▶, and then set the Lower limit and Upper limit values to determine the acceptable range. If the output value falls within the acceptable range, the measurement item is judged as passing (OK), or else it is judged as failing (NG). |
| Output Item | Description |
|---|---|
Fitted Line |
The straight line obtained through fitting. |
Midpoint |
The midpoint of the fitted line. |
Midpoint X |
The X value of the midpoint of the fitted line. |
Midpoint Y |
The Y value of the midpoint of the fitted line. |
Rotation Angle |
The rotation angle of the fitted line relative to the positive X-axis. |
Troubleshooting
|
For common errors, see Error Code List. If the error code is inconsistent with the error message, please contact Technical Support for help. |
CV-W8601
Inappropriate ROI settings.
Possible cause: The size of the ROI is too large, more than twice the size of the image.
Solution: Reset the ROI to ensure that it is of a proper size.
CV-W8602
Error: The “Caliper Center Spacing” value is outside of the valid range.
Solution: Make sure the parameter value is within 0–1000.
CV-W8603
Error: The set “Caliper Width” is invalid.
Solution: Make sure the parameter value is within 0–100.
CV-W8604
Error: The “Filter Window Size” value is outside of the valid range.
Solution: Make sure the parameter value is within 0–100.
CV-W8605
Error: The set “Edge Polarity” is invalid.
Solution: Select a valid edge detection mode from the drop-down list.
CV-W8606
Error: The set “Neighborhood” is invalid.
Solution: Select a valid edge detection mode from the drop-down list.
CV-W8607
Error: The “Grayscale Variation Threshold” is outside of the valid range.
Solution: Make sure the parameter value is within 0–255.
CV-W8608
Error: The value of “Relative Threshold” is outside of the valid range.
Solution: Make sure the parameter value is within 0–100%.
CV-W8609
Error: The “Outlier Fraction” value is outside of the valid range.
Solution: Make sure the parameter value is within 0–100%.
CV-W8610
Error: The set “Fitted Line Direction” is invalid.
Solution: Select a valid fitted line direction from the drop-down list.
CV-W8611
Error: Not enough edge points were detected to fit the line.
Possible Cause:
-
Inappropriate ROI settings.
-
The calipers are not set properly.
-
“Grayscale Change Threshold” and “Relative Threshold” are too large.
-
The set “Edge polarity” is not proper.
Solution:
-
Ensure that the ROI is not too small.
-
Adjust the caliper settings to ensure edge points can be detected from the calipers.
-
Lower the “Grayscale Variation Threshold” and “Relative Threshold”.
-
Ensure that the “Edge Polarity” parameter is set properly.