<s> import cv2 <EOL> import numpy as np <EOL> def mix_image ( back , fore , ( x , y ) , in_place = False ) : <EOL> """<STR_LIT>""" <EOL> x , y = round ( x ) , round ( y ) <EOL> if in_place : <EOL> ret = back <EOL> else : <EOL> ret = back . copy ( ) <EOL> fh , fw , fd = fore . shape <EOL> bh , bw , bd = ret . shape <EOL> if fd == <NUM_LIT:4> : <EOL> fore_alpha = lambda fy , h , fx , w : fore [ fy : fy + h , fx : fx + w , <NUM_LIT:3> ] / <NUM_LIT> <EOL> else : <EOL> fore_alpha = lambda fy , h , fx , w : <NUM_LIT:1.0> <EOL> if True in [ x + fw < <NUM_LIT:0> , x > bw , y + fh < <NUM_LIT:0> , y > bh ] : <EOL> return ret <EOL> fx , fy = <NUM_LIT:0> , <NUM_LIT:0> <EOL> bx , by = x , y <EOL> w , h = fw , fh <EOL> if bx < <NUM_LIT:0> : <EOL> w = fw + bx <EOL> fx = - bx <EOL> bx = <NUM_LIT:0> <EOL> if by < <NUM_LIT:0> : <EOL> h = fh + by <EOL> fy = - by <EOL> by = <NUM_LIT:0> <EOL> if bx + w > bw : <EOL> w = bw - bx <EOL> if by + h > bh : <EOL> h = bh - by <EOL> for c in range ( <NUM_LIT:0> , <NUM_LIT:3> ) : <EOL> ret [ by : by + h , bx : bx + w , c ] = fore [ fy : fy + h , fx : fx + w , c ] * fore_alpha ( fy , h , fx , w ) + ret [ by : by + h , bx : bx + w , c ] * ( <NUM_LIT:1.0> - fore_alpha ( fy , h , fx , w ) ) <EOL> return ret <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> back = cv2 . imread ( "<STR_LIT>" ) <EOL> fore = cv2 . imread ( "<STR_LIT>" , - <NUM_LIT:1> ) <EOL> sh = fore . shape <EOL> b = np . full_like ( fore , <NUM_LIT:255> , np . uint8 ) <EOL> bb = mix_image ( b , fore , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> cv2 . imshow ( '<STR_LIT>' , bb ) <EOL> cv2 . imshow ( '<STR_LIT>' , back ) <EOL> from random import random as rdm <EOL> w , h , d = back . shape <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> back = mix_image ( back , fore , ( w * <NUM_LIT> * ( rdm ( ) - <NUM_LIT> ) , h * <NUM_LIT> * ( rdm ( ) - <NUM_LIT> ) ) ) <EOL> cv2 . imshow ( '<STR_LIT>' , back ) <EOL> cv2 . imwrite ( '<STR_LIT>' , back ) <EOL> cv2 . waitKey ( <NUM_LIT:0> ) </s>
