cap = cv2.VideoCapture(0) count = 0 while cap.isOpened(): ret, frame = cap.read() if ret: count += 1 # if count % 1 == 0: # 转换通道, 转成Image 格式 b, g, r = cv2.split(frame) img = cv2.merge([r, g, b]) img = Image.fromarray(img.astype(np.uint8)) # P网络 pboxs = utils.PnetDetect(pnet, img, imgshow=False) # R网络 rboxs = utils.RnetDetect(rnet, img, pboxs, imgshow=False) # O网络 oboxs = utils.OnetDetect(onet, img, rboxs, imgshow=True, show_conf=False, isuse=True) img = np.array(img, dtype=np.uint8) # #转换通道BGR r, g, b = cv2.split(img) img = cv2.merge([b, g, r]) cv2.imshow("img", img) # else: # cv2.imshow("img", frame)
rnet = nets.R_Net(istraining=False) if torch.cuda.is_available(): pnet = pnet.cuda() rnet = rnet.cuda() pnet.eval() rnet.eval() pnet.load_state_dict( torch.load( r'C:\Users\liev\Desktop\myproject\face_recognition\params\p_params.pkl' )) # 导入训练参数 rnet.load_state_dict( torch.load( r'C:\Users\liev\Desktop\myproject\face_recognition\params\r_params.pkl' )) # 导入训练参数 #输入图片 img = Image.open( r"C:\Users\liev\Desktop\data\face_match_pic\14ce36d3d539b6009c2f88f9ea50352ac75cb79f.jpg" ) # P网络 start_tim = time.time() pboxs = utils.PnetDetect(pnet, img, imgshow=False) pnet_tim = time.time() # R网络 rboxs = utils.RnetDetect(rnet, img, pboxs, imgshow=True, show_conf=False) rnet_tim = time.time() print("pnet_time:", pnet_tim - start_tim, "rnet_time:", rnet_tim - pnet_tim)