• <tfoot id='VkOFh'></tfoot>
    • <bdo id='VkOFh'></bdo><ul id='VkOFh'></ul>

    1. <i id='VkOFh'><tr id='VkOFh'><dt id='VkOFh'><q id='VkOFh'><span id='VkOFh'><b id='VkOFh'><form id='VkOFh'><ins id='VkOFh'></ins><ul id='VkOFh'></ul><sub id='VkOFh'></sub></form><legend id='VkOFh'></legend><bdo id='VkOFh'><pre id='VkOFh'><center id='VkOFh'></center></pre></bdo></b><th id='VkOFh'></th></span></q></dt></tr></i><div id='VkOFh'><tfoot id='VkOFh'></tfoot><dl id='VkOFh'><fieldset id='VkOFh'></fieldset></dl></div>

      <small id='VkOFh'></small><noframes id='VkOFh'>

        <legend id='VkOFh'><style id='VkOFh'><dir id='VkOFh'><q id='VkOFh'></q></dir></style></legend>

        在 Python 中以角度(旋转)绘制文本

        时间:2023-07-03
        <i id='xU8HF'><tr id='xU8HF'><dt id='xU8HF'><q id='xU8HF'><span id='xU8HF'><b id='xU8HF'><form id='xU8HF'><ins id='xU8HF'></ins><ul id='xU8HF'></ul><sub id='xU8HF'></sub></form><legend id='xU8HF'></legend><bdo id='xU8HF'><pre id='xU8HF'><center id='xU8HF'></center></pre></bdo></b><th id='xU8HF'></th></span></q></dt></tr></i><div id='xU8HF'><tfoot id='xU8HF'></tfoot><dl id='xU8HF'><fieldset id='xU8HF'></fieldset></dl></div>
              <tbody id='xU8HF'></tbody>
            <tfoot id='xU8HF'></tfoot>
            <legend id='xU8HF'><style id='xU8HF'><dir id='xU8HF'><q id='xU8HF'></q></dir></style></legend>

                <bdo id='xU8HF'></bdo><ul id='xU8HF'></ul>

                  <small id='xU8HF'></small><noframes id='xU8HF'>

                • 本文介绍了在 Python 中以角度(旋转)绘制文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 Python 中的

                  I am drawing text onto a numpy array image in Python (using a custom font). Currently I am converting the image to PIL, drawing the text and then converting back to a numpy array.

                  import numpy as np
                  import cv2
                  
                  from PIL import Image
                  from PIL import ImageDraw
                  from PIL import ImageFont
                  
                  char_image = np.zeros((200, 300, 3), np.uint8)
                  
                  # convert to pillow image
                  pillowImage = Image.fromarray(char_image)
                  draw = ImageDraw.Draw(pillowImage)
                  
                  # add chars to image
                  font = ImageFont.truetype("arial.ttf", 32)
                  draw.text((50, 50), 'ABC', (255, 255, 255), font=font)
                  
                  # convert back to numpy array
                  char_image = np.array(pillowImage, np.uint8)
                  
                  # show image on screen
                  cv2.imshow('myImage', char_image)
                  cv2.waitKey(0)
                  

                  Is there anyway to draw the text on a given angle, ie. 33 degrees?

                  Rotating the image once the text has been drawn is not an option

                  解决方案

                  Using matplotlib, first visualize array and draw on it, get the raw data from the figure back. Pro: both tools are quite high level and let you deal with many details of the process. ax.annotate() offers flexibility for where and how to draw and set font properties, and plt.matshow() offers flexibility that lets you deal with aspects of array visualization.

                  import matplotlib.pyplot as plt
                  import scipy as sp
                  
                  # make Data array to draw in
                  M = sp.zeros((500,500))
                  
                  dpi = 300.0
                  
                  # create a frameless mpl figure
                  fig, axes = plt.subplots(figsize=(M.shape[0]/dpi,M.shape[1]/dpi),dpi=dpi)
                  axes.axis('off')
                  fig.subplots_adjust(bottom=0,top=1.0,left=0,right=1)
                  axes.matshow(M,cmap='gray')
                  
                  # set custom font
                  import matplotlib.font_manager as fm
                  ttf_fname = '/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-B.ttf'
                  prop = fm.FontProperties(fname=ttf_fname)
                  
                  # annotate something
                  axes.annotate('ABC',xy=(250,250),rotation=45,fontproperties=prop,color='white')
                  
                  # get fig image data and read it back to numpy array
                  fig.canvas.draw()
                  w,h = fig.canvas.get_width_height()
                  Imvals = sp.fromstring(fig.canvas.tostring_rgb(),dtype='uint8')
                  ImArray = Imvals.reshape((w,h,3))
                  

                  这篇关于在 Python 中以角度(旋转)绘制文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何找到对象(形状)的方向?- Python Opencv 下一篇:遍历图像目录并将它们全部旋转 x 度并保存到目录

                  相关文章

                  <i id='bpW5R'><tr id='bpW5R'><dt id='bpW5R'><q id='bpW5R'><span id='bpW5R'><b id='bpW5R'><form id='bpW5R'><ins id='bpW5R'></ins><ul id='bpW5R'></ul><sub id='bpW5R'></sub></form><legend id='bpW5R'></legend><bdo id='bpW5R'><pre id='bpW5R'><center id='bpW5R'></center></pre></bdo></b><th id='bpW5R'></th></span></q></dt></tr></i><div id='bpW5R'><tfoot id='bpW5R'></tfoot><dl id='bpW5R'><fieldset id='bpW5R'></fieldset></dl></div>

                    <small id='bpW5R'></small><noframes id='bpW5R'>

                    <legend id='bpW5R'><style id='bpW5R'><dir id='bpW5R'><q id='bpW5R'></q></dir></style></legend>
                    1. <tfoot id='bpW5R'></tfoot>
                      • <bdo id='bpW5R'></bdo><ul id='bpW5R'></ul>