Exemple #1
0
    def extract_bu(original, x, w, y, h, num):
        """
        Extract base units from layout units consisting of written text.

        Args:
            original: The input image.
            x: X-coordinate of the bounding box.
            w: Width of the bounding box.
            y: Y-coordinate of the bounding box.
            h: Height of the bounding box.
            num: The number of contour.

        Returns:
            The layout unit identifier and the base units contained within it.
        """

        # Extract the region defined by the bounding box
        roi = original[y: y + h, x: x + w]

        # Convert the region of interest into grayscale
        gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)

        # Perform thresholding using Otsu's method
        (t, thresholded) = cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU)

        # Resize the thresholded image to 200% of the original
        resized = imutils.resize(thresholded, width=2 * w)

        # Feed the resized image to Pytesser
        content = pytesser.mat_to_string(resized)
        unicode_content = unicode(content, 'utf-8')

        # TODO Use APNR techniques to measure font size at this stage
        # - seek lines of text using aspect ratio of detected bounding boxes
        # - use morphological operations to cut individual characters from the image
        # - calculate their size and take the most common one (this should cover both normal & all caps)

        # Tokenize sentences for base units
        bu = Generate.tokenize(unicode_content)

        # Return the extracted base units
        return num, bu
Exemple #2
0
    def extract_bu(original, x, w, y, h, num):
        """
        Extract base units from layout units consisting of written text.

        Args:
            original: The input image.
            x: X-coordinate of the bounding box.
            w: Width of the bounding box.
            y: Y-coordinate of the bounding box.
            h: Height of the bounding box.
            num: The number of contour.

        Returns:
            The layout unit identifier and the base units contained within it.
        """

        # Extract the region defined by the bounding box
        roi = original[y:y + h, x:x + w]

        # Convert the region of interest into grayscale
        gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)

        # Perform thresholding using Otsu's method
        (t, thresholded) = cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU)

        # Resize the thresholded image to 200% of the original
        resized = imutils.resize(thresholded, width=2 * w)

        # Feed the resized image to Pytesser
        content = pytesser.mat_to_string(resized)
        unicode_content = unicode(content, 'utf-8')

        # TODO Use APNR techniques to measure font size at this stage
        # - seek lines of text using aspect ratio of detected bounding boxes
        # - use morphological operations to cut individual characters from the image
        # - calculate their size and take the most common one (this should cover both normal & all caps)

        # Tokenize sentences for base units
        bu = Generate.tokenize(unicode_content)

        # Return the extracted base units
        return num, bu
Exemple #3
0
def extract_bu(original, x, w, y, h, num):
    """
    Extract base units from layout units consisting of written text.

    Args:
        original: The input image.
        x: X-coordinate of the bounding box.
        w: Width of the bounding box.
        y: Y-coordinate of the bounding box.
        h: Height of the bounding box.
        num: The number of contour.

    Returns:
        The layout unit identifier and the base units contained within it.
    """

    # Extract the region defined by the bounding box
    roi = original[y: y + h, x: x + w]

    # Convert the region of interest into grayscale
    gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)

    # Perform thresholding using Otsu's method
    (t, thresholded) = cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU)

    # Resize the thresholded image to 200% of the original
    resized = imutils.resize(thresholded, width=2 * w)

    # Feed the resized image to Pytesser
    content = pytesser.mat_to_string(resized)
    unicode_content = unicode(content, 'utf-8')

    # Tokenize sentences for base units
    bu = tokenize(unicode_content)

    # Return the extracted base units
    return num, bu
Exemple #4
0
def extract_bu(original, x, w, y, h, num):
    """
    Extract base units from layout units consisting of written text.

    Args:
        original: The input image.
        x: X-coordinate of the bounding box.
        w: Width of the bounding box.
        y: Y-coordinate of the bounding box.
        h: Height of the bounding box.
        num: The number of contour.

    Returns:
        The layout unit identifier and the base units contained within it.
    """

    # Extract the region defined by the bounding box
    roi = original[y:y + h, x:x + w]

    # Convert the region of interest into grayscale
    gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)

    # Perform thresholding using Otsu's method
    (t, thresholded) = cv2.threshold(gray, 0, 255, cv2.THRESH_OTSU)

    # Resize the thresholded image to 200% of the original
    resized = imutils.resize(thresholded, width=2 * w)

    # Feed the resized image to Pytesser
    content = pytesser.mat_to_string(resized)
    unicode_content = unicode(content, 'utf-8')

    # Tokenize sentences for base units
    bu = tokenize(unicode_content)

    # Return the extracted base units
    return num, bu
import numpy
import cv2
import time
import pytesser

print "Automatic Apple ID Creator\n"

index = 24

while index < 26:

    path = "captcha/captcha" + str(index) + ".jpg"

    img = cv2.imread(path)
    gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    #detect text in the image
    text = pytesser.mat_to_string(gray_img)

    print(text)

    cv2.imshow('Image', gray_img)
    key = cv2.waitKey(113)
    time.sleep(0.25)

    cv2.destroyAllWindows()
    index = index + 1
Exemple #6
0
import numpy
import cv2
import time
import pytesser

print "Automatic Apple ID Creator\n"

index = 24

while index < 26:

	path = "captcha/captcha" + str(index) + ".jpg"

	img = cv2.imread(path)
	gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

	#detect text in the image
	text = pytesser.mat_to_string(gray_img)

	print(text)

	cv2.imshow('Image', gray_img)
	key = cv2.waitKey(113)
	time.sleep(0.25)
	
	cv2.destroyAllWindows()
	index = index + 1