def main(argv, prog=''): # Create an instance of the matting class mat = Matting() # Parse the command line arguments success, args, unprocessedArgv, msg = parseArguments(argv, mat, prog) if not success: print 'Error: Argument parsing: ', msg return success, unprocessedArgv # Initialize the variables for measuring timings t1 = t2 = t3 = t4 = 0 if args.matting: # Get the value of the openCV timer t1 = cv.getTickCount() # Call the routine that reads the images and stores them in # the appropriate data structure stored with the matting # instance # # Note: The images themselves are supposed to be private # variables. They should be acccessed using the # readImage(), writeImage(), useTriangulationResults() # methods of the matting class. The images are referenced # by their string descriptor for (fname, key) in [(args.backA[0], 'backA'), (args.backB[0], 'backB'), (args.compA[0], 'compA'), (args.compB[0], 'compB')]: success, msg = mat.readImage(fname, key) if not success: print 'Error: %s'%msg return success, unprocessedArgv # Get the value of the openCV timer t2 = cv.getTickCount() # Run the triangulation matting algorithm. The routine # returns a tuple whose first element is True iff the routine # was successfully executed and the second element is # an error message string (if the routine failed) print 'Triangulation matting...' success, text = mat.triangulationMatting() if not success: print 'Error: Triangulation matting routine failed: %s'%text return success, unprocessedArgv # Get the value of the openCV timer t3 = cv.getTickCount() # Call the routine that writes to disk images stored in a matting # instance. # Note: The images themselves are supposed to be private variables # They should be acccessed using the readImage(), writeImage() # and useTriangulationResults() methods of the matting class # The images are referenced by their string descriptor for (fname, key) in [(args.colOut[0], 'colOut'), (args.alphaOut[0], 'alphaOut')]: success, msg = mat.writeImage(fname, key) if not success: print msg print 'Error: Image %s cannot be written'%fname return success, unprocessedArgv # Get the value of the openCV timer t4 = cv.getTickCount() elif args.compositing: t1 = cv.getTickCount() # Call the routine that reads the images and stores them in # the appropriate data structure stored with the matting # instance # # Note: The images themselves are supposed to be private # variables. They should be acccessed using the # readImage(), writeImage(), useTriangulationResults() # methods of the matting class. The images are referenced # by their string descriptor for (fname, key) in [(args.colIn[0], 'colIn'), (args.alphaIn[0], 'alphaIn'), (args.backIn[0], 'backIn')]: success, msg = mat.readImage(fname, key) if not success: print 'Error: %s'%msg return success, unprocessedArgv print 'Compositing...' t2 = cv.getTickCount() # Run the compositing algorithm. The routine # returns a tuple whose first element is True iff the routine # was successfully executed and the second element is # an error message string (if the routine failed) success, text = mat.createComposite() if not success: print 'Error: %s'%text return success, unprocessedArgv t3 = cv.getTickCount() success, msg = mat.writeImage(args.compOut[0], 'compOut') if not success: print msg print 'Error: Image %s cannot be written'%fname return success, unprocessedArgv t4 = cv.getTickCount() print '----------------------------------\nTimings\n----------------------------------' print 'Reading: %g seconds'%((t2-t1)/cv.getTickFrequency()) print 'Processing: %g seconds'%((t3-t2)/cv.getTickFrequency()) print 'Writing: %g seconds'%((t4-t3)/cv.getTickFrequency()) # return any command-line arguments that were not processed return success, unprocessedArgv
def main(argv, prog=''): # Create an instance of the matting class mat = Matting() # Parse the command line arguments success, args, unprocessedArgv, msg = parseArguments(argv, mat, prog) if not success: print 'Error: Argument parsing: ', msg return success, unprocessedArgv # Initialize the variables for measuring timings t1 = t2 = t3 = t4 = 0 if args.matting: # Get the value of the openCV timer t1 = cv.getTickCount() # Call the routine that reads the images and stores them in # the appropriate data structure stored with the matting # instance # # Note: The images themselves are supposed to be private # variables. They should be acccessed using the # readImage(), writeImage(), useTriangulationResults() # methods of the matting class. The images are referenced # by their string descriptor for (fname, key) in [(args.backA[0], 'backA'), (args.backB[0], 'backB'), (args.compA[0], 'compA'), (args.compB[0], 'compB')]: success, msg = mat.readImage(fname, key) if not success: print 'Error: %s' % msg return success, unprocessedArgv # Get the value of the openCV timer t2 = cv.getTickCount() # Run the triangulation matting algorithm. The routine # returns a tuple whose first element is True iff the routine # was successfully executed and the second element is # an error message string (if the routine failed) print 'Triangulation matting...' success, text = mat.triangulationMatting() if not success: print 'Error: Triangulation matting routine failed: %s' % text return success, unprocessedArgv # Get the value of the openCV timer t3 = cv.getTickCount() # Call the routine that writes to disk images stored in a matting # instance. # Note: The images themselves are supposed to be private variables # They should be acccessed using the readImage(), writeImage() # and useTriangulationResults() methods of the matting class # The images are referenced by their string descriptor for (fname, key) in [(args.colOut[0], 'colOut'), (args.alphaOut[0], 'alphaOut')]: success, msg = mat.writeImage(fname, key) if not success: print msg print 'Error: Image %s cannot be written' % fname return success, unprocessedArgv # Get the value of the openCV timer t4 = cv.getTickCount() elif args.compositing: t1 = cv.getTickCount() # Call the routine that reads the images and stores them in # the appropriate data structure stored with the matting # instance # # Note: The images themselves are supposed to be private # variables. They should be acccessed using the # readImage(), writeImage(), useTriangulationResults() # methods of the matting class. The images are referenced # by their string descriptor for (fname, key) in [(args.colIn[0], 'colIn'), (args.alphaIn[0], 'alphaIn'), (args.backIn[0], 'backIn')]: success, msg = mat.readImage(fname, key) if not success: print 'Error: %s' % msg return success, unprocessedArgv print 'Compositing...' t2 = cv.getTickCount() # Run the compositing algorithm. The routine # returns a tuple whose first element is True iff the routine # was successfully executed and the second element is # an error message string (if the routine failed) success, text = mat.createComposite() if not success: print 'Error: %s' % text return success, unprocessedArgv t3 = cv.getTickCount() success, msg = mat.writeImage(args.compOut[0], 'compOut') if not success: print msg print 'Error: Image %s cannot be written' % fname return success, unprocessedArgv t4 = cv.getTickCount() print '----------------------------------\nTimings\n----------------------------------' print 'Reading: %g seconds' % ((t2 - t1) / cv.getTickFrequency()) print 'Processing: %g seconds' % ((t3 - t2) / cv.getTickFrequency()) print 'Writing: %g seconds' % ((t4 - t3) / cv.getTickFrequency()) # return any command-line arguments that were not processed return success, unprocessedArgv