Ejemplo n.º 1
0
def add_xml_book_data_to_json(book_code, json_obj):

    json_data = json_utils.read_json_file(const.JSON_PATH)

    books = json_data['books']
    if book_code in books.keys():
        books[book_code].append(json_obj)
    else:
        books[book_code] = [json_obj]

    json_data['books'] = books

    json_utils.write_json_file(const.JSON_PATH, json_data)
Ejemplo n.º 2
0
def add_xml_book_data_to_json(book_code, json_obj):

    json_data = json_utils.read_json_file(const.JSON_PATH)

    books = json_data['books']
    if book_code in books.keys():
        books[book_code].append(json_obj)
    else:
        books[book_code] = [json_obj]

    json_data['books'] = books

    json_utils.write_json_file(const.JSON_PATH, json_data)
    print(const.BLUE, 'Added XML Book Entry to JSON', const.END)
Ejemplo n.º 3
0
def test_detect_metrics():
    tps, fns, fps = 0, 0, 0
    for img_path in glob(test_folder + "/*.jpg"):
        json_path = str(img_path)[:-3] + "json"
        img = cv2.imread(str(img_path))
        results = engine.diff_areas(img)
        predictions = [item['bbox'] for item in results]
        ground_truths = get_bbox_from_json(read_json_file(json_path))
        tp, fn, fp = get_metrics(predictions, ground_truths, iou_thres=0.3)
        tps += tp
        fns += fn
        fps += fp
    precision = tps / (tps + fps)
    recall = tps / (tps + fns)
    f1_score = 2 * precision * recall / (precision + recall)
    print(
        f"precision: {precision:.4f}, recall: {recall:.4f}, f1_score: {f1_score:.4f}"
    )
Ejemplo n.º 4
0
def validate_all_xml_files():

    json_data = json_utils.read_json_file(const.JSON_PATH)

    book_schema = get_book_schema(const.XSD_PATH)

    books_json = json_data['books']
    for book_code in books_json.keys():
        books_list = books_json[book_code]
        for book in books_list:
            if book['is_validated']:
                print(const.BLUE, 'Book : ', book['xml_file'], ' is valid',
                      const.END)
                continue
            else:
                if 'xml_file_path' in book:
                    result = book_schema.is_valid(book['xml_file_path'])
                    print('Validating Book : ', book['xml_file'], ' -> ',
                          result)
                    book['is_validated'] = result

    json_data['books'] = books_json
    json_utils.write_json_file(const.JSON_PATH, json_data)
Ejemplo n.º 5
0
def save_validated_files_to_db():
    json_data = json_utils.read_json_file(const.JSON_PATH)
    books_json = json_data['books']
    for book_code in books_json.keys():
        books_list = books_json[book_code]
        for book in books_list:
            if not book['is_validated']:
                print(const.WARNING, 'XML File :: ', book['xml_file'], ' is not validated against XSD', const.END)
                continue
            if not book['is_saved_to_db']:
                print(const.BLUE, 'Adding Book Data : ', book['xml_file'], ' to the DB', const.END)
                book_dict = read_xml.parse_xml_file(book['xml_file_path'])
                result = adb.add_book_to_db(book_code, book_dict)
                book['is_saved_to_db'] = result
                w_str = const.WARNING
                if result:
                    w_str = const.BLUE
                print(w_str, 'Result :: ', result, const.END, '\n')
            else:
                print(const.BLUE, "Book Data already added to the Database", const.END)

    json_data['books'] = books_json
    json_utils.write_json_file(const.JSON_PATH, json_data)
import glob
import os
from PIL import Image
from utils.pascal_utils import write_pascal_annotation_aug
from utils.json_utils import read_json_file

data_dir='/media/milton/ssd1/dataset/pedestrian/caltech_pedestrian/caltech-pedestrian-dataset-converter/data'
images_dir=os.path.join(data_dir,'images')
json_file=os.path.join(data_dir,'annotations.json')

data=read_json_file(json_file)
for set_key in data.keys():
    set_data=data[set_key]
    for v_key in set_data.keys():
        frames=set_data[v_key]['frames']
        for frame_key in frames.keys():
            for frame_anno  in frames[frame_key]:

                filename="{}_{}_{}.png".format(set_key.lower(),v_key,frame_key)
                file_path=os.path.join(images_dir, filename)
                # if not os.path.exists(file_path):
                #     print("{} not found".format(file_path))
                try:
                    img=Image.open(file_path)
                except Exception as e:
                    continue
                pass


Ejemplo n.º 7
0
def show_ground_gt(img, json_path):
    json_data = read_json_file(json_path)
    bboxes = get_bbox_from_json(json_data)
    for bbox in bboxes:
        cv2.rectangle(img, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0),
                      3)