Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to solve this captcha? #21

Closed
paulebe opened this issue Jun 11, 2018 · 15 comments
Closed

how to solve this captcha? #21

paulebe opened this issue Jun 11, 2018 · 15 comments

Comments

@paulebe
Copy link

paulebe commented Jun 11, 2018

hello, i have a harder challange, how would i use the library to presegment and actually solve thiscaptcha?
1nkm4j
3wj671
730cr1

img.debugImage("debugPreprocessed");
img.binarize(190);

@skotz
Copy link
Owner

skotz commented Jun 12, 2018

I'd start by filtering out the horizontal line with a convolution filter that basically smears things vertically.

var cbl = new CBL({
    preprocess: function(img) {
        img.debugImage("debugPreprocessed");
        img.convolute([ [0, 1, 0],
                        [0, 1, 0],
                        [0, 0, 0] ]);
        img.debugImage("debugPreprocessed");
        img.colorRegions(2, false);
        img.debugImage("debugPreprocessed");
    },
    character_set: "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
    blob_min_pixels: 5,
    blob_max_pixels: 100,
    pattern_width: 16,
    pattern_height: 16,
    pattern_maintain_ratio: true,
    allow_console_log: true,
    perceptive_colorspace: true,
    blob_debug: "debugSegmented",
    model_loaded: function() {
        document.getElementById("aSolve").style.display = "inline-block";
    }
});
cbl.train("1NKM4J.png");

solve
It's not perfect, but it's a good start.

@skotz skotz added the question label Jun 12, 2018
@skotz skotz self-assigned this Jun 12, 2018
@paulebe
Copy link
Author

paulebe commented Jun 13, 2018

@skotz Thank You!!

@paulebe
Copy link
Author

paulebe commented Jun 13, 2018

and for this type of captcha with inverse color format above png just like this ...
3
4
2

@skotz
Copy link
Owner

skotz commented Jun 14, 2018

You could try first inverting the image and then running the same filters as before. I just added the invert method, so you'll need to get the latest version of the library for it to work.

preprocess: function(img) {
    img.debugImage("debugPreprocessed");
    img.invert();
    img.debugImage("debugPreprocessed");
    img.convolute([ [0, 1, 0],
                    [0, 1, 0],
                    [0, 0, 0] ]);
    img.debugImage("debugPreprocessed");
    img.colorRegions(2, false);
    img.debugImage("debugPreprocessed");
}

@skotz
Copy link
Owner

skotz commented Jun 14, 2018

Actually, since there are always 6 characters that are always in the same place with the same horizontal line, you can just grab the characters out of the same place every time. Again, I added a new method to the library to support this. With this method you can get pretty close to 100% accuracy after training.

var cbl = new CBL({
    preprocess: function(img) {
        img.debugImage("debugPreprocessed");
        img.convolute([ [0, 1, 0],
                        [1, 2, 1],
                        [0, 1, 0] ], 1/6);
        img.debugImage("debugPreprocessed");
        img.binarize(128);
        img.debugImage("debugPreprocessed");
        img.invert();
        img.debugImage("debugPreprocessed");
    },
    fixed_blob_locations: [ 
        { x1:  5, y1: 3, x2: 13, y2: 12 },
        { x1: 15, y1: 3, x2: 23, y2: 12 },
        { x1: 25, y1: 3, x2: 33, y2: 12 },
        { x1: 35, y1: 3, x2: 43, y2: 12 },
        { x1: 45, y1: 3, x2: 53, y2: 12 },
        { x1: 55, y1: 3, x2: 63, y2: 12 } 
    ],
    character_set: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
    pattern_width: 9,
    pattern_height: 10,
    allow_console_log: true,
    blob_debug: "debugSegmented",
    model_file: "model.dat"
});

cbl.train("1NKM4J.png");
cbl.train("3WJ671.png");
cbl.train("730CR1.png");

cap

@paulebe
Copy link
Author

paulebe commented Jun 14, 2018

Thank You!!! for your great help @skotz

@paulebe
Copy link
Author

paulebe commented Jun 14, 2018

How can i distinguish between these two different captcha, programtically

So that i can apply transformation accordingly

@skotz
Copy link
Owner

skotz commented Jun 14, 2018

You could write a method to check the pixel at (0, 0) and see whether it's black or white.

@paulebe
Copy link
Author

paulebe commented Jun 15, 2018

@skotz Thank you

@paulebe
Copy link
Author

paulebe commented Jun 15, 2018

@skotz Thank You for your support. now i able to achieve 99% accuracy for the above captcha

@paulebe paulebe closed this as completed Jun 15, 2018
@paulebe paulebe reopened this Jun 15, 2018
@paulebe
Copy link
Author

paulebe commented Jun 15, 2018

Does the library has any method to get the pixel value? It's some what difficult to get the pixel value through CANVAS element.
Kindly extend the library to support getPixel method

@skotz
Copy link
Owner

skotz commented Jun 15, 2018

That's a good idea. I'll mark this thread as an enhancement and add that when I have time.

@paulebe
Copy link
Author

paulebe commented Jun 16, 2018

Thank you for your response @skotz

@paulebe
Copy link
Author

paulebe commented Jun 16, 2018

CLOSED

@paulebe paulebe closed this as completed Jun 16, 2018
@skotz
Copy link
Owner

skotz commented Jun 16, 2018

By the way, I've added the method. Now you can get a specific pixel and perform some kind of check to see if it's white, and if it is, invert the image.

if (img.getPixel(0, 0).r == 255) {
    img.invert();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants