Sep-30-2019, 08:03 AM
Hello all,
I was working on a project where I would separate the frames of an image using OpenCV using Argument Parser. It is something to do with the right way to pass argument parse variables as parameters for a function. This is what the error states.
Thank you so much,
Aditya
I was working on a project where I would separate the frames of an image using OpenCV using Argument Parser. It is something to do with the right way to pass argument parse variables as parameters for a function. This is what the error states.
File "video-frames.py", line 13 def extractFrames('args.input', 'args.output'): ^ SyntaxError: invalid syntaxBelow is my code:
import cv2 import os import argparse ap = argparse.ArgumentParser() ap.add_argument("-i", "--input", required=True, help="path to input video") ap.add_argument("-o", "--output", required=True, help="path to output directory") args = vars(ap.parse_args()) #Function to extract frames def extractFrames('args.input', 'args.output'): #directory path, where my video images will be stored #Capture vidoe from video file cap = cv2.VideoCapture(args["input"]) #Counter Variable count = 0 while (cap.isOpened()): # Capture frame-by-frame ret, frame = cap.read() if ret == True: print('Read %d frame: ' % count, ret) # save frame as JPEG file cv2.imwrite(os.path.join(args["output"], "frame{:d}.png".format(count)), frame) count += 1 else: break # When everything done, release the capture cap.release() cv2.destroyAllWindows() def main(): extractFrames(args["input"] , args["output"]) if __name__=="__main__": main()Any help in fixing this would be greatly appreciated.
Thank you so much,
Aditya