Beispiel #1
0
def get_mosaic_position(img_origin,net_mosaic_pos,opt,threshold = 128 ):
    mask = run_unet(img_origin,net_mosaic_pos,size=224,use_gpu = opt.use_gpu)
    mask = impro.mask_threshold(mask,30,threshold)
    if not opt.all_mosaic_area:
        mask = impro.find_mostlikely_ROI(mask)
    x,y,size,area = impro.boundingSquare(mask,Ex_mul=opt.ex_mult)
    rat = min(img_origin.shape[:2])/224.0
    x,y,size = int(rat*x),int(rat*y),int(rat*size)
    return x,y,size,mask
Beispiel #2
0
def get_mosaic_position(img_origin, net_mosaic_pos, opt):
    h, w = img_origin.shape[:2]
    mask = run_segment(img_origin, net_mosaic_pos, size=360, gpu_id=opt.gpu_id)
    # mask_1 = mask.copy()
    mask = impro.mask_threshold(mask,
                                ex_mun=int(min(h, w) / 20),
                                threshold=opt.mask_threshold)
    if not opt.all_mosaic_area:
        mask = impro.find_mostlikely_ROI(mask)
    x, y, size, area = impro.boundingSquare(mask, Ex_mul=opt.ex_mult)
    #Location fix
    rat = min(h, w) / 360.0
    x, y, size = int(rat * x), int(rat * y), int(rat * size)
    x, y = np.clip(x, 0, w), np.clip(y, 0, h)
    size = np.clip(size, 0, min(w - x, h - y))
    # print(x,y,size)
    return x, y, size, mask
Beispiel #3
0
                    videopath,
                    opt.temp_dir + '/video2image/%05d.' + opt.tempimage_type,
                    fps=1,
                    start_time=util.second2stamp(cut_point * opt.interval),
                    last_time=util.second2stamp(opt.time))
                imagepaths = util.Traversal(opt.temp_dir + '/video2image')
                imagepaths = sorted(imagepaths)
                cnt = 0
                for i in range(opt.time):
                    img = impro.imread(imagepaths[i])
                    mask = runmodel.get_ROI_position(img,
                                                     net,
                                                     opt,
                                                     keepsize=True)[0]
                    if not opt.all_mosaic_area:
                        mask = impro.find_mostlikely_ROI(mask)
                    x, y, size, area = impro.boundingSquare(mask, Ex_mul=1)
                    if area > opt.minmaskarea and size > opt.minsize and impro.Q_lapulase(
                            img) > opt.quality:
                        cnt += 1
                if cnt == opt.time:
                    # print(second)
                    timestamps.append(
                        util.second2stamp(cut_point * opt.interval))
        util.writelog(os.path.join(opt.savedir, 'opt.txt'),
                      videopath + '\n' + str(timestamps))
        #print(timestamps)

        #generate datasets
        print('Generate datasets...')
        for timestamp in timestamps:
Beispiel #4
0
        for cut_point in range(1, int((endtime - opt.time) / opt.interval)):
            util.clean_tempfiles()
            ffmpeg.video2image(videopath,
                               './tmp/video2image/%05d.' + opt.tempimage_type,
                               fps=1,
                               start_time=util.second2stamp(cut_point *
                                                            opt.interval),
                               last_time=util.second2stamp(opt.time))
            imagepaths = util.Traversal('./tmp/video2image')
            cnt = 0
            for i in range(opt.time):
                img = impro.imread(imagepaths[i])
                mask = runmodel.get_ROI_position(img, net, opt,
                                                 keepsize=True)[0]
                if not opt.all_mosaic_area:
                    mask = impro.find_mostlikely_ROI(mask)
                x, y, size, area = impro.boundingSquare(mask, Ex_mul=1)
                if area > opt.minmaskarea and size > opt.minsize and impro.Q_lapulase(
                        img) > opt.quality:
                    cnt += 1
            if cnt == opt.time:
                # print(second)
                timestamps.append(util.second2stamp(cut_point * opt.interval))
        util.writelog(os.path.join(opt.savedir, 'opt.txt'),
                      videopath + '\n' + str(timestamps))
        #print(timestamps)

        # util.clean_tempfiles()
        # fps,endtime,height,width = ffmpeg.get_video_infos(videopath)
        # # print(fps,endtime,height,width)
        # ffmpeg.continuous_screenshot(videopath, './tmp/video2image', 1)
Beispiel #5
0
                mask = mask_drawn
            if 'irregular' in opt.mod:
                mask_irr = impro.imread(irrpaths[random.randint(0, 12000 - 1)],
                                        'gray')
                mask_irr = data.random_transform_single(
                    mask_irr, (img.shape[0], img.shape[1]))
                mask = mask_irr
            if 'network' in opt.mod:
                mask_net = runmodel.get_ROI_position(img,
                                                     net,
                                                     opt,
                                                     keepsize=True)[0]
                if opt.use_gpu != -1:
                    torch.cuda.empty_cache()
                if not opt.all_mosaic_area:
                    mask_net = impro.find_mostlikely_ROI(mask_net)
                mask = mask_net
            if opt.mod == ['drawn', 'irregular']:
                mask = cv2.bitwise_and(mask_irr, mask_drawn)
            if opt.mod == ['network', 'irregular']:
                mask = cv2.bitwise_and(mask_irr, mask_net)

                #checkandsave
                # t=threading.Thread(target=checksaveimage,args=(opt,img,mask,))
                # t.start()

                saveflag = True
                if opt.mod == ['drawn', 'irregular']:
                    x, y, size, area = impro.boundingSquare(
                        mask_drawn, random.uniform(1.2, 1.6))
                elif opt.mod == ['network', 'irregular']: