comixify/comic_layout/comic_layout.py
Maciej Pęśko 1e5252b8f0
Add comix gan (#16)
* Add ComixGAN #1

* Add minor fixes

* Reduce batch size

* Fix concatenate bug

* Fix GPU memory not released problem #2

* Build client

* Fix style_transfer_mode bug

* Improve timings

* Add minor fix with GPU name

* Fix tf session problem

* Compile frontend

* Change parameters

* Fix occasional  yt Error
2018-11-10 22:45:55 +01:00

33 lines
1.1 KiB
Python

import cv2
import numpy as np
from utils import profile
class LayoutGenerator():
@classmethod
@profile
def get_layout(cls, frames):
result_imgs = cls._pad_images(frames)
first_row = np.hstack(result_imgs[:2])
second_row = np.hstack(result_imgs[2:5])
third_row = np.hstack(result_imgs[5:7])
fourth_row = np.hstack(result_imgs[7:10])
second_row = cv2.resize(second_row,
(first_row.shape[1],
(second_row.shape[0] * first_row.shape[1]) // second_row.shape[1]))
fourth_row = cv2.resize(fourth_row,
(first_row.shape[1],
(fourth_row.shape[0] * first_row.shape[1]) // fourth_row.shape[1]))
return np.vstack([first_row, second_row, third_row, fourth_row])
@staticmethod
def _pad_images(frames):
padded_result_imgs = []
for img in frames:
padded_img = cv2.copyMakeBorder(img, 5, 5, 5, 5, cv2.BORDER_CONSTANT, value=(255, 255, 255))
padded_result_imgs.append(padded_img)
return padded_result_imgs