def test_regions(self): sample = decaptcha.monochrome(self.captcha.channel(220, 227)) regions = decaptcha.regions(sample, threshold=1) self.assertTrue( regions == EXPECTED_REGIONS, "Expected regions %s, instead got %s" % (EXPECTED_REGIONS, regions))
def test_guess_character(self): sample = decaptcha.monochrome(self.captcha.channel(220, 227)) regions = decaptcha.regions(sample) segment = self.captcha.segment(sample, regions[0], crop=False) exp_seg = Image.open(TEST_SEGMENT_IMG(1)) self.assertTrue(segment.histogram() == exp_seg.histogram(), "Segment is wrong") predictions = self.captcha.guess_character(segment) self.assertTrue( predictions[0] == EXPECTED_OUTPUT, "Expected %s, got %s" % (EXPECTED_OUTPUT, predictions[0]))
def test_guess_character(self): sample = decaptcha.monochrome(self.captcha.channel(220, 227)) regions = decaptcha.regions(sample) segment = self.captcha.segment(sample, regions[0], crop=False) exp_seg = Image.open(TEST_SEGMENT_IMG(1)) self.assertTrue(segment.histogram() == exp_seg.histogram(), "Segment is wrong") predictions = self.captcha.guess_character(segment) self.assertTrue(predictions[0] == EXPECTED_OUTPUT, "Expected %s, got %s" % (EXPECTED_OUTPUT, predictions[0]))
def test_segmentation(self): """Note, in the test cases of the original publication (http://tinyurl.com/phvggox), output segments #3 and #5 (which are both the number 9) are mistakenly swapped. """ sample = decaptcha.monochrome(self.captcha.channel(220, 227)) segments = self.captcha.segments(sample, crop=False, tolerance=1) for i, segment in enumerate(segments): EXPECTED_SEGMENT = Image.open(TEST_SEGMENT_IMG(i + 1)) self.assertTrue( segment.histogram() == EXPECTED_SEGMENT.histogram(), "Segment #%s is wrong." % (i + 1))
def test_segmentation(self): """Note, in the test cases of the original publication (http://tinyurl.com/phvggox), output segments #3 and #5 (which are both the number 9) are mistakenly swapped. """ sample = decaptcha.monochrome(self.captcha.channel(220, 227)) segments = self.captcha.segments(sample, crop=False, tolerance=1) for i, segment in enumerate(segments): EXPECTED_SEGMENT = Image.open(TEST_SEGMENT_IMG(i+1)) self.assertTrue(segment.histogram() == EXPECTED_SEGMENT.histogram(), "Segment #%s is wrong." % (i+1))
def test_channels(self): channel = decaptcha.monochrome(self.captcha.channel(220, 227)) print(channel.histogram()) self.assertTrue( channel.histogram() == Image.open(TEST_CHANNEL_IMG).histogram(), "Channel sample did not match expected image")
def test_regions(self): sample = decaptcha.monochrome(self.captcha.channel(220, 227)) regions = decaptcha.regions(sample, threshold=1) self.assertTrue(regions == EXPECTED_REGIONS, "Expected regions %s, instead got %s" % (EXPECTED_REGIONS, regions))
def test_channels(self): channel = decaptcha.monochrome(self.captcha.channel(220, 227)) print(channel.histogram()) self.assertTrue(channel.histogram() == Image.open(TEST_CHANNEL_IMG).histogram(), "Channel sample did not match expected image")