Blocks.EdgeDetector

 1import cv2
 2import numpy as np
 3
 4def main(inputs, outputs, parameters, synchronise):
 5    '''
 6    ## Detects Edges in an Image\n
 7    It takes in two parameters `Lower` and `Upper`. These parameters are used as the limits in Canny Edge 
 8    Detection. First we convert the input `BGR` image to `GRAY`. Next we apply Canny Edge Detection via the 
 9    `cv2.Canny()` function. The resulting image is then converted back to `BGR`.
10
11    This image is then shared to the wire via the `share_image()` function.
12    
13    **Inputs**: BGR Image
14
15    **Outputs**: BGR Image
16
17    **Parameters**: Lower, Upper (Threshold values)
18    '''
19    lower = int(parameters.read_string("Lower"))
20    upper = int(parameters.read_string("Upper"))
21
22    auto_enable = False
23    try:
24        enable = inputs.read_number("Enable")
25    except Exception:
26        auto_enable = True
27
28    while(auto_enable or inputs.read_number('Enable')):
29        frame = inputs.read_image("Img")
30        if frame is None:
31            continue
32
33        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
34        edge_img = cv2.Canny(frame, lower, upper)
35        edge_img = cv2.cvtColor(edge_img, cv2.COLOR_GRAY2BGR)
36        
37        outputs.share_image('Out', edge_img)
38
39        synchronise()
def main(inputs, outputs, parameters, synchronise)
 5def main(inputs, outputs, parameters, synchronise):
 6    '''
 7    ## Detects Edges in an Image\n
 8    It takes in two parameters `Lower` and `Upper`. These parameters are used as the limits in Canny Edge 
 9    Detection. First we convert the input `BGR` image to `GRAY`. Next we apply Canny Edge Detection via the 
10    `cv2.Canny()` function. The resulting image is then converted back to `BGR`.
11
12    This image is then shared to the wire via the `share_image()` function.
13    
14    **Inputs**: BGR Image
15
16    **Outputs**: BGR Image
17
18    **Parameters**: Lower, Upper (Threshold values)
19    '''
20    lower = int(parameters.read_string("Lower"))
21    upper = int(parameters.read_string("Upper"))
22
23    auto_enable = False
24    try:
25        enable = inputs.read_number("Enable")
26    except Exception:
27        auto_enable = True
28
29    while(auto_enable or inputs.read_number('Enable')):
30        frame = inputs.read_image("Img")
31        if frame is None:
32            continue
33
34        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
35        edge_img = cv2.Canny(frame, lower, upper)
36        edge_img = cv2.cvtColor(edge_img, cv2.COLOR_GRAY2BGR)
37        
38        outputs.share_image('Out', edge_img)
39
40        synchronise()

Block Description

Detects Edges in an Image

It takes in two parameters Lower and Upper. These parameters are used as the limits in Canny Edge Detection. First we convert the input BGR image to GRAY. Next we apply Canny Edge Detection via the cv2.Canny() function. The resulting image is then converted back to BGR.

This image is then shared to the wire via the share_image() function.

Inputs: BGR Image

Outputs: BGR Image

Parameters: Lower, Upper (Threshold values)