-
Notifications
You must be signed in to change notification settings - Fork 0
/
test3.py
54 lines (46 loc) · 1.73 KB
/
test3.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
# -------------------------------------#
# Call camera detection
# -------------------------------------#
from keras.layers import Input
from yolo import YOLO
from PIL import Image
import cv2
import time
from keras.layers import Input
from yolo import YOLO
from PIL import Image
import numpy as np
import cv2
import time
import os
# Camera detection
fps = 0
yolo = YOLO()
cap = cv2.VideoCapture(2) # Create built-in camera variables
while True:
t1 = time.time()
ret, img = cap.read() # Save the img variable obtained from the camera
img = cv2.resize(img, (1280, 720), interpolation=cv2.INTER_CUBIC)
frame = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# Convert to Image
frame = Image.fromarray(np.uint8(frame))
# detect
tuxiang, zuobiao, label = yolo.detect_image(frame)
change = zuobiao
if len(zuobiao) != 0:
# coordinate calculation based on the candidate bounds,
# which is the geometric centre of the candidate bound
zuobiao = (str(zuobiao[0]) + "#" + str(zuobiao[1]) + "#" + str(zuobiao[2]) + "#" + str(
zuobiao[3]) + "#" + label).encode("utf-8")
frame = np.array(tuxiang)
# RGBtoBGR
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
fps = (fps + (1. / (time.time() - t1))+3) / 2
print("fps= %.2f" % (fps))
frame = cv2.putText(frame, "fps= %.2f" % (fps), (60, 60), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
print("zuobiao",( int((change[1]+change[3])/2),int((change[0]+change[2])/2)))
frame = cv2.putText(frame, "o",
( int((change[1]+change[3])/2),int((change[0]+change[2])/2)), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
cv2.imshow("video", frame)
cv2.waitKey(1)
yolo.close_session()