-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
32 lines (26 loc) · 693 Bytes
/
test.py
File metadata and controls
32 lines (26 loc) · 693 Bytes
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
import cv2
import matplotlib.pyplot as plt
patient = "Breast_MRI_103_37"
jpg_name = f"test/{patient}.jpg"
txt_name = f"test/{patient}.txt"
jpg = cv2.imread(jpg_name)
#jpg = cv2.flip(jpg, -1)
shape = jpg.shape
boxes = []
with open(txt_name) as f:
for line in f.readlines():
line = line.rstrip("\n")
boxes.append(line.split("\t")[1:])
for b in boxes:
b = [float(b1) for b1 in b]
x, y, w, h = b
#x = shape[0]-x
#y = shape[1]-y
_l = int(x)
_r = int(x + w)
_t = int(y + h)
_b = int(y)
print(f"{_l}_{_r}_{_t}_{_b}")
print(shape)
jpg = cv2.rectangle(jpg, (_l, _b), (_r, _t), (0, 0, 255), 6)
plt.imsave(f"test_{patient}.jpg", jpg)