示例#1
0
def my_read_frame(frame_dir, transforms, scale_size):
    """
    read a single frame & preprocess
    """
    frame = cv2.imread(frame_dir, cv2.IMREAD_COLOR)
    ori_h,ori_w,_ = frame.shape
    # scale, makes height & width multiples of 64
    if(len(scale_size) == 1):
        if(ori_h > ori_w):
        	tw = scale_size[0]
        	th = (tw * ori_h) / ori_w
        	th = int((th // 64) * 64)
        else:
        	th = scale_size[0]
        	tw = (th * ori_w) / ori_h
        	tw = int((tw // 64) * 64)
    else:
        tw = scale_size[1]
        th = scale_size[0]
    frame = cv2.resize(frame, (640,640))
    img = copy.deepcopy(frame)
    img = np.array(img, dtype=np.float32)
    img = img / 255
    meanval = [0.485, 0.456, 0.406]
    std = [0.229, 0.224, 0.225]
    img = np.subtract(img, np.array(meanval, dtype=np.float32))
    img = img / std
    img = img.transpose((2, 0, 1))
    img = torch.from_numpy(img).float()
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2LAB)

    pair = [frame, frame]
    transformed = list(transforms(*pair))
    return transformed[0].cuda().unsqueeze(0), ori_h, ori_w, img.cuda().unsqueeze(0)
示例#2
0
def read_frame(frame_dir, transforms, scale_size):
    """
    read a single frame & preprocess
    """
    frame = cv2.imread(frame_dir)
    ori_h,ori_w,_ = frame.shape
    # scale, makes height & width multiples of 64
    if(len(scale_size) == 1):
        if(ori_h > ori_w):
        	tw = scale_size[0]
        	th = (tw * ori_h) / ori_w
        	th = int((th // 64) * 64)
        else:
        	th = scale_size[0]
        	tw = (th * ori_w) / ori_h
        	tw = int((tw // 64) * 64)
    else:
        tw = scale_size[1]
        th = scale_size[0]
    frame = cv2.resize(frame, (tw,th))
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2LAB)

    pair = [frame, frame]
    transformed = list(transforms(*pair))
    return transformed[0].cuda().unsqueeze(0), ori_h, ori_w
示例#3
0
文件: utils.py 项目: DuckerDuck/UVC
def read_frame(frame_dir, transforms):
    frame = cv2.imread(frame_dir)
    ori_h, ori_w, _ = frame.shape
    if (ori_h > ori_w):
        tw = ori_w
        th = (tw * ori_h) / ori_w
        th = int((th // 64) * 64)
    else:
        th = ori_h
        tw = (th * ori_w) / ori_h
        tw = int((tw // 64) * 64)
    #h = (ori_h // 64) * 64
    #w = (ori_w // 64) * 64
    frame = cv2.resize(frame, (tw, th))
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2LAB)

    pair = [frame, frame]
    transformed = list(transforms(*pair))
    return transformed[0].cuda().unsqueeze(0), ori_h, ori_w