예제 #1
0
    # cap = cv2.VideoCapture(r"C:\Users\liev\Desktop\myproject\face_recognition\test\test.mp4")
    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)
예제 #2
0
import torch, time
import net.checknet as nets
import tool.utils as utils
from PIL import Image
import numpy as np

if __name__ == '__main__':
    net = nets.P_Net(istraining=False)
    if torch.cuda.is_available():
        net = net.cuda()
    net.eval()

    net.load_state_dict(
        torch.load(
            r'C:\Users\liev\Desktop\myproject\face_recognition\params\p_params.pkl'
        ))  # 导入训练参数
    #输入图片
    img = Image.open(r"./5.jpg")

    #P网络
    start_tim = time.time()
    pboxs = utils.PnetDetect(net, img, imgshow=True)
    end_tim = time.time()

    print("pnet_time:", end_tim - start_tim)