Help us understand the problem. What is going on with this article?

[python]gifの画像を合成してみた

Gifを一枚づつに分解すると、2枚目以降は差分しか保存されていないので、
「なら合成してしまおう」とpython3で合成するプログラムを書いてみました。

gif画像の分解にONOさんのブログのコード(opencv版)を使いました。

gif_combine.py
import os
import cv2

img0 = cv2.imread("screen_caps\\0.png",-1)

print(img.shape)

size = img.shape[:2]

#透過箇所(緑)か
def isGreen(color):
    if color[0]==0 and color[1]==255 and color[2]==0 and color[3]==255:
        return True
    return False


if not os.path.exists("Combine"):
    os.mkdir("combine")

for i in range(308):
    img = cv2.imread("screen_caps\\"+str(i)+".png",-1)
    for x in range(size[0]):
        for y in range(size[1]):
            mask = img[x,y,:]
            if not isGreen(mask):
                img0[x,y,:] = mask 
    print("save num:"+str(i))
    print(cv2.imwrite("combine\\gif"+str(i)+".png",img0))

約500*400のサイズでもそれなりに時間がかかったので、最適化のご指南いただけると幸いです。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away