我怎么会经文字图像周围的边缘?

0

的问题

我试图创建一个图像与边缘替换为文本,类似于 这个Youtube视频略 ,但从来源的图像。 我使用了开源,以获得一个版本的一个来源的图像带的边缘,并且枕头到实际编写的文字,但我不知道该从哪里开始的,当涉及到实际操作该案文自动适合的边缘。 代码是我迄今为:

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

我不知道这里的"边缘"从canny边缘探测器。

然而,圆形的文本包装可以做得非常简单Python/魔杖使用ImageMagick. 或者一个可以这样做,在Python/开源使用cv2.重和定义转化地图。

输入:

enter image description here

1. 蟒蛇魔杖

(输出大小确定的自动输入的大小)

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. 蟒蛇/开源

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

既没有开源也太平船务有办法做到这一点,但是可以使用ImageMagick. 如何扭曲的图像形的路径与蟒蛇?

2021-11-24 23:52:41

有一些非常有用的信息 ImageMagick 扭曲,在这里... legacy.imagemagick.org/Usage/distorts/#circular_distorts 此外,请注意 wand 是蟒蛇的包装 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ý
..................................................................................................................