def addmosaic_img(opt,netS): path = opt.media_path print('Add Mosaic:',path) img = impro.imread(path) mask = runmodel.get_ROI_position(img,netS,opt)[0] img = mosaic.addmosaic(img,mask,opt) impro.imwrite(os.path.join(opt.result_dir,os.path.splitext(os.path.basename(path))[0]+'_add.jpg'),img)
def styletransfer_img(opt, netG): print('Style Transfer_img:', opt.media_path) img = impro.imread(opt.media_path) img = runmodel.run_styletransfer(opt, netG, img) suffix = os.path.basename(opt.model_path).replace('.pth', '').replace( 'style_', '') impro.imwrite( os.path.join( opt.result_dir, os.path.splitext(os.path.basename(opt.media_path))[0] + '_' + suffix + '.jpg'), img)
def cleanmosaic_img(opt,netG,netM): path = opt.media_path print('Clean Mosaic:',path) img_origin = impro.imread(path) x,y,size,mask = runmodel.get_mosaic_position(img_origin,netM,opt) #cv2.imwrite('./mask/'+os.path.basename(path), mask) img_result = img_origin.copy() if size != 0 : img_mosaic = img_origin[y-size:y+size,x-size:x+size] img_fake = runmodel.run_pix2pix(img_mosaic,netG,opt) img_result = impro.replace_mosaic(img_origin,img_fake,x,y,size,opt.no_feather) else: print('Do not find mosaic') impro.imwrite(os.path.join(opt.result_dir,os.path.splitext(os.path.basename(path))[0]+'_clean.jpg'),img_result)
fill_flags = -1 * np.ones(int(src_indexs[-1] / 100 * FPS) + 12, dtype=np.int64) for i in range(len(src_indexs)): match_index = match_indexs[i] adv_frame = dst_adv_frames[match_indexs[i]] start_frame = int(np.round(src_indexs[i] / 100 * FPS) - adv_frame) last_frame = int(dst_last_frames[match_index]) for j in range(last_frame): fill_flags[start_frame + j] = match_index img = cv2.imread( os.path.join('./tmp/video_imgs', '%02d' % match_index, '%05d' % (j + 1) + '.png')) impro.imwrite( os.path.join('./tmp/output_imgs', '%05d' % (start_frame + j) + '.jpg'), img) if i != (len(src_indexs) - 1) and start_frame + last_frame <= int( np.round(src_indexs[i + 1] / 100 * FPS) - adv_frame): for j in range( int(np.round(src_indexs[i + 1] / 100 * FPS) - adv_frame) - start_frame - last_frame + 1): frame = start_frame + last_frame + j fill_flags[frame] = match_index img = cv2.imread( os.path.join('./tmp/video_imgs', '%02d' % match_index, '%05d' % (last_frame) + '.png')) impro.imwrite( os.path.join('./tmp/output_imgs', '%05d' % (frame) + '.jpg'), img)
for i, imagepath in enumerate(imagepaths): x, y, size = positions[i][0], positions[i][1], positions[i][2] tmp_cnt = i while size < opt.minsize // 2: tmp_cnt = tmp_cnt - 1 x, y, size = positions[tmp_cnt][0], positions[tmp_cnt][ 1], positions[tmp_cnt][2] img = impro.resize(imgs[i][y - size:y + size, x - size:x + size], opt.outsize, interpolation=cv2.INTER_CUBIC) mask = impro.resize(masks[i][y - size:y + size, x - size:x + size], opt.outsize, interpolation=cv2.INTER_CUBIC) impro.imwrite( os.path.join(origindir, '%05d' % (i + 1) + '.jpg'), img) impro.imwrite(os.path.join(maskdir, '%05d' % (i + 1) + '.png'), mask) # x_tmp,y_tmp,size_tmp # for imagepath in imagepaths: # img = impro.imread(imagepath) # mask,x,y,halfsize,area = runmodel.get_ROI_position(img,net,opt,keepsize=True) # if halfsize>opt.minsize//4: # if not opt.all_mosaic_area: # mask_avg = impro.find_mostlikely_ROI(mask_avg) # x,y,size,area = impro.boundingSquare(mask_avg,Ex_mul=ex_mul) # img = impro.resize(imgs[i][y-size:y+size,x-size:x+size],opt.outsize,interpolation=cv2.INTER_CUBIC) # mask = impro.resize(masks[i][y-size:y+size,x-size:x+size],opt.outsize,interpolation=cv2.INTER_CUBIC) # impro.imwrite(os.path.join(origindir,'%05d'%(i+1)+'.jpg'), img) # impro.imwrite(os.path.join(maskdir,'%05d'%(i+1)+'.png'), mask)