Esempio n. 1
0
def test_get_numb_line_img(path):
    list_file = ppf.list_files1(path, 'jpg')
    list_file += ppf.list_files1(path, 'png')
    for pimg in list_file:
        cv2.destroyAllWindows()
        path_img = os.path.join(path, pimg)
        img = cv2.imread(path_img)
        print(ppf.get_numb_line_img(img,True,0.2,0.1, True))
Esempio n. 2
0
def test_delete_red_sign(path):
    list_file = ppf.list_files1(path, 'jpg')
    list_file += ppf.list_files1(path, 'png')
    for pimg in list_file:
        # cv2.destroyAllWindows()
        path_img = os.path.join(path, pimg)
        img = cv2.imread(path_img)
        ppf.delete_red_sign_in_text_black(img, True)
Esempio n. 3
0
def test_erase_box_cell(path):
    list_file = ppf.list_files1(path, 'jpg')
    list_file += ppf.list_files1(path, 'png')
    for pimg in list_file:
        # cv2.destroyAllWindows()
        path_img = os.path.join(path, pimg)
        img = cv2.imread(path_img)
        cv2.imshow("img",ppf.erase_cell(img,debug= True))
        cv2.waitKey()
Esempio n. 4
0
def test_auto_rotate_image(path):
    list_file = ppf.list_files1(path, 'jpg')
    list_file += ppf.list_files1(path, 'png')
    for pimg in list_file:
        # cv2.destroyAllWindows()
        path_img = os.path.join(path, pimg)
        img = cv2.imread(path_img)
        img_out = ppf.auto_rotation(img, debug= True)
        cv2.imshow('img out ',img_out)
        cv2.waitKey()
Esempio n. 5
0
def store_data_handwriting_table(path, save_path, expand_y=0):
    list_img = impr.list_files1(path, "jpg")
    list_img += impr.list_files1(path, "png")
    dir_name = os.path.dirname(path)

    pred_time = datetime.today().strftime('%Y-%m-%d_%H-%M')
    if save_path is not None:
        result_save_dir = os.path.join(save_path, "aicrhw_" + pred_time)
        if not os.path.isdir(result_save_dir):
            os.mkdir(result_save_dir)
    if len(list_img) == 0:
        print("input image empty")
        return
    list_class_img_info = []
    count = 0
    for path_img in list_img:
        path_img = os.path.join(path, path_img)
        img = cv2.imread(path_img)
        count += 1
        path_save_image = os.path.join(result_save_dir,
                                       "AICR_P" + str(count).zfill(7))
        if not os.path.isdir(path_save_image):
            os.mkdir(path_save_image)
        path_org_img = os.path.join(path_save_image, "origine.jpg")
        cv2.imwrite(path_org_img, img)
        img_bl = img.copy()
        h_n = img_bl.shape[0]
        w_n = img_bl.shape[1]
        hline_list, vline_list = tbdetect.get_h_and_v_line_bbox_CNX(img_bl)
        list_p_table, hline_list, vline_list = tbdetect.detect_table(
            hline_list, vline_list)
        count_img = 0
        for table in list_p_table:
            table.detect_cells()
            len_cells = len(table.listCells)
            if len_cells != 12:
                print("error ", path_save_image)
            for id_box in range(len_cells):
                if id_box % 2 != 0:
                    count_img += 1
                    bx, by, ex, ey = table.listCells[id_box]
                    info_img = impr.crop_image(img_bl, bx, by, ex, ey)
                    save_path_img = os.path.join(path_save_image,
                                                 str(count_img) + ".jpg")
                    cv2.imwrite(save_path_img, info_img)
    print("finished !!")
Esempio n. 6
0
def test_extract_table(path):
    list_file = ppf.list_files1(path, 'jpg')
    list_file += ppf.list_files1(path, 'png')
    for pimg in list_file:
        cv2.destroyAllWindows()
        path_img = os.path.join(path, pimg)
        img = cv2.imread(path_img)
        h = img.shape[0]
        print(path_img)
        print('h h2/7 ',h,int(h*2/7))
        cv2.imshow('raw',img)
        hline_list, vline_list = tblet.get_h_and_v_line_bbox_CNX(img)
        list_p_table, hline_list, vline_list = tblet.detect_table(hline_list, vline_list,int(h/20))
        id = -1
        max_s = 0
        count = 0
        for t in list_p_table:
            print("startY ",t.startY)
            if t.startY > h*2/7:
                wt = t.endX - t.startX
                ht = t.endY - t.startY
                print("x y wt ht ",t.startX,t.startY,ht,wt)
                if wt*ht > max_s and  ht < h/2:
                    id = count
                    max_s = wt*ht
            count+=1
        if id != -1:
            list_p_table[id].detect_cells()
            ifb = list_p_table[id].listCells[-1]
            crop_img = ppf.crop_image(img,ifb[0],ifb[1],ifb[2],ifb[3])
            l_if = ppf.get_numb_line_img(crop_img,True,0.2,0.1, False)
            print(l_if)
            cv2.imshow("crop",crop_img)
            c = 0
            for l in l_if:
                x, y, xe, ye,_ = l
                ci = ppf.crop_image(crop_img, x, y, xe, ye)
                if ci.shape[0] > 0 and ci.shape[1] > 0:
                    cv2.imshow("crop_"+str(c),ci)
                c+=1
        cv2.waitKey()
Esempio n. 7
0
def store_data_handwriting_template(path,
                                    path_config_file,
                                    save_path,
                                    expand_y=0):
    list_img = impr.list_files1(path, "jpg")
    list_img += impr.list_files1(path, "png")
    dir_name = os.path.dirname(path)

    pred_time = datetime.today().strftime('%Y-%m-%d_%H-%M')
    if save_path is not None:
        result_save_dir = os.path.join(save_path, "aicrhw_" + pred_time)
        if not os.path.isdir(result_save_dir):
            os.mkdir(result_save_dir)
    if len(list_img) == 0:
        print("input image empty")
        return
    template = impr.clTemplate_demo()
    with open(path_config_file, 'r+') as readf:
        count = 0
        for line in readf:
            count += 1
            if count == 1:
                template.name_template = line
            else:
                list_inf = line.split()
                if len(list_inf) == 5:
                    bb_i = [
                        list_inf[0],
                        int(list_inf[1]),
                        int(list_inf[2]),
                        int(list_inf[1]) + int(list_inf[3]),
                        int(list_inf[2]) + int(list_inf[4])
                    ]
                    template.listBoxinfor.append(bb_i)
                elif len(list_inf) == 2:
                    template.height = int(list_inf[0])
                    template.width = int(list_inf[1])
    count_img = 0
    list_class_img_info = []
    count = 0
    for path_img in list_img:
        path_img = os.path.join(path, path_img)
        img = cv2.imread(path_img)
        count += 1
        path_save_image = os.path.join(result_save_dir,
                                       "AICR_P" + str(count).zfill(7))
        if not os.path.isdir(path_save_image):
            os.mkdir(path_save_image)
        path_org_img = os.path.join(path_save_image, "origine.jpg")
        cv2.imwrite(path_org_img, img)
        img_bl = impr.auto_rotation(img)
        h_n = img_bl.shape[0]
        w_n = img_bl.shape[1]
        ratioy = h_n / template.height
        ratiox = w_n / template.width
        for if_box in template.listBoxinfor:
            prefix = if_box[0]
            count_img += 1
            bx = int(if_box[1] * ratiox)
            by = int((if_box[2] - expand_y) * ratioy)
            ex = int(if_box[3] * ratiox)
            ey = int((if_box[4] + expand_y) * ratioy)
            info_img = impr.crop_image(img_bl, bx, by, ex, ey)
            save_path_img = os.path.join(path_save_image, prefix + ".jpg")
            cv2.imwrite(save_path_img, info_img)
    print("finished !!")