Created
September 30, 2016 06:16
-
-
Save macrat/6a0d4627c2aef577712636e2e573a79c 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
import math | |
import cv2 | |
import numpy | |
count = 0 | |
for i in range(12): | |
print('makeing {0}.mp4 background image'.format(i+1)) | |
video = cv2.VideoCapture('src/{0}.mp4'.format(i+1)) | |
background = numpy.array(video.read()[1], numpy.uint32) | |
frame_count = 1 | |
while True: | |
ok, img = video.read() | |
if not ok: | |
break | |
background += img | |
frame_count += 1 | |
background = numpy.array(background / frame_count, numpy.uint8) | |
video.release() | |
for x in range(0, background.shape[1]-128, 64): | |
for y in range(0, background.shape[0]-128, 64): | |
print(count) | |
cv2.imwrite('ng/{0}.jpg'.format(count), background[y:y+128, x:x+128]) | |
count += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment