So resurrecting this thread and investigating @Andrew_Steel suggestion, opencv will do the job. The following python code saves every n
th image to a temp folder, having scaled it down. The scale factor, output format (png or jpg) and n
are determined by user inputs:
# Copy input to output
output_table_1 = input_table_1.copy()
import cv2
from io import BytesIO
imgCol = []
i = 0
for x in range(len(input_table_1['Path'])):
cap = cv2.VideoCapture(input_table_1['Path'][x])
images = []
while(cap.isOpened()):
ret, frame = cap.read()
if ret == False:
break
outPath = flow_variables['temp_dir_path_location']+"/" + input_table_1['outName'][x] + "_" + str(i) +"." + flow_variables['imgFormat']
i = i + 1
if i % flow_variables['nthFrame'] == 0:
newDim = (int(frame.shape[1] * flow_variables['thumbnailScale'] / 100), int(frame.shape[0] * flow_variables['thumbnailScale'] / 100))
frame = cv2.resize(frame, newDim, interpolation=cv2.INTER_AREA)
cv2.imwrite(outPath, frame)
images.append(outPath)
#is_success, buffer = cv2.imencode(".png", frame)
#io_buf = BytesIO(buffer)
#images = io_buf.getvalue()
imgCol.append(images)
output_table_1['frames']=imgCol
Notes:
- The commentated out code was me trying to write the blobs directly to the output table which KNIME can’t do yet!
- Apologies to the pythonistas out there who could probably make this much more elegant - I inhabit the java world by day and cobbled this together from various examples and looking up things that are probably elementary in python-speak
Thanks again,
Steve
PS - anyone want to flick through several thousand thumbnails to spot the interesting wildlife that the webcam caught in amidst the videos of blowing leaves, rain etc etc?!