skotz / cbl-js

JavaScript CAPTCHA solving library
MIT License
155 stars 47 forks source link

How to solve this captcha? #34

Open avinashsonee opened 5 years ago

avinashsonee commented 5 years ago

D9QQ8U H6E7V2 6HYFHM 76US7T

I tried with this

var cbl = new CBL({
            preprocess: function(img) {
                img.binarize(150);
                img.debugImage("debugPreprocessed");
                img.blur();
                img.debugImage("debugPreprocessed");
                img.binarize(50);
                img.debugImage("debugPreprocessed");
                img.colorRegions(50,true, 1);
                img.debugImage("debugPreprocessed");
            },
            /* The set of characters that could potentially be in this CAPTCHA system. */
            character_set: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
            /* The minimum number of pixels required to call a grouping of similar pixels a blob. Use this to filter out small specks before segmentation. */
            blob_min_pixels: 100,
            /* The maximum number of pixels required to call a grouping of similar pixels a blob. */
            blob_max_pixels: 400,
            /* The width of the extracted blobs. All patterns are normalized to this width. */
            pattern_width: 25,
            /* The height of the extracted blobs. All patterns are normalized to this height. */
            pattern_height: 25,
            /* Enable advanced logging in the browser's console. */
            allow_console_log: true,
            /* Compare the differences between colors using algorithms based on how the human eye perceives color (instead of just an RGB comparison). */
            perceptive_colorspace: true,
            /* The ID of the element to output all work-in-progress images of segmented characters from each image. */
            blob_debug: "debugSegmented"
        });
skotz commented 5 years ago

You're pretty much there. I'd start with a cropRelative to remove the border, and then make sure you don't merge the patterns before generating your model. The method used here for recognition isn't very good against rotation, but you can make it work if you supply enough sample data. Basically instead of one pattern to represent a given character you're saving multiple: one for each general rotation.

This seems to work well:

var cbl = new CBL({
    preprocess: function(img) {
        img.cropRelative(2, 2, 2, 2);
        img.debugImage("debugPreprocessed");
        img.binarize(120);
        img.debugImage("debugPreprocessed");
        img.blur();
        img.debugImage("debugPreprocessed");
        img.binarize(50);
        img.debugImage("debugPreprocessed");
        img.colorRegions(50, true, 1);
        img.debugImage("debugPreprocessed");
    },
    character_set: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
    pattern_width: 25,
    pattern_height: 25,
    blob_min_pixels: 10,
    blob_max_pixels: 250,
    allow_console_log: true,
    blob_console_debug: true,
    perceptive_colorspace: true,
    blob_debug: "debugSegmented"
});

cbl.train("6HYFHM.png");
cbl.train("76US7T.png");
cbl.train("D9QQ8U.png");
cbl.train("H6E7V2.png");

var saveModel = function() {
    // cbl.condenseModel(); // don't do this since the letters vary in rotation
    cbl.sortModel();
    cbl.visualizeModel("visualizeModel");
    cbl.saveModel();
}

image

avinashsonee commented 5 years ago

Thanks Scott 👍 I tried with couple more training data but the results are not accurate yet. Will try with a more number of training set and hopefully that should solve the problem along with some more tweaking.