1+ import iewrap
2+
3+ import time
4+
5+ import cv2
6+ import numpy as np
7+
8+ imgBuf = {}
9+ label = []
10+
11+ def callback (infId , output ):
12+ global imgBuf , label
13+
14+ # Draw bounding boxes and labels onto the image
15+ output = output .reshape ((100 ,7 ))
16+ img = imgBuf .pop (infId )
17+ img_h , img_w , _ = img .shape
18+ for obj in output :
19+ imgid , clsid , confidence , x1 , y1 , x2 , y2 = obj
20+ if confidence > 0.6 : # Draw a bounding box and label when confidence>0.8
21+ x1 = int (x1 * img_w )
22+ y1 = int (y1 * img_h )
23+ x2 = int (x2 * img_w )
24+ y2 = int (y2 * img_h )
25+ cv2 .rectangle (img , (x1 , y1 ), (x2 , y2 ), (0 ,255 ,255 ), thickness = 4 )
26+ cv2 .putText (img , label [int (clsid )][:- 1 ], (x1 , y1 ), cv2 .FONT_HERSHEY_PLAIN , fontScale = 4 , color = (0 ,255 ,255 ), thickness = 4 )
27+ cv2 .imshow ('result' , img )
28+ cv2 .waitKey (1 )
29+
30+ def main ():
31+ global imgBuf , label
32+ label = open ('voc_labels.txt' ).readlines ()
33+
34+ cap = cv2 .VideoCapture (0 )
35+ cap .set (cv2 .CAP_PROP_FRAME_WIDTH , 640 )
36+ cap .set (cv2 .CAP_PROP_FRAME_HEIGHT , 480 )
37+
38+ #cap = cv2.VideoCapture('../sample-videos/people-detection.mp4')
39+
40+ ie = iewrap .ieWrapper ('public/mobilenet-ssd/FP16/mobilenet-ssd.xml' , 'CPU' , 10 )
41+ ie .setCallback (callback )
42+
43+ while True :
44+ ret , img = cap .read ()
45+ if ret == False :
46+ break
47+ refId = ie .asyncInfer (img ) # Inference
48+ imgBuf [refId ]= img
49+ #time.sleep(1/30)
50+
51+ if __name__ == '__main__' :
52+ main ()
0 commit comments