【Animation】Animating Sample Code

1. Performing a simple block-based animation 

[UIView animateWithDuration:1.0 animations:^{
          firstView.alpha = 0.0;
          secondView.alpha = 1.0;
}];

The animations in the preceding example run only once using an ease-in, ease-out animation curve.  


2.  Creating an animation block with custom options 

- (IBAction)showHideView:(id)sender
  {
      // Fade out the view right away
      [UIView animateWithDuration:1.0
          delay: 0.0
          options: UIViewAnimationOptionCurveEaseIn
animations:^{
               thirdView.alpha = 0.0;
          }
          completion:^(BOOL finished){

// Wait one second and then fade in the view
[UIView animateWithDuration:1.0
     delay: 1.0
     options:UIViewAnimationOptionCurveEaseOut
     animations:^{
        thirdView.alpha = 1.0;
     }
     completion:nil];<pre name="code" class="objc" style="font-size: 13px;">    }]; 
}


Using a completion handler is the primary way that you link multiple animations. 

3.  Performing a simple begin/commit animation (iOS 3.2  and earlier)

[UIView beginAnimations:@"ToggleViews" context:nil];
[UIView setAnimationDuration:1.0];
// Make the animatable changes.
firstView.alpha = 0.0;
secondView.alpha = 1.0;
// Commit the changes and perform the animation.
[UIView commitAnimations];


4.  Nesting animations that have different configurations 

[UIView animateWithDuration:1.0
          delay: 1.0
          options:UIViewAnimationOptionCurveEaseOut
          animations:^{
              aView.alpha = 0.0;
// Create a nested animation that has a different
              // duration, timing curve, and configuration.
              [UIView animateWithDuration:0.2
                   delay:0.0
                   options: UIViewAnimationOptionOverrideInheritedCurve |
                            UIViewAnimationOptionCurveLinear |
                            UIViewAnimationOptionOverrideInheritedDuration |
                            UIViewAnimationOptionRepeat |
                            UIViewAnimationOptionAutoreverse
                   animations:^{
                        [UIView setAnimationRepeatCount:2.5];
                        anotherView.alpha = 0.0;
                   }
                   completion:nil];
          }
          completion:nil];

The UIViewAnimationOptionOverrideInheritedCurveandUIViewAnimationOptionOverrideInheritedDurationkeys used in the nested animation block allowthe curve and duration values from the first animation to be modified for the second animation. If these keyswere not present, the duration and curve of the outer animation block would be used instead. 


5.  Changing the Subviews of a View 

- (IBAction)displayNewPage:(id)sender
{
    [UIView transitionWithView:self.view
        duration:1.0
        options:UIViewAnimationOptionTransitionCurlUp
        animations:^{
            currentTextView.hidden = YES;
            swapTextView.hidden = NO;
        }
        completion:^(BOOL finished){
            // Save the old text and then swap the views.
            [self saveNotes:temp];
            UIView*    temp = currentTextView;
            currentTextView = swapTextView;
            swapTextView = temp;
}]; }



6. 

Replacing a View with a Different View 

- (IBAction)toggleMainViews:(id)sender {
    [UIView transitionFromView:(displayingPrimary ? primaryView : secondaryView)
:
}
toView:(displayingPrimary ? secondaryView : primaryView)
duration:1.0
options:(displayingPrimary ? UIViewAnimationOptionTransitionFlipFromRight
            UIViewAnimationOptionTransitionFlipFromLeft)
completion:^(BOOL finished) {
    if (finished) {
        displayingPrimary = !displayingPrimary;
} }];







# 3D Cinemagraphy from a Single Image (CVPR 2023) [Xingyi Li](https://scholar.google.com/citations?user=XDKQsvUAAAAJ&hl)<sup>1,3</sup>, [Zhiguo Cao](http://english.aia.hust.edu.cn/info/1085/1528.htm)<sup>1</sup>, [Huiqiang Sun](https://huiqiang-sun.github.io/)<sup>1</sup>, [Jianming Zhang](https://jimmie33.github.io/)<sup>2</sup>, [Ke Xian](https://kexianhust.github.io/)<sup>3*</sup>, [Guosheng Lin](https://guosheng.github.io/)<sup>3</sup> <sup>1</sup>Huazhong University of Science and Technology, <sup>2</sup>Adobe Research, <sup>3</sup>S-Lab, Nanyang Technological University [Project](https://xingyi-li.github.io/3d-cinemagraphy/) | [Paper](https://github.com/xingyi-li/3d-cinemagraphy/blob/main/pdf/3d-cinemagraphy-paper.pdf) | [arXiv](https://arxiv.org/abs/2303.05724) | [Video](https://youtu.be/sqCy7ffTEEY) | [Supp](https://github.com/xingyi-li/3d-cinemagraphy/blob/main/pdf/3d-cinemagraphy-supp.pdf) | [Poster](https://github.com/xingyi-li/3d-cinemagraphy/blob/main/pdf/3d-cinemagraphy-poster.pdf) This repository contains the official PyTorch implementation of our CVPR 2023 paper "3D Cinemagraphy from a Single Image". ## Installation ``` git clone https://github.com/xingyi-li/3d-cinemagraphy.git cd 3d-cinemagraphy bash requirements.sh ``` ## Usage Download pretrained models from [Google Drive](https://drive.google.com/file/d/1ROxvB7D-vNYl4eYmIzZ5Gitg84amMd19/view?usp=sharing), then unzip and put them in the directory `ckpts`. To achieve better motion estimation results and controllable animation, here we provide the controllable version. Firstly, use [labelme](https://github.com/wkentaro/labelme) to specify the target regions (masks) and desired movement directions (hints): ```shell conda activate 3d-cinemagraphy cd demo/0/ labelme image.png ``` A screenshot here: ![labelme](assets/labelme.png) It is recommended to specify **short** hints rather than long hints to avoid artifacts. Please follow [labelme](https://github.com/wkentaro/labelme) for detailed instructions if needed. After that, we can obtain an image.json file. Our next step is to convert the annotations stored in JSON format into datasets that can be used by our method: ```shell labelme_json_to_dataset image.json # this will generate a folder image_json cd ../../ python scripts/generate_mask.py --inputdir demo/0/image_json ``` We now can create 3D cinemagraphs according to your preference: ```shell python demo.py -c configs/config.yaml --input_dir demo/0/ --ckpt_path ckpts/model_150000.pth --flow_scale 1.0 --ds_factor 1.0 ``` - `input_dir`: input folder that contains src images. - `ckpt_path`: checkpoint path. - `flow_scale`: scale that used to control the speed of fluid, > 1.0 will slow down the fluid. - `ds_factor`: downsample factor for the input images. Results will be saved to the `input_dir/output`. ## Known issues - Due to the limited size of the training dataset, the intermediate frame may occasionally experience flickering. - The utilization of a fixed distance threshold in agglomerative clustering within the disparity space can occasionally result in the presence of visible boundaries between different layers. - We may sometimes see artifacts when the fluid is moving very fast. You can either slow down the fluid by increasing the `flow_scale` or try to specify short hints rather than long hints, to avoid artifacts. - The motion estimation module occasionally generates motion fields that do not perfectly align with the desired preferences. ## Citation If you find our work useful in your research, please consider to cite our paper: ``` @InProceedings{li2023_3dcinemagraphy, author = {Li, Xingyi and Cao, Zhiguo and Sun, Huiqiang and Zhang, Jianming and Xian, Ke and Lin, Guosheng}, title = {3D Cinemagraphy From a Single Image}, booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)}, month = {June}, year = {2023}, pages = {4595-4605} } ``` ## Relevant works - [Animating Pictures with Eulerian Motion Fields](https://openaccess.thecvf.com/content/CVPR2021/papers/Holynski_Animating_Pictures_With_Eulerian_Motion_Fields_CVPR_2021_paper.pdf), CVPR 2021 - [Controllable Animation of Fluid Elements in Still Images](https://openaccess.thecvf.com/content/CVPR2022/papers/Mahapatra_Controllable_Animation_of_Fluid_Elements_in_Still_Images_CVPR_2022_paper.pdf), CVPR 2022 - [Simulating Fluids in Real-World Still Images](https://arxiv.org/pdf/2204.11335), arXiv 2022 - [3D Photography using Context-aware Layered Depth Inpainting](https://openaccess.thecvf.com/content_CVPR_2020/papers/Shih_3D_Photography_Using_Context-Aware_Layered_Depth_Inpainting_CVPR_2020_paper.pdf), CVPR 2020 - [3D Photo Stylization: Learning to Generate Stylized Novel Views from a Single Image](https://openaccess.thecvf.com/content/CVPR2022/papers/Mu_3D_Photo_Stylization_Learning_To_Generate_Stylized_Novel_Views_From_CVPR_2022_paper.pdf), CVPR 2022 - [3D Moments from Near-Duplicate Photos](https://openaccess.thecvf.com/content/CVPR2022/papers/Wang_3D_Moments_From_Near-Duplicate_Photos_CVPR_2022_paper.pdf), CVPR 2022 - [3D Video Loops from Asynchronous Input](https://openaccess.thecvf.com/content/CVPR2023/papers/Ma_3D_Video_Loops_From_Asynchronous_Input_CVPR_2023_paper.pdf), CVPR 2023 ## Acknowledgement This code borrows heavily from [3D Moments](https://github.com/google-research/3d-moments) and [SLR-SFS](https://github.com/simon3dv/SLR-SFS). We thank the respective authors for open sourcing their methods.
最新发布
06-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值