예제 #1
0
def getAllMarks(image):
    img = helper.cut_image(image, 330, 480, 335, 460)
    cv2.imwrite('C:\\Users\\Istrati Lucian\\Admitere-OCR\\bac.jpg', img)
    good = ""
    for i in range(335, 436, 25):
        singleMark = helper.cut_image(image, 330, 480, i, i + 25)
        cv2.imwrite(
            'C:\\Users\\Istrati Lucian\\Admitere-OCR\\bac' + str(
                (460 - i) / 25) + '.jpg', singleMark)
        text = get_text.get_text_from_image(singleMark)
        t = extractMarkUsingLetters(text)
        good += str(t) + " "
    return good
예제 #2
0
def getCNP(image):

    # get gender

    #img = helper.cut_image(image, 80, 245, 277, 295) good
    img = helper.cut_image(image, 89, 245, 277, 295)
    #160 pixels, 13*12
    text = ""
    pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
    for i in range(89,234,12):
        digit = helper.cut_image(image,i,i+9,277,293)
        path = "C:\\Users\\Istrati Lucian\\Admitere-OCR\\DIGIT"+str(i)+".jpg"
        cv2.imwrite(path,digit)
        t = get_text.get_text_from_image(digit)
        #t = pytesseract.image_to_string(Image.open(path))
        print(t,end=" ")
        text+=t
    """
    vertical = img
    vertical = cv.bitwise_not(vertical)
    show_wait_destroy("vertical_bit", vertical)
    
    Extract edges and smooth image according to the logic
    1. extract edges
    2. dilate(edges)
    3. src.copyTo(smooth)
    4. blur smooth img
    5. smooth.copyTo(src, edges)
    '''
    # Step 1
    edges = cv.adaptiveThreshold(vertical, 255, cv.ADAPTIVE_THRESH_MEAN_C, \
                                cv.THRESH_BINARY, 3, -2)
    show_wait_destroy("edges", edges)
    # Step 2
    kernel = np.ones((2, 2), np.uint8)
    edges = cv.dilate(edges, kernel)
    show_wait_destroy("dilate", edges)
    # Step 3
    smooth = np.copy(vertical)
    # Step 4
    smooth = cv.blur(smooth, (2, 2))
    # Step 5
    (rows, cols) = np.where(edges != 0)
    vertical[rows, cols] = smooth[rows, cols]
    # Show final result
    show_wait_destroy("smooth - final", vertical)
    """
        

    #text = get_text.get_text_from_image(img)
    return text
예제 #3
0
def cropFromOneHoughLineConversion(A, color):
    h, w = firstHough.shape
    red = color
    pixels = []
    allText = ""
    h, w = firstHough.shape
    for i in range(1, h - 1):
        for j in range(1, w - 1):
            if A[i][j] != red and A[i - 1][j] == red and A[i - 1][
                    j - 1] == red and A[i][j - 1] == red:
                pixels.append((i, j))
            if A[i][j] != red and A[i - 1][j] == red and A[i - 1][
                    j + 1] == red and A[i][j + 1] == red:
                pixels.append((i, j))
            if A[i][j] != red and A[i + 1][j - 1] == red and A[
                    i + 1][j] == red and A[i][j - 1] == red:
                pixels.append((i, j))
            if A[i][j] != red and A[i + 1][j] == red and A[i + 1][
                    j + 1] == red and A[i][j + 1] == red:
                pixels.append((i, j))
    for i in range(len(pixels) - 3):
        if levi.canBeARectangle(pixels[i], pixels[i + 1], pixels[i + 4],
                                pixels[i + 3]) == True:
            singleRectangelImage = helper.cut_image(image, pixels[i][1],
                                                    pixels[i + 1][1],
                                                    pixels[i][0],
                                                    pixels[i + 3][0])
            text = get_text.get_text_from_image(singleRectangelImage)
            allText += text
            allText += '\n'
    return allText
예제 #4
0
def getName(image):
    final_image = helper.cut_image(image, 100, 385, 166, 184)
    text = get_text.get_text_from_image(final_image)
    return text




      
예제 #5
0
def getSubject(image):
    """
	This function extracts the name of the subject for which the student had his 2nd exam in Baccalaureate
	The second exam may be either History or Mathematics, we need to extract the mark at maths, if he has one
	"""
    img = helper.cut_image(image, 35, 200, 338, 358)
    cv2.imwrite('C:\\Users\\Istrati Lucian\\Admitere-OCR\\subject.jpg', img)
    text = get_text.get_text_from_image(img)
    """
	if text!=None and levi.iterative_levenshtein("Limba si literatura romana - scris",text)>=10:
		img = helper.cut_image(image, 35, 200, 370, 390)
		cv2.imwrite('C:\\Users\\Istrati Lucian\\Admitere-OCR\\subject.jpg', img)
		text = get_text.get_text_from_image(img)
	
	if text!=None and levi.iterative_levenshtein("Matematica",text)<=6 or levi.iterative_levenshtein("Istorie",text)<=6:
	"""
    return text
예제 #6
0
def getMathMark(image):
    """
	To be revised - coordonations
	"""
    img = helper.cut_image(image, 300, 475, 338, 358)
    cv2.imwrite('C:\\Users\\Istrati Lucian\\Admitere-OCR\\math.jpg', img)
    text = get_text.get_text_from_image(img)
    good = extractMarkUsingLetters(text)
    ######
    """
	img = helper.cut_image(image, 35, 200, 338, 358)
	cv2.imwrite('C:\\Users\\Istrati Lucian\\Admitere-OCR\\subject.jpg', img)
	text = get_text.get_text_from_image(img)
	
	if levi.iterative_levenshtein("Limba si literatura romana - scris",text)>=10:
		img = helper.cut_image(image, 35, 200, 350, 370)
		cv2.imwrite('C:\\Users\\Istrati Lucian\\Admitere-OCR\\subject.jpg', img)
		text = get_text.get_text_from_image(img)
	"""
    ########

    return good
예제 #7
0
def getBacMarkInCaseSubjectRomanianLanguage(image):
    img = helper.cut_image(image, 300, 475, 434, 454)
    cv2.imwrite('C:\\Users\\Istrati Lucian\\Admitere-OCR\\bac.jpg', img)
    text = get_text.get_text_from_image(img)
    good = extractMarkUsingLetters(text)
    return good
예제 #8
0
def getBacMark(image):
    img = helper.cut_image(image, 300, 475, 390, 411)
    cv2.imwrite('C:\\Users\\Istrati Lucian\\Admitere-OCR\\bac.jpg', img)
    text = get_text.get_text_from_image(img)
    good = extractMarkUsingLetters(text)
    return good
예제 #9
0
def getSubjectInCaseSubjectRomanianLanguage(image):
    img = helper.cut_image(image, 35, 200, 385, 407)
    cv2.imwrite('C:\\Users\\Istrati Lucian\\Admitere-OCR\\subject.jpg', img)
    text = get_text.get_text_from_image(img)
    return text