skotz / cbl-js

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

How I can resolve this captcha? #38

Open bearwmceo opened 4 years ago

bearwmceo commented 4 years ago

Hi, I tried to resolve this captcha but without success, I hope someone can help me. image image image image image image

var cbl = new CBL({
            /* Define a method that takes an input CAPTCHA and performs a set of image operations to remove noise. */
            preprocess: function(img) {
                // Each pixel lighter than the grayscale threshold of 220 is turned white and everything darker is turned black.
                img.binarize(220);

                // Output the work-in-progress image to an element with a specific ID so we can see the effect of our image operations.
                img.debugImage("debugPreprocessed");

                // Flood-fill every blob (a grouping of similarly colored pixels) with a unique color. 
                // This is an important last step of the segmentation phase since the segmenter will create a separate character
                // image for each unique color in the image. If all the characters are black then the segmenter will only find one character.
                img.colorRegions(1, true);

                // Once again output the image to a div or something so we see the effect of colorization.
                img.debugImage("debugPreprocessed");
            },
            /* The set of characters that could potentially be in this CAPTCHA system. */
            character_set: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz",
            /* 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: 140,
            /* The maximum number of pixels required to call a grouping of similar pixels a blob. */
            blob_max_pixels: 700,
            /* 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 4 years ago

The third parameter of the colorRegions method will help keep letters together when they're made up of separate lines which aren't touching, and the exact_characters setting can be used whenever a CAPTCHA system always has exactly the same number of characters.

These settings seem to work well.

var cbl = new CBL({
    preprocess: function(img) {
        img.debugImage("debugPreprocessed");
        img.binarize(200);
        img.debugImage("debugPreprocessed");
        img.colorRegions(50, true, 3);
        img.debugImage("debugPreprocessed");
    },
    character_set: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
    exact_characters: 5,
    pattern_width: 25,
    pattern_height: 25,
    blob_min_pixels: 10,
    blob_max_pixels: 1000,
    allow_console_log: true,
    blob_console_debug: true,
    perceptive_colorspace: true,
    blob_debug: "debugSegmented"
});

cbl.train("3jrH5.png");
cbl.train("bHaGR.png");
cbl.train("GCXKa.png");
cbl.train("gSBTt.png");
cbl.train("mXTtA.png");
cbl.train("PWRSX.png");

var saveModel = function() {
    cbl.condenseModel();
    cbl.sortModel();
    cbl.visualizeModel("visualizeModel");
    cbl.saveModel();
}

image

bearwmceo commented 4 years ago

Captchas.zip I tried with this captchas but It's not working always

skotz commented 4 years ago

Did you train a model? What's your solver look like? You can check out the quick start for help in getting started.

I ran through the training for the images above and generated this model:

image

You may want to train on more samples or play around with the segmentation settings, but it performs decently.

image

<div class="main">
    <img id="captcha" src="mXTtA.png" />
    <br />
    <input type="text" id="solution">
    <br />
    <a href="javascript: void(0)" id="solve" onclick="solve()" style="display: none">Solve!</a>
</div>
<script>
    var cbl = new CBL({
        preprocess: function(img) {
            img.binarize(200);
            img.colorRegions(50, true, 3);
        },
        /* Load the model we saved during training. */
        model_file: "condensed-30.txt",
        character_set: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
        exact_characters: 5,
        pattern_width: 25,
        pattern_height: 25,
        blob_min_pixels: 10,
        blob_max_pixels: 1000,
        //allow_console_log: true,
        //blob_console_debug: true,
        perceptive_colorspace: true,
        //blob_debug: "debugSegmented",
        /* Define a method that fires immediately after successfully loading a saved model. */
        model_loaded: function() {
            // Don't enable the solve button until the model is loaded.
            document.getElementById('solve').style.display = "block";
        }
    });    

    var solve = function() {
        // Using the saved model, attempt to find a solution to a specific image.
        cbl.solve("captcha").done(function (solution) {
            // Upon finding a solution, fill the solution textbox with the answer.
            document.getElementById('solution').value = solution;
        });
    }
</script>

condensed-30.txt