1

Currently, I am trying to work on an automated chat handler for Minecraft, where I can take certain strings / words, and see how close they identify with a set of blacklisted words. Currently, I found the code to turn a string to an image, Convert text content to Image, however, I need to find out how to create a learning mechanism to identify words. So if the word "tèst" is typed, the program will recognize è as the character e, and substitute that letter in to form test, which will cancel the message. Currently, my code based on the previous provided link is as follows:

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class Scan {

    public Scan () {}

    public void scan (String text) {

        BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = img.createGraphics();
        Font font = new Font("Arial", Font.PLAIN, 48);
        g2d.setFont(font);
        FontMetrics fm = g2d.getFontMetrics();
        int width = fm.stringWidth(text);
        int height = fm.getHeight();
        g2d.dispose();

        img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        g2d = img.createGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
        g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
        g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
        g2d.setFont(font);
        fm = g2d.getFontMetrics();
        g2d.setColor(Color.BLACK);
        g2d.drawString(text, 0, fm.getAscent());
        g2d.dispose();
        try {
            ImageIO.write(img, "png", new File("TEMP_TEXT.png"));
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

Ideally, I would hope for something relatively quick, but even if its slow, it'd be nice to learn how to.

VeeAyeInIn
  • 193
  • 1
  • 12
  • Why do you actually need this, and why are you doing it from images? for instance, I believe you can convert `è` to `e` without doing it as an image – LeoColman Apr 14 '18 at 18:04
  • @Kerooker it was mostly in case users use a character that does not exist in the data, or is custom. – VeeAyeInIn Apr 14 '18 at 18:31
  • It's an interesting approach! However, your question is too broad for SO, and it also verges on a request to recommend a library, which is off topic. If you start using something like Tensorflow (their tutorial on recognition of handwritten digits might be relevant to you), and have a specific question about a problem you encounter with it, you could ask here. – erickson May 08 '18 at 15:11

1 Answers1

1

You should implement some Machine Learning to filter that. I recommend this : Google Tensorflow.

While Machine Learning might need steep learning curve, you can follow the tutorial at https://developers.google.com/machine-learning/crash-course/.