Last active
November 28, 2017 09:09
-
-
Save yoggy/66b7c42177cc80b69381e29f28813a51 to your computer and use it in GitHub Desktop.
OpenCVを使った画像の分割ツール。縦スクロール用
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
import numpy as np | |
import cv2 | |
import sys | |
import os | |
if (len(sys.argv)!=4): | |
print("usage : {0} step_h overlap_h filename".format(sys.argv[0])) | |
sys.exit() | |
step_h = int(sys.argv[1]) | |
overlap_h = int(sys.argv[2]) | |
filename = sys.argv[3] | |
basename, ext = os.path.splitext(filename) | |
print("step_h={0}, overlap_h={1}, filename={2}".format(step_h, overlap_h, filename)) | |
img = cv2.imread(filename) | |
(h, w) = img.shape[:2] | |
print("image w={0}, h={1}".format(w, h)) | |
count = 0 | |
y = 0 | |
while True: | |
roi = img[y:y+step_h, 0:w] | |
cv2.imshow(filename, roi) | |
c = cv2.waitKey(1) | |
if (c == 32): | |
save_filename = "{0}-{1}{2}".format(basename, count, ext) | |
print("save_filename={0}".format(save_filename)) | |
cv2.imwrite(save_filename, roi) | |
count += 1 | |
if (c == 106): | |
print("j") | |
y += 10 | |
if (y > h-step_h): | |
y = h-step_h | |
if (c == 107): | |
print("k") | |
y -= 10 | |
if (y < 0): | |
y = 0 | |
if (c == 27): | |
sys.exit() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment