Created
December 17, 2023 10:02
-
-
Save hirocarma/09cfe0f69028368d6eba86055ae32223 to your computer and use it in GitHub Desktop.
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 | |
| import os | |
| import sys | |
| import shutil | |
| import numpy as np | |
| import cv2 | |
| def main(): | |
| IMG_DIR = sys.argv[1] | |
| OUT_DIR = sys.argv[2] | |
| if os.path.exists(OUT_DIR): | |
| shutil.rmtree(OUT_DIR) | |
| os.mkdir(OUT_DIR) | |
| files = os.listdir(IMG_DIR) | |
| files = sorted(files) | |
| img_file = IMG_DIR + '/'+ files[0] | |
| prev_img = cv2.imread(img_file) | |
| for file in files: | |
| img_file = IMG_DIR + '/'+ file | |
| fname = file.split('.')[0] | |
| img = cv2.imread(img_file) | |
| if not np.array_equal(prev_img, img): | |
| diff_cnt = np.count_nonzero(img != prev_img) | |
| if diff_cnt > img.size / 12: | |
| cv2.imwrite(OUT_DIR + fname + '-sel' + '.jpg',img) | |
| prev_img = img.copy() | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment