Created
August 21, 2012 19:46
-
-
Save yuyay/3418684 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
# -*- coding:utf-8 -*- | |
import os | |
import cv2 | |
folderName = '' | |
outputFolder = '' | |
for files in os.listdir(folderName): | |
if files.find('illustName') != -1: | |
print files | |
img = cv2.imread(folderName + '/' + files) | |
#左側 | |
f = False | |
for col in range(img.shape[1]): | |
for row in range(10, img.shape[0] - 10): | |
R = img[row, col][2] | |
G = img[row, col][1] | |
B = img[row, col][0] | |
if 90 < R < 130 and 125 < G < 165 and 95 < B < 135: | |
leftSplitPoint = col | |
break | |
else: | |
continue | |
break | |
#右側 | |
f = False | |
for col in reversed(range(img.shape[1])): | |
for row in range(10, img.shape[0] - 10): | |
R = img[row, col][2] | |
G = img[row, col][1] | |
B = img[row, col][0] | |
if 90 < R < 130 and 125 < G < 165 and 95 < B < 135: | |
rightSplitPoint = col | |
break | |
else: | |
continue | |
break | |
#print leftSplitPoint | |
#print rightSplitPoint | |
cv2.imwrite(outputFolder + '/' + files, img[:,leftSplitPoint + 20:rightSplitPoint - 20]) | |
''' | |
cv2.namedWindow('sak') | |
cv2.imshow('sak', img[:,leftSplitPoint + 20:rightSplitPoint - 20]) | |
cv2.waitKey(0) | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment