# # 关键点检测 # # 模型的下载路径:http://dlib.net/files/ # predictor = dlib.shape_predictor(r'C:\Users\14271\Desktop\del\shape_predictor_68_face_landmarks.dat') # # for det in dets: # shape = predictor(img, det) # print(shape.parts()) # # # 人脸对齐 # my_img = dlib.get_face_chip(img, shape, size=150) # # plt.imshow(my_img) # plt.show() # img_dir = r"/home/ldq/20220112_img_from_iphone/img" save_dir = r"/home/ldq/20220112_img_from_iphone/xml" detector = dlib.get_frontal_face_detector() for each_img_path in FileOperationUtil.re_all_file(img_dir, endswitch=['.jpg', '.JPG', '.png', '.PNG']): print(each_img_path) each_dete_res = DeteRes(assign_img_path=each_img_path) img = cv2.imread(each_img_path) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) dets = detector(img, 1) for each_shape in dets: each_dete_res.add_obj(x1=int(each_shape.left()), y1=int(each_shape.top()), x2=int(each_shape.right()), y2=int(each_shape.bottom()), tag='face') each_dete_res.save_to_xml(os.path.join(save_dir, FileOperationUtil.bang_path(each_img_path)[1] + '.xml'))
b.img_path = os.path.join(os.path.dirname(each_json_path), a.name + '.jpg') if not os.path.exists(b.img_path): continue if a.comments is None: continue for each_comment in a.comments: x1 = int(each_comment['x']) y1 = int(each_comment['y']) x2 = int(each_comment['width']) + x1 y2 = int(each_comment['height']) + y1 tag = str(each_comment['annotation']).split('_')[0] b.add_obj(x1, y1, x2, y2, tag=tag, conf=-1) if b.has_tag('040303021') or b.has_tag('040303022'): # 存在防振锤,需要进行复制文件 each_xml_name = os.path.split(b.file_name)[1][:-3] + 'xml' each_save_img_name = os.path.split(b.file_name)[1][:-3] + 'jpg' each_xml_path = os.path.join(save_dir, each_xml_name) each_save_img_path = os.path.join(save_dir, each_save_img_name) # print(each_xml_path) # print(each_save_img_path) b.filter_by_tags(need_tag=[ '040303021', '040303022', '040303000', '040303011', '040303031', '040303041' ])
# -*- coding: utf-8 -*- # -*- author: jokker -*- from JoTools.txkjRes.deteRes import DeteRes a = DeteRes() b = DeteRes() a.add_obj(1, 2, 3, 4, 'a') a.add_obj(2, 3, 4, 5, 'b') b.add_obj(2, 3, 4, 5, 'c') b.add_obj(2, 3, 4, 5, 'd') c = a + b a.print_as_fzc_format() print('-' * 50) b.print_as_fzc_format() print('-' * 50) c.print_as_fzc_format()
loc = res['result']['face_list'][i]['location'] x1, y1 = loc['left'], loc['top'] width, height = loc['width'], loc['height'] x2, y2 = x1 + width, y1 + height face_info.append([int(x1), int(y1), int(x2), int(y2)]) return face_info # OperateDeteRes.crop_imgs(img_dir, xml_dir=img_dir, save_dir=save_dir) # todo 测试正脸的图片 for img_path in FileOperationUtil.re_all_file( img_dir, lambda x: str(x).endswith(('.JPG', '.jpg'))): dete_res = DeteRes(assign_img_path=img_path) res = dete_face(img_path) print(res) for index, each_res in enumerate(res): x1, y1, x2, y2 = each_res dete_res.add_obj(x1=x1, y1=y1, x2=x2, y2=y2, tag='face', assign_id=index) save_path = os.path.join(save_dir, os.path.split(img_path)[1]) dete_res.draw_dete_res(save_path) time.sleep(3)
json_dir = r"C:\data\004_绝缘子污秽\val\json" a = SegmentJson() dete_res = DeteRes() for each_json_path in list( FileOperationUtil.re_all_file(json_dir, endswitch=['.json']))[20:]: print(each_json_path) a.parse_json_info(each_json_path, parse_img=True, parse_mask=True) dete_res.img = Image.fromarray(a.image_data) for each_obj in a.shapes: print(each_obj.box) box = each_obj.box dete_res.add_obj(box[0], box[1], box[2], box[3], tag=each_obj.label) b = Image.fromarray(a.mask.astype(np.uint8) * 100) b.save(r"C:\Users\14271\Desktop\del\112233.png") dete_res.draw_dete_res(r"C:\Users\14271\Desktop\del\1100.png") # a.save_mask(r"C:\Users\14271\Desktop\del\del.npy") break a.print_as_fzc_format()
# -*- coding: utf-8 -*- # -*- author: jokker -*- from JoTools.txkjRes.deteRes import DeteObj, DeteRes save_path = r"C:\Users\14271\Desktop\del.xml" a = DeteRes() a.add_obj(10, 20, 30, 40, "test", 0.5) a.add_angle_obj(10, 10, 100, 100, 30, 'hehe', 0.5) a[0].hehe = 'just test' a[0].add_new = 123222121 a[0].add_123 = '111122' a[1].test_1 = 'test1' a[1].test_2 = 'test1' a[1].test_3 = 'test1' a.save_to_xml(save_path) b = a.save_to_json() a = DeteRes(json_dict=b) print(a[0].__dict__) print(a[1].__dict__) print(a[0].add_123) print(a[1].test_1)