Flaw & Anomaly Inspection
The
IFlawDetectionEdgesResultArguments
interface in TypeScript defines the structure for flaw detection (edges) results. It includes the following properties:
-
time
: number; indicates the time taken by a tool or process, including image acquisition.
-
tool_time
: number; similar to time, indicating the time taken by a tool or process.
-
success
: boolean; indicates whether a specific operation or process was successful (true) or not (false).
-
defects_present
: boolean; indicates if one or more defects were found.
-
defects_length
: number; indicates the total length of all detected flaws in pixels.
-
statistics: IStatisticsArguments
; contains tool execution statistics accumulated between operations.
interface IFlawDetectionEdgesResultArguments {
time: number;tool_time: number;success: boolean;defects_present: boolean;defects_length: number;statistics: IStatisticsArguments;
}
The
IFlawDetectionIntensityResultArguments
interface in TypeScript defines the structure for flaw detection (intensity) results. It includes the following properties:
-
time
: number; indicates the time taken by a tool or process, including image acquisition.
-
tool_time
: number; similar to time, indicating the time taken by a tool or process.
-
success
: boolean; indicates whether a specific operation or process was successful (true) or not (false).
-
defects_present
: boolean; indicates if one or more defects were found.
-
defects_area
: number; indicates the total area of all detected flaws in pixels.
-
statistics: IStatisticsArguments
; contains tool execution statistics accumulated between operations.
interface IFlawDetectionIntensityResultArguments {
time: number;tool_time: number;success: boolean;defects_present: boolean;defects_area: number;statistics: IStatisticsArguments;
}
The Classification tool is available on NS42 and FS42 devices only.
The
IClassifyObjectResultArguments
interface in TypeScript defines the structure for classification tool results. The classification tool uses a trained deep learning model to categorize the object in a region of interest into one of the classes defined by that model. A job can contain at most one classification tool, and its result is available only in the
onResults
callback. It includes the following properties:
-
time: number;
indicates the time taken by a tool or process, including image acquisition.
-
tool_time: number;
similar to time, this number indicates the time taken by a tool or process.
-
success: boolean;
indicates whether a specific operation or process was successful (true) or not (false). When using the classification tool, a passing result requires the predicted class to be enabled in the configuration and its confidence threshold to meet or exceed the defined threshold. A failing result occurs if either condition is missed, or if the tool or job times out. The result is reversed if the Invert Pass/Fail Result option is enabled.
-
statistics: IStatisticsArguments;
contain the tool's statistics accumulated between operations.
-
predicted_class_name: string;
indicates the name of the class with the highest score. It is an empty string when the tool did not produce a prediction.
-
score: number;
indicates the score of the predicted class, in the range 0.0 to 1.0. The value is produced as a single-precision float and widened to a JavaScript number, so a score of 0.95 is read as 0.949999988079071. Compare it using a tolerance rather than testing for equality, and format it for display.
-
score_matrix: IClassificationArguments[];
contains one entry for every class defined by the model, including the predicted class, in ascending class id order. The entries are not ordered by score. It is empty when the tool did not produce a prediction.
-
accepted_class: boolean;
indicates whether the predicted class is enabled in the tool configuration (true) or not (false). It does not take the confidence threshold into account, and it is true when the tool did not produce a prediction, so it must not be used on its own to decide whether the tool passed.
interface IClassifyObjectResultArguments {
time: number;
tool_time: number;
success: boolean;
statistics: IStatisticsArguments;
predicted_class_name: string;
score: number;
score_matrix: IClassificationArguments[];
accepted_class: boolean;
}
The
IClassificationArguments
interface in TypeScript defines the structure of a single class score inside score_matrix. It includes the following properties:
-
class_id: number;
indicates the zero-based index of the class in the model. It is also the position of the entry in score_matrix.
-
class_name: string;
indicates the name of the class as defined by the model.
-
score: number;
indicates the score for this class, in the range 0.0 to 1.0.
interface IClassificationArguments {
class_id: number;
class_name: string;
score: number;
}
Reading the classification result
A tool result is read from
args.tool_results_by_names
using the tool's script name. The script name is the tool's name in the job, with every character that is not a letter or a digit replaced by an underscore. For example, the default name Classification 1 becomes Classification_1. A tool that did not run contributes no entry; therefore, the property is undefined and must be checked before use.
Reporting the predicted class and the runner-up
export function onResults (args) {
const result = args.tool_results_by_names['Classification_1'];
if (!result) {
return {};
}
const ranked = [...result.score_matrix].sort((a, b) => b.score - a.score);
console.log(`Predicted: ${result.predicted_class_name} (${result.score.toFixed(2)})`);
if (ranked.length > 1) {
console.log(`Runner-up: ${ranked.class_name} (${ranked.score.toFixed(2)})`);
}
return {};
}
Sending the verdict, the class, and the score over TCP/IP
The verdict comes from
success
, which accounts for the confidence threshold, not from
accepted_class
.
export function onResults (args) {
const result = args.tool_results_by_names['Classification_1'];
if (!result) {
return { tcp_ip: 'NO_RESULT\r\n' };
}
const verdict = result.success ? 'PASS' : 'FAIL';
return { tcp_ip: `${verdict},${result.predicted_class_name},${result.score.toFixed(3)}\r\n` };
}
Failing the job when the predicted class is not the expected one
Returning
null
for
job_success
leaves the job's own verdict untouched, whereas returning
false
forces the job to fail.
export function onResults (args) {
const result = args.tool_results_by_names['Classification_1'];
if (!result) {
return { job_success: null };
}
return { job_success: result.success && result.predicted_class_name === 'ClassA' };
}
Classification tool settings that affect a script
-
Model
- each classification tool holds one trained model, which defines the set of classes reported in
score_matrix
and the
class_id
of each one.
-
Class enable and confidence threshold
- every class of the model can be enabled or disabled individually and given its own confidence threshold in the range 0.0 to 1.0, which defaults to 0.90. The enabled state of the predicted class is reported as
accepted_class
, and together with that class's threshold it determines
success
.
-
Invert Pass/Fail Result
- reverses
success
.
-
Region of Interest (ROI)
- a rectangle or a circle. The classification tool does not act as a fixture leader; however, it can follow a fixture leader. The transformed region of interest is not reported to scripts.
The predicted class identifier and the model version are not reported to scripts. Match a class by
class_name
and read its
class_id
from
score_matrix
if a numeric identifier is needed.
The
IAnomalyDetectionResultArguments
interface in TypeScript defines the structure for anomaly detection results. It includes the following properties:
-
time: number;
indicates the time taken by a tool or process, including image acquisition.
-
tool_time: number;
similar to time, this number indicates the time taken by a tool or process.
-
success: boolean;
indicates whether a specific operation or process was successful (true) or not (false).
-
statistics: IStatisticsArguments;
contains the tool's statistics accumulated between operations.
-
valid: boolean;
indicates whether an image is considered valid (true) or not (false).
-
score: number;
represents the score of an image.
-
confident: boolean;
indicates whether a result is considered confident (true) or not (false).
-
roi: IPointArguments[];
an array of IPointArguments objects, each representing a point in two-dimensional space. It typically denotes the positions or corners of the tool region of interest.
interface IAnomalyDetectionResultArguments {
time: number;
tool_time: number;
success: boolean;
statistics: IStatisticsArguments;
valid: boolean;
score: number;
confident: boolean;
roi: IPointArguments[];
}