Created
October 12, 2017 22:40
-
-
Save awentzonline/040e4037c2ad5488b84b0b94be041760 to your computer and use it in GitHub Desktop.
A python script to extract edges from a glob of images.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """Extract edges from a glob of files.""" | |
| import argparse | |
| import glob | |
| import os | |
| import cv2 | |
| def main(config): | |
| for filename in glob.glob(config.source_glob): | |
| img = cv2.imread(filename, 0) | |
| edges = cv2.Canny(img, config.t1, config.t2) | |
| out_filename = os.path.join( | |
| config.destination, os.path.basename(filename)) | |
| cv2.imwrite(out_filename, edges) | |
| print('{} -> {}'.format(filename, out_filename)) | |
| if __name__ == '__main__': | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('source_glob') | |
| parser.add_argument('destination') | |
| parser.add_argument('--t1', default=60, help='Threshold 1') | |
| parser.add_argument('--t2', default=60, help='Threshold 2') | |
| config = parser.parse_args() | |
| main(config) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment