def main(image_file): detector = Detector(weight_dir=MODEL_WEIGHT_SAVE_DIR, mode=3, min_face_size=24) input_img_full_path = TEST_INPUT_IMG_DIR + '/' + image_file output_img_full_path = TEST_OUTPUT_IMG_DIR + '/' + image_file image = cv2.imread(input_img_full_path) bbox, bboxes, landmarks = detector.predict(image) print('bboxes-shape---:', bboxes.shape) print('landmarks-shape---:', landmarks.shape) for bbox in bboxes: #print('bbox score--:',bbox[4]) #cv2.putText(image,str(np.round(bbox[4],2)),(int(bbox[0]),int(bbox[1])),cv2.FONT_HERSHEY_TRIPLEX,1,color=(255,0,255)) cv2.rectangle(image, (int(bbox[0]), int(bbox[1])), (int(bbox[2]), int(bbox[3])), (0, 0, 255)) for landmark in landmarks: #print('landmark-shape---:',landmark.shape) #print('landmark----:',landmark) for i in range(0, 5): cv2.circle(image, (int(landmark[2 * i]), int(int(landmark[2 * i + 1]))), 3, (0, 0, 255)) #break cv2.imwrite(output_img_full_path, image) cv2.imshow('yy', image) cv2.waitKey(0)
def main(input_net_name): net_name = input_net_name assert net_name in NET_NAMES images_dir = WIDER_FACE_IMG_DIR annotation_file = WIDER_FACE_ANNO_FILE out_dir = GAN_DATA_ROOT_DIR out_dir = '{}/{}'.format(out_dir, net_name) if net_name == 'r_net': mode = 1 elif net_name == 'o_net': mode = 2 #images_path images_jpg bboxes dataset = load_widerface_dataset(images_dir, annotation_file) detector = Detector(weight_dir= MODEL_WEIGHT_SAVE_DIR, mode=mode) bboxes_all = [] #p_net 一次测一张图片,注意,其返回可能会有多个,因为图片中可以包含多张面,而且还有图片金字塔 print('data img len --:',len(dataset['images_jpg'])) for img_jpg in dataset['images_jpg']: _, bboxes, _ = detector.predict(img_jpg) bboxes_all.append(bboxes) bboxes_all = np.array(bboxes_all) print('predict over---') if not os.path.exists(out_dir): os.mkdir(out_dir) detections_path = os.path.join(out_dir, 'middle_wideface_data_det.pkl') with open(detections_path, 'wb') as f: pickle.dump({ 'bboxes': bboxes_all, }, f) save_hard_examples(net_name, out_dir, dataset, detections_path)