Blocks.Threshold
1import cv2 2import numpy as np 3 4def main(inputs, outputs, parameters, synchronise): 5 ''' 6 ## Thresholds an Image 7 THis block reads the parameters `LowerThreshold` and `UpperThreshold`.\n 8 Based on these values it converts the input image form `BGR` into `GRAY` and applies the `cv2.threshold()` function on it. 9 10 The image is then converted back into `BGR` and shared to the output wire using the 11 `share_image()` function. 12 13 [Further reading](https://docs.opencv.org/4.x/d7/d4d/tutorial_py_thresholding.html) 14 15 **Inputs**: BGR Image 16 17 **Outputs**: BGR Image 18 19 **Parameters**: LowerThreshold, UpperThreshold 20 ''' 21 lower = parameters.read_number("LowerThreshold") 22 upper = parameters.read_number("UpperThreshold") 23 24 auto_enable = False 25 try: 26 enable = inputs.read_number("Enable") 27 except Exception: 28 auto_enable = True 29 30 while(auto_enable or inputs.read_number('Enable')): 31 frame = inputs.read_image("Img") 32 if frame is None: 33 continue 34 35 frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 36 (T, thresh) = cv2.threshold(frame, lower, upper, cv2.THRESH_BINARY) 37 output = cv2.cvtColor(thresh, cv2.COLOR_GRAY2BGR) 38 39 outputs.share_image('Out', output) 40 41 synchronise()
def
main(inputs, outputs, parameters, synchronise)
5def main(inputs, outputs, parameters, synchronise): 6 ''' 7 ## Thresholds an Image 8 THis block reads the parameters `LowerThreshold` and `UpperThreshold`.\n 9 Based on these values it converts the input image form `BGR` into `GRAY` and applies the `cv2.threshold()` function on it. 10 11 The image is then converted back into `BGR` and shared to the output wire using the 12 `share_image()` function. 13 14 [Further reading](https://docs.opencv.org/4.x/d7/d4d/tutorial_py_thresholding.html) 15 16 **Inputs**: BGR Image 17 18 **Outputs**: BGR Image 19 20 **Parameters**: LowerThreshold, UpperThreshold 21 ''' 22 lower = parameters.read_number("LowerThreshold") 23 upper = parameters.read_number("UpperThreshold") 24 25 auto_enable = False 26 try: 27 enable = inputs.read_number("Enable") 28 except Exception: 29 auto_enable = True 30 31 while(auto_enable or inputs.read_number('Enable')): 32 frame = inputs.read_image("Img") 33 if frame is None: 34 continue 35 36 frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 37 (T, thresh) = cv2.threshold(frame, lower, upper, cv2.THRESH_BINARY) 38 output = cv2.cvtColor(thresh, cv2.COLOR_GRAY2BGR) 39 40 outputs.share_image('Out', output) 41 42 synchronise()
Block Description
Thresholds an Image
THis block reads the parameters LowerThreshold
and UpperThreshold
.
Based on these values it converts the input image form BGR
into GRAY
and applies the cv2.threshold()
function on it.
The image is then converted back into BGR
and shared to the output wire using the
share_image()
function.
Inputs: BGR Image
Outputs: BGR Image
Parameters: LowerThreshold, UpperThreshold