Blocks.Blur
1import cv2 2import numpy as np 3 4def main(inputs, outputs, parameters, synchronise): 5 """ 6 ## Blurs an Object\n 7 The object to be blurred is read through the inputs. 8 We have multiple available blurs including Gaussian, Averaging and Median Blur. 9 We can change these blurs by changing the name given in the parameter block 10 11 `while` loop is the part of the program that is executed continuously. 12 It is enabled by default but can be disabled by passing in 0 through the enable wire. 13 14 Outputs the blurred image through the `share_image()` function 15 16 **Inputs**: BGR Image 17 18 **Outputs**: BGR Image 19 20 **Parameters**: BlurType 21 """ 22 # Blur Type 23 blur_type : str = parameters.read_string("BlurType") 24 """Type of blur, reads from a parameter""" 25 # Kernel Size 26 kernel = tuple([int(x.strip()) for x in parameters.read_string("Kernel").split(',')]) 27 auto_enable = False 28 try: 29 enable = inputs.read_number("Enable") 30 except Exception: 31 auto_enable = True 32 33 while(auto_enable or inputs.read_number('Enable')): 34 frame = inputs.read_image("Img") 35 if frame is None: 36 continue 37 38 if blur_type == 'Gaussian': 39 blurred_img = cv2.GaussianBlur(frame, kernel, 0) 40 41 elif blur_type == 'Averaging': 42 blurred_img = cv2.blur(frame, kernel) 43 44 elif blur_type == 'Median': 45 blurred_img = cv2.medianBlur(frame, kernel[0]) 46 47 outputs.share_image('Out', blurred_img) 48 synchronise()
def
main(inputs, outputs, parameters, synchronise)
5def main(inputs, outputs, parameters, synchronise): 6 """ 7 ## Blurs an Object\n 8 The object to be blurred is read through the inputs. 9 We have multiple available blurs including Gaussian, Averaging and Median Blur. 10 We can change these blurs by changing the name given in the parameter block 11 12 `while` loop is the part of the program that is executed continuously. 13 It is enabled by default but can be disabled by passing in 0 through the enable wire. 14 15 Outputs the blurred image through the `share_image()` function 16 17 **Inputs**: BGR Image 18 19 **Outputs**: BGR Image 20 21 **Parameters**: BlurType 22 """ 23 # Blur Type 24 blur_type : str = parameters.read_string("BlurType") 25 """Type of blur, reads from a parameter""" 26 # Kernel Size 27 kernel = tuple([int(x.strip()) for x in parameters.read_string("Kernel").split(',')]) 28 auto_enable = False 29 try: 30 enable = inputs.read_number("Enable") 31 except Exception: 32 auto_enable = True 33 34 while(auto_enable or inputs.read_number('Enable')): 35 frame = inputs.read_image("Img") 36 if frame is None: 37 continue 38 39 if blur_type == 'Gaussian': 40 blurred_img = cv2.GaussianBlur(frame, kernel, 0) 41 42 elif blur_type == 'Averaging': 43 blurred_img = cv2.blur(frame, kernel) 44 45 elif blur_type == 'Median': 46 blurred_img = cv2.medianBlur(frame, kernel[0]) 47 48 outputs.share_image('Out', blurred_img) 49 synchronise()
Block Description
Blurs an Object
The object to be blurred is read through the inputs. We have multiple available blurs including Gaussian, Averaging and Median Blur. We can change these blurs by changing the name given in the parameter block
while
loop is the part of the program that is executed continuously.
It is enabled by default but can be disabled by passing in 0 through the enable wire.
Outputs the blurred image through the share_image()
function
Inputs: BGR Image
Outputs: BGR Image
Parameters: BlurType