...
Expand | |||||||
---|---|---|---|---|---|---|---|
| |||||||
Exit image evaluation from flow:It is possible to stop evaluation early to save time based on a specific condition e.g. a Classifier distinguishes product types and chooses different evaluation branches to meet the specific product requirements.
See the example of different evaluation flows based on product type:
It is necessary to modify the list |
Expand | |||||
---|---|---|---|---|---|
| |||||
Crop image by a detected rectangleUseful when the image contains unnecessary elements and the goal is to focus only on a certain part. To do this:
It is necessary to modify the |
Expand | |||||||||
---|---|---|---|---|---|---|---|---|---|
| |||||||||
Save evaluated images to foldersUseful when your goal is to inspect the evaluated images at a later time again.
Code Block | | ||||||||
|
Code Block | ||
---|---|---|
| ||
import cv2 import skimage import numpy as np from datetime import datetime from pathlib import Path RED = (0, 0, 255) GREEN = (0, 255, 0) BLUE = (255, 0, 0) YELLOW = (0, 255, 255) WHITE = (255, 255, 255) #################################### STARTPROGRAM CODE SETTINGS ####################################### # Specify the path to the save folder, image formats, and the wanted color of rectangles SAVE_FOLDER = r"C:\Users\Vox\Downloads" ORIGINAL_IMAGE_FORMAT = '.png' ANNOTATED_IMAGE_FORMAT = '.jpg' RECTANGLE_COLOR = RED ################################# END CODEPROGRAM SETTINGS #################################### def main(context): # Get result result = context['result'] # When image has result TRUE, program stop. if result is True: return # Get image from context image = context['image'] # Save Original Image save_image_to_disc(image, filename_prefix = 'original_', image_format = ORIGINAL_IMAGE_FORMAT) # Draw rectangles to original image image = draw_rectangles_to_image(image, context, BARVA_RECTANGLU) # Save Anotated Image save_image_to_disc(image, filename_prefix = 'anotated_', image_format = ANNOTATED_IMAGE_FORMAT) def save_image_to_disc(image, filename_prefix:str = '', image_format = '.png'): timestamp = generate_timestamp() full_save_path = Path(SAVE_FOLDER).joinpath(filename_prefix + timestamp + image_format) cv2.imwrite(str(full_save_path), image) def generate_timestamp(): timestamp = datetime.now() formatted_timestamp = timestamp.strftime("%Y-%m-%d_%H-%M-%S_%f") return formatted_timestamp def draw_rectangles_to_image(image, context, color:tuple = (0,0,255)): for rect in context['detectedRectangles']: rect_start = (int(rect['x']), int(rect['y'])) rect_end = (int(rect['x'] + rect['width']), int(rect['y'] + rect['height'])) image = cv2.rectangle(image, rect_start, rect_end, color, 2) return image |
It is necessary to modify at least SAVE_FOLDER
with your path to the saving folder. Modifying ?_IMAGE_FORMAT
or RECTANGLE_COLOR
is not necessary.
The folder path to copy and paste is written here:
Expand | |||||
---|---|---|---|---|---|
| |||||
Send data to S7-1200 PLCTo send your custom data or data from Pekat to a PLC:
This is for sending booleans. To send other type of data: Set up
|
Expand | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
Use Heatmap as a maskIt is possible to use previously detected heatmap (from anomaly or surface) as a masking tool to hide specific objects or features.
To get back the original image (delete the mask), copy and paste the following code into a different code module:
See image: Surface detector finds the heatmap of an object → Code module masks out the image → Further detections are done → Code module unmasks back to the original. |
Expand | |||||
---|---|---|---|---|---|
| |||||
Measure the distance between rectanglesIt is possible to calculate the distance between detected objects for further evaluation.
This code:
|
Expand | |||||
---|---|---|---|---|---|
| |||||
Color a grayscale depth map imageThe grayscale depth map can be colored based on a specified threshold and color. Useful when using a 3D scanner (like Photoneo) that returns a depth map. The extreme pixels (white and black) in the image are ignored, other pixels are linearly interpolated and assigned a color.
|
Expand | |||||
---|---|---|---|---|---|
| |||||
Rename existing model classesIt is possible to change the names of classes that were used in training. Useful when you made a mistake during naming or only made numeric names like “Type 1” - see images
Classes not mentioned in the dictionary will not be modified.
|
Expand | |||||
---|---|---|---|---|---|
| |||||
Rescaling the heatmap back to the original is useful in a project where Anomaly or Surface modules are applied on a smaller cut-out version of the image to lower evaluation time and increase heatmap accuracy.
|
Expand | ||
---|---|---|
| ||
It is possible to count and show the amount of rectangles belonging to a specific class using the following guide.
|