예제 #1
0
    def do_skew_correction(self,widget):
     
        global imgloc
        global skewcorrected
        if imgloc == 0 :
         
            errorwindow = builder.get_object("error_message_box")
            errorwindow.set_transient_for(window)
            errorwindow.set_markup("<b>No Image loaded to the application</b>")
            errorwindow.format_secondary_markup("Add or Scan image to start skew correction")
            errorwindow.show()


        elif skewcorrected == 0 :
            
            loc = imgloc
          
            out=os.path.join(os.path.split(loc)[0],'skewcorrected'+os.path.splitext(os.path.split(loc)[1])[0]+os.path.splitext(os.path.split(loc)[1])[1])
           
            d = Deskew(
                   input_file=loc,
                   display_image=None,
                   output_file=out,
                   r_angle=0)
            d.run()
            
            imgloc = out
         
            img = builder.get_object("previmage")
            img.set_from_file(imgloc)
            skewcorrected = 1
            successwindow = builder.get_object("error_message_box")
            successwindow.set_transient_for(window)
            successwindow.set_markup("<b>Skewness of the Image Corrected Successfully</b>")
            successwindow.format_secondary_markup("You can now proceed Converting to text")
            successwindow.show()
            global zoomout
            zoomout =1

        
        else:
           
            errorwindow = builder.get_object("error_message_box")
            errorwindow.set_transient_for(window)
            errorwindow.set_markup("<b>Image already Skew Corrected</b>")
            errorwindow.format_secondary_markup("Further correction may increase the skewness")
            errorwindow.show()
예제 #2
0
def process_image(img_path, output_path):
    img = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)
    print('Skew correcting image: ', img_path)
    processed1 = process1(img)
    cv2.imwrite(os.path.join(output_path, 'processed1.png'), processed1)

    try:
        angle = compute_skew(img)
        print("deskew angle: {:.3f}".format(angle))
        out = deskew_image(img, angle)
        cv2.imwrite(os.path.join(output_path, 'processed2.png'), out)
    except:
        print('Failed')

    d = Deskew(input_file=img_path,
               display_image=False,
               output_file=os.path.join(output_path, 'corrected.png'),
               r_angle=0)
    d.run()
예제 #3
0
def default_freset(op, noise, boxes, img):

    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    #debug
    cv2.imshow('ori', img)
    cv2.waitKey()
    
    pcs_obj = Preprocessing(img)
    if op: 
        pcs_img = pcs_obj.natural_img_processing(noise)
    else:
        pcs_img = pcs_obj.digital_img_processing()

    #debug
    cv2.imshow('pre', pcs_img)
    cv2.waitKey()        

    skew_obj = Deskew(pcs_img)
    skew_img = skew_obj.run()

    #debug
    cv2.imshow('skew', skew_img)
    cv2.waitKey()        


    tdt_obj = TextDetection(skew_img, img)
    text_img = tdt_obj.detection()
  
    #debug
    flag = -1
    for t_img, y, x in text_img:
        #cv2.imshow('', t_img)
        #cv2.waitKey()
        t_img = cv2.copyMakeBorder(t_img, 10, 10, 10, 10, cv2.BORDER_CONSTANT, value=[255,255,255])
        if flag <= y+1 and flag >= y-1:
            tesseract_ocr(t_img, True)
        else:
            tesseract_ocr(t_img)
        
        if boxes: 
            b_img = tesseract_boxes(t_img)
            h, w = t_img.shape[:2]
            gray[y*2:y*2+h, x*2:x*2+w] = b_img
        flag = y

    #debug
    if boxes:
        cv2.imshow('origin', tesseract_boxes(img))
        cv2.imshow('result', gray)
        cv2.waitKey()
예제 #4
0
from time import sleep

from cv2.cv2 import *
import numpy as np
from matplotlib import pyplot as plt

from deskew import Deskew

path = "C:\\Users\\OmarMarridi\\Desktop\\Semester\\Digtal Image Processing\\ImageProject\\Preprocessing DataSet\\"
deskew_obj = Deskew(path+'Doc14.tif', 'Yes', 0)
image=deskew_obj.run()
image = threshold(image,130,255,THRESH_BINARY)
imwrite(path+'testborder.tif',image[1])
예제 #5
0
from skew_detect import SkewDetect
from deskew import Deskew
from text_cleaner import clean_image

img_path = './images/12.png'
clean_image(img_path, './')
img_path = 'cleaned.png'
#sd = SkewDetect(input_file=img_path, output_file='./output.txt', display_output='Yes')
#sd.run()

d = Deskew(input_file=img_path,
           display_image=False,
           output_file='output_img.png',
           r_angle=0)
d.run()
예제 #6
0
        # if a face find in this case we consider this face and image and continue our job
        if (len(faces) != 0):
            M = cv2.getRotationMatrix2D(center, 180, 1.0)
            docImage = cv2.warpAffine(docImage, M, (width, height))

    print("Found {0} faces!".format(len(faces)))
    return docImage, faces


#################################################################
#################################################################
inputAddress = 'patent3.jpg'
outputAddress = 'patent3Ro.jpg'

des = Deskew(inputAddress, False, outputAddress, 0)
des.run()
image = Image.open(outputAddress)

box = getbox(image)
result = image.crop(box)
result.save('sampleCut.jpg')

# Read the image
image = cv2.imread('sampleCut.jpg')
image, faces = detectFace(image)

# we keep only the biggest face. because sometime some noise fool the algorithm
faceArea = 0
faceX = 0
faceY = 0
faceW = 0