-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwound_predict
49 lines (46 loc) · 1.52 KB
/
wound_predict
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
# -*- coding: utf-8 -*-
"""
20190109
Created on Wed Dec 19 15:23:18 2018
@author: adi
"""
from keras.models import load_model
from keras.preprocessing import image
import numpy as np
import cv2
def pre():
classes=['擦傷','瘀青','割裂傷','抓傷']
cap = cv2.VideoCapture(0)
print('======== Load Model =========')
model=load_model("wound0103MOBILENET.h5")
print('======== Load Done =========')
#img = image.load_img("image 1.jpg", target_size=(224, 224))
'''img=cv2.imread("1.jpeg")
img=cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img.resize(224,224,3)'''
while True:
ret, img = cap.read()
img=cv2.resize(img,(224,224))
#img=cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img_tensor = image.img_to_array(img) # (height, width, channels)
img_tensor=img_tensor/255.
img_tensor = np.expand_dims(img_tensor, axis=0)
pred=model.predict(img_tensor)
cv2.imshow('Video_FR', img)
if cv2.waitKey(1)&0xFF==ord('q'):
cv2.destroyAllWindows()
break
print(pred)
if np.max(pred)>0.6:
cv2.destroyAllWindows()
break
return classes[np.argmax(pred)]
'''
img_tensor = image.img_to_array(img) # (height, width, channels)
img_tensor=img_tensor/255.
#print(img_tensor)
img_tensor = np.expand_dims(img_tensor, axis=0)
pred=model.predict(img_tensor)
print(pred)
print(classes[np.argmax(pred)])
'''