whai362 / PSENet

Official Pytorch implementations of PSENet.
Apache License 2.0
1.17k stars 344 forks source link

How to create the green polygons on top of the images? #169

Closed Mary63 closed 3 years ago

Mary63 commented 3 years ago

Hello!

Thank you for your great work.

I have trained the model on CTW data and I tested it. Now, I have a folder that has .txt files. But I don't know how to see these result on the images. I mean how to create those green polygons on the images?

Any help would be greatly appreciated.

Mary63 commented 3 years ago

I finally created a new .py file containing these code under the (eval/ctw) and I could create the polygons around the images. Here is the code:

import file_util import numpy as np import matplotlib.pyplot as plt import matplotlib.image as mpimg import ipdb from shapely.geometry import Polygon

project_root = '../../'

pred_root = project_root + 'outputs/submit_ctw' image_root = project_root + 'data/CTW1500/test/text_image'

def get_pred(path): lines = file_util.read_file(path).split('\n') bboxes = [] for line in lines: if line == '': continue bbox = line.split(',') if len(bbox) % 2 == 1: print(path) bbox = [int(x) for x in bbox] bboxes.append(bbox) return bboxes

if name == 'main':

pred_list = file_util.read_dir(pred_root)
image_list = file_util.read_dir(image_root)

i = 0
for imgs in image_list:

    for pred_path in [pred_list[i]]:
        preds = get_pred(pred_path)

        for pred_id, pred in enumerate(preds):
            pred = np.array(pred)
            pred = pred.reshape(pred.shape[0] // 2, 2)[:, ::-1]

            pred_p = Polygon(pred)
            x,y = pred_p.exterior.xy
            plt.plot(x,y)

    img = mpimg.imread(imgs)
    plt.imshow(img)
    plt.show()
    i += 1
ChenJian7578 commented 1 year ago

你好请问如何在训练CTW数据集的?我将数据集下载下来后进行配置,但是它好像不能识别xml文件的标注信息。