2020-12-10 python

python numpy ones

그림에 텍스트 넣기

검색어 : python opencv text
참고 : https://www.geeksforgeeks.org/python-opencv-cv2-puttext-method/
참고2 : https://stackoverflow.com/questions/16615662/how-to-write-text-on-a-image-in-windows-using-python-opencv2
참고3 한글 - : http://www.gisdeveloper.co.kr/?p=8338

import numpy as np 
import cv2
from PIL import ImageFont, ImageDraw, Image

# Create a black image
original = cv2.imread('image/pengsu.png', cv2.IMREAD_COLOR)

b,g,r,a = 255,255,255,0
fontpath = "fonts/gulim.ttc"
font = ImageFont.truetype(fontpath, 20)
img_pil = Image.fromarray(original)
draw = ImageDraw.Draw(img_pil)
draw.text((60, 70),  "김형준ABC123#GISDeveloper", font=font, fill=(b,g,r,a))
original = np.array(img_pil)

#Display the image
cv2.imshow("img",original)

cv2.waitKey(0)
cv2.destroyAllWindows()

사진안에 사진 넣기
참고 : https://stackoverflow.com/questions/14063070/overlay-a-smaller-image-on-a-larger-image-python-opencv

import cv2

fname = "image/pengsu.png"
s_img = cv2.imread("image/h2.png")
x_offset=90
y_offset=160


original = cv2.imread(fname, cv2.IMREAD_COLOR)

y1, y2 = y_offset, y_offset + s_img.shape[0]
x1, x2 = x_offset, x_offset + s_img.shape[1]

alpha_s = s_img[:, :, 1] / 255.0
alpha_l = 1.0 - alpha_s

for c in range(0, 3):
    original[y1:y2, x1:x2, c] = (alpha_s * s_img[:, :, c] +
                              alpha_l * original[y1:y2, x1:x2, c])

cv2.imshow('Original', original)

cv2.waitKey(0)
cv2.destroyAllWindows()

동영상에 자막 넣기

좋은 웹페이지 즐겨찾기