从位图字体图像中提取字形数据的工具
我拥有以 PNG 呈现的字体的所有字符。我想在 OpenGL 中使用 PNG 进行纹理映射字体渲染,但我需要提取字形信息 - 字符位置和大小等。
是否有任何工具可以帮助完成该过程?我看到的大多数工具都会一起生成图像文件和字形数据。我还没有找到任何可以帮助我从现有图像中提取内容的内容。
我使用 gimp 作为我的主要图像编辑器,并且我考虑编写一个插件来帮助我识别每个字符的边界框。我了解 python,但之前没有做过任何 gimp 插件,所以这将是一件苦差事。我希望有些东西已经存在...
I have all the characters of a font rendered in a PNG. I want to use the PNG for texture-mapped font rendering in OpenGL, but I need to extract the glyph information - character position and size, etc.
Are there any tools out there to assist in that process? Most tools I see generate the image file and glyph data together. I haven't found anything to help me extract from an existing image.
I use the gimp as my primary image editor, and I've considered writing a plugin to assist me in the process of identifying the bounding box for each character. I know python but haven't done any gimp plugins before, so that would be a chore. I'm hoping something already exists...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,其工作方式是使用工具来生成字形图像。该工具还将生成这些字形的度量信息(它们有多大等)。您不应该分析图像来查找字形;你应该在你的字形旁边有额外的信息,告诉它们在哪里,它们应该有多大等等。
考虑字母“i”。根据字体的不同,它的左侧和右侧会有一些空格。即使您有一个可以识别字形“i”的工具,您也需要知道字体在字形的左侧和右侧放置了多少像素的空间。对所有字母都准确地做到这一点几乎是不可能的。并非没有一些非常先进的计算机视觉算法。由于生成这些字形的工具已经知道它们应该获得多少间距,因此您最好也更改该工具来写入字形信息。
Generally, the way this works is you use a tool to generate the glyph images. That tool will also generate metric information for those glyphs (how big they are, etc). You shouldn't be analyzing the image to find the glyphs; you should have additional information alongside your glyphs that tell where they are, how big they should be, etc.
Consider the letter "i". Depending on the font, there will be some space to the left and right of it. Even if you have a tool that can identify the glyph "i", you would need to know how many pixels of space the font put to the left and right of the glyph. This is pretty much impossible to do accurately for all letters. Not without some very advanced computer vision algorithms. And since the tool that generated those glyphs already knew how much spacing they were supposed to get, you would be better off changing the tool to write the glyph info as well.
您可以使用 PIL 来帮助您自动化该过程。
假设至少有一行/列背景颜色分隔线/字符,您可以使用
Image.crop
方法来检查每一行(然后是每一列) row) 如果它只包含背景颜色;这样你就得到了每个字符的边界。如果您需要进一步帮助,请 Ping。
You can use PIL to help you automate the process.
Assuming there is at least one row/column of background colour separating lines/characters, you can use the
Image.crop
method to check each row (and then each column of the row) if it contains only the background colour; thus you get the borders of each character.Ping if you need further assistance.