-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathpredict_HRI.py
62 lines (47 loc) · 1.58 KB
/
predict_HRI.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
import cv2
from darkflow.net.build import TFNet
options = {'model': 'cfg/tiny-yolo-voc-3c.cfg',
'load': 3750,
'threshold': 0.15,
'gpu': 0.7}
tfnet = TFNet(options)
C = [] # Center
R = [] # Radius
L = [] # Label
im_name = 'HRI001'
image = cv2.imread('data/' + im_name + '.jpg')
for h in range(0, 2592, 890):
for w in range(0, 3872, 1290):
im = image[h:h + 890, w:w + 1290]
output = tfnet.return_predict(im)
RBC = 0
WBC = 0
Platelets = 0
for prediction in output:
label = prediction['label']
confidence = prediction['confidence']
tl = (prediction['topleft']['x'], prediction['topleft']['y'])
br = (prediction['bottomright']['x'], prediction['bottomright']['y'])
height, width, _ = image.shape
center_x = int((tl[0] + br[0]) / 2)
center_y = int((tl[1] + br[1]) / 2)
center = (center_x + w, center_y + h)
radius = int((br[0] - tl[0]) / 2)
C.append(center)
R.append(radius)
L.append(label)
record = []
for i in range(0, len(C)):
center = C[i]
radius = R[i]
label = L[i]
if label == 'RBC':
color = (255, 0, 0)
elif label == 'WBC':
color = (0, 255, 0)
elif label == 'Platelets':
color = (0, 0, 255)
image = cv2.circle(image, center, radius, color, 5)
font = cv2.FONT_HERSHEY_COMPLEX
image = cv2.putText(image, label, (center[0] - 30, center[1] + 10), font, 1, color, 2)
cv2.imwrite('output/' + im_name + 'out.jpg', image)