어떻게 warp 텍스트 주위에 이미지의 가장자리가?

0

질문

나가고 이미지를 만들과 함께 가장자리로 대체 텍스트와 비슷한 이 유튜브 동영상 미리보기 에서 있지만이 소스 이미지입니다. 사용했 의 버전을 다운로드하려면 소스 이미지의 가장자리,베를 실제로 쓰기 텍스트,하지만 어디를 시작할 때 실제로 오는 텍스트를 조작하에 맞게 자동으로 가장자리에. 코드는 지금까지입니다:

import cv2 as cv
from matplotlib import pyplot as plt
from PIL import Image, ImageFont, ImageDraw, ImageShow

font = ImageFont.truetype(r"C:\Users\X\Downloads\Montserrat\Montserrat-Light.ttf", 12)
text = ["text", "other text"]

img = cv.imread(r"C:\Users\X\Pictures\picture.jpg",0)
edges = cv.Canny(img,100,200)

img = cv.cvtColor(img, cv.COLOR_BGR2RGB)
im_pil = Image.fromarray(edges)

이 코드는 그냥하는 가장자리를 탐지하고 움직이는 검출한 가장자리에 베개가 있습니다.

도와주세요

image opencv python
2021-11-24 03:40:23
2

최고의 응답

1

나는"가"에서 영 edge 탐지기입니다.

그러나,원형 텍스트를 포장 할 수 있는 아주 간단하게 파이썬/지팡이 사용하는 ImageMagick. 또 하나를 할 수 있는 파이썬/OpenCV 를 사용하여 cv2.매핑하고 사용자 지정 변환 maps.

입력:

enter image description here

1. Python 지팡이

(출력 크기에 따라 자동으로 결정됩 입력 크기)

from wand.image import Image
from wand.font import Font
from wand.display import display

with Image(filename='some_text.png') as img:
    img.background_color = 'white'
    img.virtual_pixel = 'white'
    # 360 degree arc, rotated 0 degrees
    img.distort('arc', (360,0))
    img.save(filename='some_text_arc.png')
    img.format = 'png'
    display(img)

결과:

enter image description here

2. Python/OpenCV

import numpy as np
import cv2
import math

# read input
img = cv2.imread("some_text.png")
hin, win = img.shape[:2]
win2 = win / 2

# specify desired square output dimensions and center
hout = 100
wout = 100
xcent = wout / 2
ycent = hout / 2
hwout = max(hout,wout)
hwout2 = hwout / 2

# set up the x and y maps as float32
map_x = np.zeros((hout, wout), np.float32)
map_y = np.zeros((hout, wout), np.float32)

# create map with the arc distortion formula --- angle and radius
for y in range(hout):
    Y = (y - ycent)
    for x in range(wout):
        X = (x - xcent)
        XX = (math.atan2(Y,X)+math.pi/2)/(2*math.pi)
        XX = XX - int(XX+0.5)
        XX = XX * win + win2
        map_x[y, x] = XX
        map_y[y, x] = hwout2 - math.hypot(X,Y)

# do the remap  this is where the magic happens
result = cv2.remap(img, map_x, map_y, cv2.INTER_CUBIC, borderMode = cv2.BORDER_CONSTANT, borderValue=(255,255,255))

# save results
cv2.imwrite("some_text_arc.jpg", result)

# display images
cv2.imshow('img', img)
cv2.imshow('result', result)
cv2.waitKey(0)
cv2.destroyAllWindows()

결과:

enter image description here

2021-11-24 23:59:34
0

도 OpenCV 도 PIL 가를 할 수 있는 방법을 사용할 수 있지만 ImageMagick. 하는 방법 warp 이미지 형태의 경로는 파이썬?

2021-11-24 23:52:41

거기에 몇 가지 아주 유용한 정보에 ImageMagick 왜곡은 여기... legacy.imagemagick.org/Usage/distorts/#circular_distorts 또한,note wand Python 래퍼 ImageMagick docs.wand-py.org/en/0.6.7
Mark Setchell

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................