print __doc__ cvparam_dict = {} cvparam_dict["threshold"] = cvparams.sliderparam("Threshold", 500, 50, updateImage) cvparam_dict["minLength"] = cvparams.sliderparam("Min Length", 500, 100, updateImage) cvparam_dict["maxGapLength"] = cvparams.sliderparam("Max Gap", 500, 20, updateImage) import argparse parser = argparse.ArgumentParser(description="Interactively experiment with HoughLinesP parameters.") parser.add_argument("file", help="image to threshold", type=str) # add a command line parameter for every slider parameter cvparams.addCommandLineArgs(cvparam_dict, parser) args = parser.parse_args() cvparams.setValuesFromCommandLine(cvparam_dict, args) from glob import glob for filename in glob(args.file): img = get_image(filename) h, w = img.shape[:2] img = cv2.GaussianBlur(img, (5, 5), 0) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) edges = cv2.Canny(gray, 600, 600, apertureSize=5) cv2.imshow("results", img) # window needs to exist before we add sliders cvparams.addSlidersToWindow(cvparam_dict, "results") updateImage() ch = cv2.waitKey()
cvparam_dict['filterSize'] = cvparams.kernelparam("Filter Size", 100, 11, updateImage) cvparam_dict['spaceKernelSize'] = cvparams.kernelparam( "Space Kernel Size", 150, 109, updateImage) cvparam_dict['colorKernelSize'] = cvparams.kernelparam( "Color Kernel Size", 150, 109, updateImage) import argparse parser = argparse.ArgumentParser( description="Apply bilateral (edge preserving) blur operator.") parser.add_argument('file', help='image to blur (wildcards ok)', type=str) # add a command line parameter for every slider parameter cvparams.addCommandLineArgs(cvparam_dict, parser) args = parser.parse_args() cvparams.setValuesFromCommandLine(cvparam_dict, args) from glob import glob for filename in glob(args.file): img = cv2.imread(filename) assert img is not None, "File " + args.file + " was not found." h, w = img.shape[:2] cv2.imshow('results', img) # window needs to exist before we add sliders cvparams.addSlidersToWindow(cvparam_dict, "results") updateImage() ch = cv2.waitKey() if ch == 27: break