|
a |
|
b/read_detection.py |
|
|
1 |
import sys |
|
|
2 |
from glob import glob |
|
|
3 |
from PIL import Image |
|
|
4 |
%matplotlib inline |
|
|
5 |
from matplotlib import pyplot as plt |
|
|
6 |
import os |
|
|
7 |
import cv2 |
|
|
8 |
import json |
|
|
9 |
import pandas as pd |
|
|
10 |
import numpy as np |
|
|
11 |
from glob import glob |
|
|
12 |
from tqdm import tqdm |
|
|
13 |
from IPython import embed |
|
|
14 |
import base64 |
|
|
15 |
import csv |
|
|
16 |
from tqdm import trange |
|
|
17 |
import xml.etree.cElementTree as ET |
|
|
18 |
# from labelme import utils |
|
|
19 |
|
|
|
20 |
if sys.version_info[0] == 2: |
|
|
21 |
import xml.etree.cElementTree as ET |
|
|
22 |
else: |
|
|
23 |
import xml.etree.ElementTree as ET |
|
|
24 |
|
|
|
25 |
font = cv2.FONT_HERSHEY_SIMPLEX |
|
|
26 |
|
|
|
27 |
color_mode = [(0,0,255),(0,255,0),(255,0,0),(0,255,255),(255,0,255),(255,255,0),(255,255,255)] |
|
|
28 |
|
|
|
29 |
plt.figure(figsize=(10, 10)) |
|
|
30 |
|
|
|
31 |
image_path = r"G:\bleeding\labelled_images\blood_fresh\Blood - fresh" |
|
|
32 |
csv_file = r"G:\bleeding\metadata.csv" |
|
|
33 |
csvfile = open( r"G:\bleeding\metadata.csv",'r') |
|
|
34 |
annotations = [each for each in csv.DictReader(csvfile, delimiter=';')] |
|
|
35 |
# annotations = pd.read_csv(csv_file,header=None).values |
|
|
36 |
# category = reader['finding_category'] |
|
|
37 |
img_name = os.listdir(image_path) |
|
|
38 |
total_csv_annotations = [] |
|
|
39 |
total_position = [] |
|
|
40 |
for annotation in annotations: |
|
|
41 |
key = annotation['filename']#.split(os.sep)[-1] |
|
|
42 |
# name = annotation['filename'] |
|
|
43 |
position = [annotation['x1'],annotation['y1'],annotation['x2'],annotation['y2'],annotation['x3'], |
|
|
44 |
annotation['y3'],annotation['x4'],annotation['y4']] |
|
|
45 |
name = key |
|
|
46 |
if key in img_name: |
|
|
47 |
pts = ['xmin', 'ymin', 'xmax', 'ymax'] |
|
|
48 |
bndbox = [min(position[0],position[2],position[4],position[6]),min(position[1],position[3],position[5],position[7]), |
|
|
49 |
max(position[0],position[2],position[4],position[6]),max(position[1],position[3],position[5],position[7])] |
|
|
50 |
img = cv2.imread(os.path.join(image_path,key)) |
|
|
51 |
|
|
|
52 |
top_corner, down_corner = (int(bndbox[0]), int(bndbox[1])), (int(bndbox[2]), int(bndbox[3])) |
|
|
53 |
cv2.rectangle(img, top_corner, down_corner, color_mode[0], thickness=2) |
|
|
54 |
# cv2.putText(img,str(name),(top_corner[0]+5, top_corner[1]+25), font, 1,color_mode[1],1,cv2.LINE_AA) |
|
|
55 |
plt.imshow(img[:,:,::-1]) |
|
|
56 |
plt.axis('off') |
|
|
57 |
plt.show() |