This repository has been archived by the owner on Dec 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcsv_to_img.py
executable file
·79 lines (58 loc) · 2.01 KB
/
csv_to_img.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
File for converting the csv file into bounding box image
"""
import numpy as np
import os
import argparse
import pprint
from PIL import Image
from object_detection.logging.logger import rootLogger
from object_detection.utils import (get_available_datasets)
import csv
import cv2
# Datasets
DATASETS = {'polyps'}
# training settings
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description='Bounding Box Predictions')
# general
parser.add_argument('-d', '--dataset', type=str, default='polyps',
help="dataset, {'" +\
"', '".join(get_available_datasets()) +\
"'}")
# parse and validate parameters
args = parser.parse_args()
for k, v in args._get_kwargs():
if isinstance(v, str):
setattr(args, k, v.strip().lower())
def main(args=args):
"""
main function that parses the arguments and trains
:param args: arguments related
:return: None
"""
# pylint: disable=line-too-long
dataset_name = args.dataset
FILE_PATH_SRC = os.path.join(os.getcwd(), 'data/'+ args.dataset+'/val_predictions/')
FILE_PATH_DEST = os.path.join(os.getcwd(), 'data/'+ args.dataset+'/val_predictions_bbox/')
file_name = 'bbox_predictions.csv'
with open(FILE_PATH_SRC+file_name) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
for row in csv_reader:
if line_count == 0:
line_count += 1
else:
image = row[0]
xmin = row[3]
ymin = row[4]
xmax = row[5]
ymax = row[6]
img = cv2.imread(FILE_PATH_DEST+image)
img = cv2.rectangle(img, (int(xmin), int(ymin)), (int(xmax), int(ymax)), (0, 255, 0), 1)
cv2.imwrite(FILE_PATH_DEST+image,img)
line_count += 1
if __name__ == '__main__':
main()