Improve text image process performance#31
Open
luiz-meireles wants to merge 2 commits intorodorgas:masterfrom
Open
Improve text image process performance#31luiz-meireles wants to merge 2 commits intorodorgas:masterfrom
luiz-meireles wants to merge 2 commits intorodorgas:masterfrom
Conversation
5d69d52 to
eb2551b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Para transformar um texto em imagem era necessário calcular o tamanho que a imagem que irá conter o texto, dessa forma o texto fica corretamente contido nela. No entanto, internamente a função que desenha o texto na imagem faz exatamente a mesma coisa, ou seja, o tempo para calcular as dimensões da imagem estava duplicado. Resolvi esse problema ao pegar a imagem (mask) que representava o texto e para desenhar, usei funções mais internas do pillow. Só isso reduziu quase pela metade o tempo gasto.
Outra melhoria foi baixar todos os emojis do https://github.com/twitter/twemoji e mapeá-los usando os códigos unicode correspondentes. Com isso ao invés de trabalhar com uma font, uma operação custosa, dado que isso é feito internamente, passamos a fazer isso de forma direta. Essa melhoria reduziu consideravelmente o tempo de execução do algoritmo.
Compactei todos os emojis no arquivo compressed_pngs.dat para não poluir o git/github, descompactando-os em runtime.
O tradeoff é mais velocidade em troca de mais memória.