Blocks.VideoStreamer
1import cv2 2import numpy as np 3 4def main(inputs, outputs, parameters, synchronise): 5 ''' 6 ## Streams Video from File 7 The filepath of your video is given in the `PathToFile` parameter. 8 *Note:* that this file path is relative to the `modules` folder of the final built application. 9 10 Capturing begins using the `cv2.VideoCapture()` function. 11 The video is then read frame by frame and each frame is shared to the output wire using the 12 `share_image()` function. 13 14 **Inputs**: None 15 16 **Outputs**: BGR Image 17 18 **Parameters**: PathToFile 19 ''' 20 filepath = parameters.read_string("PathToFile") 21 auto_enable = False 22 try: 23 enable = inputs.read_number("Enable") 24 except Exception: 25 auto_enable = True 26 27 cap = cv2.VideoCapture(filepath) 28 29 while(auto_enable or inputs.read_number('Enable') and cap.isOpened()): 30 ret, frame = cap.read() 31 if ret: 32 outputs.share_image('Out', frame) 33 else: 34 cap.set(cv2.CAP_PROP_POS_FRAMES, 0) 35 36 synchronise()
def
main(inputs, outputs, parameters, synchronise)
5def main(inputs, outputs, parameters, synchronise): 6 ''' 7 ## Streams Video from File 8 The filepath of your video is given in the `PathToFile` parameter. 9 *Note:* that this file path is relative to the `modules` folder of the final built application. 10 11 Capturing begins using the `cv2.VideoCapture()` function. 12 The video is then read frame by frame and each frame is shared to the output wire using the 13 `share_image()` function. 14 15 **Inputs**: None 16 17 **Outputs**: BGR Image 18 19 **Parameters**: PathToFile 20 ''' 21 filepath = parameters.read_string("PathToFile") 22 auto_enable = False 23 try: 24 enable = inputs.read_number("Enable") 25 except Exception: 26 auto_enable = True 27 28 cap = cv2.VideoCapture(filepath) 29 30 while(auto_enable or inputs.read_number('Enable') and cap.isOpened()): 31 ret, frame = cap.read() 32 if ret: 33 outputs.share_image('Out', frame) 34 else: 35 cap.set(cv2.CAP_PROP_POS_FRAMES, 0) 36 37 synchronise()
Block Description
Streams Video from File
The filepath of your video is given in the PathToFile
parameter.
Note: that this file path is relative to the modules
folder of the final built application.
Capturing begins using the cv2.VideoCapture()
function.
The video is then read frame by frame and each frame is shared to the output wire using the
share_image()
function.
Inputs: None
Outputs: BGR Image
Parameters: PathToFile