Created
May 1, 2019 13:08
-
-
Save campanalbero/b941a32ca6d6740c7dea6477d610fb30 to your computer and use it in GitHub Desktop.
diff.py create sequencial symlink, but some of pictures are skipped by diff value.
This file contains 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/python | |
import cv2 | |
import glob | |
import numpy as np | |
import os | |
import sys | |
""" | |
2019-02-18 | |
calc diff compared with next jpg. | |
create symlinks with sequential names under ~/workspace/ | |
the end of PATH directory should be HH, /00/ - /23/ | |
every HH should have 3600 pictures. | |
pictures that are over 3600, will be skipped to create sequential symlinks. | |
e.g. | |
if 3602 pictures exist, diff.py make 2 groups. | |
diff.py find the smallest diff image and makes sequencial symlinks excluding the pic. | |
usage: python diff.py PATH | |
""" | |
# e.g. '/home/suzuki/2018-06-21/original/13/' | |
PATH = os.path.abspath(sys.argv[-1]) | |
files = sorted(glob.glob(PATH + '*.jpg')) | |
count = 0 | |
minimum = 1920 * 1080 * 255 | |
print(PATH + 'mask.png') | |
mask = cv2.imread('mask.png', cv2.IMREAD_GRAYSCALE) | |
curr = cv2.imread(files[-1], cv2.IMREAD_GRAYSCALE) * mask | |
# TODO if-condition 3600 | |
group_num = 3600 / (len(files) - 3600) | |
skipped = set() | |
print("path, diff value compared with prev img") | |
# find the smallest different image every group_num images | |
path = "" | |
for f in files: | |
prev = curr | |
curr = cv2.imread(f, cv2.IMREAD_GRAYSCALE) * mask | |
diff = cv2.absdiff(prev, curr) | |
diff_sum = diff.sum() | |
print(f + ', ' + str(diff_sum)) | |
if minimum > diff_sum: | |
minimum = diff_sum | |
path = f | |
count = count + 1 | |
if count > group_num: | |
skipped.add(path) | |
minimum = 1920 * 1080 * 255 | |
count = 0 | |
print("skipped items: " + str(skipped)) | |
# CHANGE this | |
count = int(PATH.split("/")[-2]) * 3600 | |
for f in files: | |
if f not in skipped: | |
os.symlink(f, "~/workspace/" + str('{0:05d}'.format(count)) + ".jpg") | |
count = count + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment