def main(): if not os.path.exists(mp4): print("mp4 not exists, please check: %s" % mp4) cap = cv.VideoCapture(mp4) my_graph = ai.Graph(model_path) while True: success, bgr_img = cap.read() if bgr_img is None: break img = cv.resize(bgr_img, (resize_w, resize_h)) print("start") #推理结果 result_list = my_graph.Inference_single(img) if not result_list: print("get no result") return h, w = bgr_img.shape[0], bgr_img.shape[1] solution = (h, w) # 后处理 detection_result_list = ai.SSDPostProcess(result_list, solution, 0.5, CLASSES) for result in detection_result_list: cv.rectangle(bgr_img, (result.lt.x,result.lt.y) , (result.rb.x, result.rb.y), (0,255,0)) p3 = (max(result.lt.x, 15), max(result.lt.y, 15)) cv.putText(bgr_img, result.result_text, p3, cv.FONT_ITALIC, 0.6, (0, 255, 0), 1) print(result.result_text) print("over")
def predict(raw_q, pred_q): my_graph = ai.Graph(model_path) while True: raw_img = raw_q.get() raw_img = cv2.resize(raw_img, img_shape) result_list = my_graph.Inference(raw_img) if not result_list: print("get no result") return h, w = raw_img.shape[0], raw_img.shape[1] solution = (h, w) detection_result_list = ai.SSDPostProcess(result_list[0], solution, 0.5, CLASSES) for result in detection_result_list: pred_q.put(result.result_text)
def combine_images(queue_list, cam_addrs, img_shape): my_graph = ai.Graph(model_path) num_cameras = len(queue_list) while True: imgs = [cv2.resize(q.get(), img_shape) for q in queue_list] imgs_list = [] for num in range(num_cameras): imgs_list.append(imgs[num]) #ai/graph Inference(self, input_data) result_list = my_graph.Inference(imgs_list) if not result_list: print("get no result") return h, w = imgs[0].shape[0], imgs[1].shape[1] solution = (h, w) for num in range(num_cameras): detection_result_list = ai.SSDPostProcess(result_list[num], solution, 0.5, CLASSES) for result in detection_result_list: global t2 t2 = time.time() print(result.result_text, cam_addrs[num], t2 - t1)
def main(): bgr_img = cv.imread(img_path) img = cv.resize(bgr_img, (resize_w, resize_h)) my_graph = ai.Graph(model_path) result_list = my_graph.Inference_single(img) if not result_list: print("get no result") return # print(bgr_img.shape) h, w = bgr_img.shape[0], bgr_img.shape[1] solution = (h, w) # 后处理 detection_result_list = ai.SSDPostProcess(result_list, solution, 0.5, CLASSES) for result in detection_result_list: cv.rectangle(bgr_img, (result.lt.x,result.lt.y) , (result.rb.x, result.rb.y), (0,255,0)) p3 = (max(result.lt.x, 15), max(result.lt.y, 15)) cv.putText(bgr_img, result.result_text, p3, cv.FONT_ITALIC, 0.6, (0, 255, 0), 1) print(result.result_text) print("over")
def main(): camera_width = 1280 camera_height = 720 presenter_config = './face_detection.conf' cap = camera.Camera(id=0, fps=20, width=camera_width, height=camera_height, format=camera.CAMERA_IMAGE_FORMAT_YUV420_SP) if not cap.IsOpened(): print("Open camera 0 failed") return dvpp_handle = dvpp_process.DvppProcess(camera_width, camera_height) graph = ai.Graph('./model/face_detection_rgb.om') chan = presenteragent.OpenChannel(presenter_config) if chan == None: print("Open presenter channel failed") return while True: yuv_img = cap.Read() orig_image = dvpp_handle.Yuv2Jpeg(yuv_img) yuv_img = yuv_img.reshape((1080, 1280)) img = cv.cvtColor(yuv_img, cv.COLOR_YUV2RGB_I420) img = cv.resize(img, (300, 300)) result = graph.Inference(img) detection_list = ai.SSDPostProcess(result, (camera_height, camera_width), 0.9, ['background', 'face']) chan.SendDetectionData(camera_width, camera_height, orig_image.tobytes(), detection_list)