LoginSignup
2
10

More than 3 years have passed since last update.

2枚の画像から中間画像を生成する

Last updated at Posted at 2019-07-11

はじめに

2枚の画像から中間画像をさくっと生成したかったので opencv を使って書いてみました。
メモ程度の内容ですが誰かの参考になればと思います。

ソースコード

generator.py
#coding:utf-8
import numpy
import cv2

split = 10
imgStart = cv2.imread("start.jpg")
imgEnd = cv2.imread("end.jpg")

# 0.0~1.0
imgStart = (imgStart / 255)
imgEnd = (imgEnd / 255)

calc = split - 1
for i in range(split):
    imgTmp = (imgStart / calc * (calc - i)) + (imgEnd / calc * i)
    imgRes = cv2.resize(imgTmp,(640, 480))

    cv2.imshow("color", imgRes)
    cv2.imwrite(str(i) + ".jpg", imgTmp * 255)
    cv2.waitKey(10)

cv2.waitKey(0)
cv2.destroyAllWindows()

実行結果

実行前

generator.py / start.jpg / end.jpg の3ファイルがある状態で実行します。

image.png

コマンド

python generator.py

実行後

0.jpg ~ 9.jpg の計10枚の画像が出力されました。

image.png

終わりに

よければ ブログ「Unity+AssetStoreおすすめ情報」の方にも色々記載しているのでぜひご参照いただければと思います。

2
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
10