ทำไมฉันจะต้องรย้อนข้อความอยู่ตรภาพคือขอบ?

0

คำถาม

ฉันพยายามที่จะสร้างภาพกับขอบแทนที่ด้วยข้อความคล้ายกันที่ นี่คลิปในยูทูปแสดงภาพตัวอย่างขนาดเล็ก แต่งจากแหล่งข่าวภาพได้ที่นี่ ฉันเคย OpenCV ต้องได้เวอร์ชั่นของแหล่งข่าวภาพกับขอบและหมอนเพื่อที่จริงเขียนข้อความแต่ฉันไม่แน่ใจว่าจะเริ่มจากตรงไหนเมื่อมันมาพร้อมที่จะจริงกำลังหลอกข้อความโดยอัตโนมัติจะพอดีกับคนขอบ. รหัสฉันต้องตอนนี้คือ:

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 ขอบผมก็อาจจะสนใจอาชีพสืบส.

อย่างไรก็ตามที่แบบวงกลมข้อความห่อสามารถทำได้มากแค่ภาษาไพธอน/ตรวจค้นที่ใช้ ImageMagick. หรือหนึ่งสามารถทำอย่างนั้นภาษาไพธอน/OpenCV ใช้ cv2.remap และกำหนดการเปลี่ยแปลงครั้งแผนที่อยู่

นำเข้าข้อมูล:

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. ปลั๊กอินสำหรับไพธอน/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 หรือพิลมีทางให้ทำอย่างนั้นแต่คุณสามารถใช้ ImageMagick. วิธีการย้อนภาพที่จะเอารูปร่างของเส้นทางกับเป็นภาษาไพธอน?

2021-11-24 23:52:41

มีบางอย่างมาช่วยข้อมูลของ ImageMagick distortions อยู่ที่นี่... legacy.imagemagick.org/Usage/distorts/#circular_distorts แล้วก็โน้ตนั่น wand เป็นภาษาไพธอน wrapper อยู่ 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ý
..................................................................................................................

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่