skotz / cbl-js

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

Can you help resolve this #41

Open yassinevic opened 4 years ago

yassinevic commented 4 years ago

Its a five number captcha. this is where I get so far. var cbl = new CBL({ preprocess: function(img) { img.debugImage("debugPreprocessed"); img.binarize(32); img.debugImage("debugPreprocessed"); img.cropRelative(28, 2, 60, 2); img.debugImage("debugPreprocessed"); img.colorRegions(50, true, 0); }, character_set: "0123456789abcdefghijklmnopqrstuvwxyz", exact_characters_width: 50, exact_characters_play: 2, exact_characters: 5, blob_min_pixels: 10, blob_max_pixels: 10000, pattern_width: 30, pattern_height: 30, allow_console_log: true, blob_console_debug: true, blob_debug: "debugSegmented" });

    cbl.train("./sss/0.png");
    cbl.train("./sss/1.png");
    cbl.train("./sss/2.png");
    cbl.train("./sss/3.png");
    cbl.train("./sss/4.png");
    cbl.train("./sss/5.png");
    cbl.train("./sss/6.png");
    cbl.train("./sss/7.png");
    cbl.train("./sss/8.png");
    cbl.train("./sss/9.png");

0 1 2 3 4 5 6 7 8 9

Tnx a lot

skotz commented 4 years ago

Yeah, lines can be difficult to remove... I'd recommend playing around with convolution filters after the binarize step to see if you can filter away the horizontal lines. Maybe start with something like this.

img.convolute([ [-1,  4, -1],
                [-1,  2, -1],
                [-1,  4, -1] ], 1);

Other than that I'd probably have to extend the library with a method to specifically detect and remove horizontal lines.

skotz commented 4 years ago

I've added a new method to remove lines. It's experimental, so it might have some bugs, It's not perfect but it works decently.

image

var cbl = new CBL({
    preprocess: function(img) {
        img.debugImage("debugPreprocessed");
        img.cropRelative(20, 2, 20, 2);
        img.debugImage("debugPreprocessed");
        img.removeLight(16);
        img.debugImage("debugPreprocessed");
        img.removeHorizontalLine(2);
        img.debugImage("debugPreprocessed");
        img.colorRegions(50, true, 0);
        img.debugImage("debugPreprocessed");
    },
    character_set: "0123456789abcdefghijklmnopqrstuvwxyz",
    exact_characters_width: 18,
    exact_characters_play: 3,
    exact_characters: 5,
    blob_min_pixels: 50,
    blob_max_pixels: 10000,
    pattern_width: 30,
    pattern_height: 30,
    allow_console_log: true,
    blob_console_debug: true,
    perceptive_colorspace: true,
    blob_debug: "debugSegmented"
});