utils Module

The utils module contains functions to cut the white space, extract coordinates of black pixels in an image and merge two images horizontally. This module is used by amazoncaptcha.solver.AmazonCaptcha.

Functions

amazoncaptcha.utils.cut_the_white(letter)[source]

Cuts white spaces/borders to get a clear letter.

Parameters:letter (PIL.Image) – Letter to be processed.
Returns:The letter without white spaces.
Return type:PIL.Image
amazoncaptcha.utils.merge_horizontally(img1, img2)[source]

Merges two letters horizontally.

Created in case an image is corrupted and the last letter ends at the beginning of the image, causing letter to be unreadable.

Parameters:
  • img1 (PIL.Image) – First letter.
  • img2 (PIL.Image) – Second letter.
Returns:

Two merged letters.

Return type:

PIL.Image

amazoncaptcha.utils.find_letter_boxes(img, maxlength)[source]

Finds and separates letters from a captcha image.

Parameters:
  • img (PIL.Image) – Monochromed captcha.
  • maxlength (int) – Maximum letter length by X axis.
Returns:

List with X coords of each letter.

Return type:

letter_boxes (list of tuple)