DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Beyond Manual Mapping: AI-Orchestrated Governance for Hybrid Cloud
  • Every Generation Fears the Machine. Here Is How the AI Job Panic Usually Ends
  • AI Agents Need an Identity Plane: Rethinking Enterprise Authorization for Autonomous Software
  • Applying Microservices Lessons to Multi-Agent AI Systems

Trending

  • AI Agents and Frontier Models: Insights From The Neuron
  • PII Detection Before RAG Ingestion: Screening Documents in C#
  • Why AI Agents Need a Shared Enterprise Ontology
  • SSRF Prevention in C#: Securing File Imports From User-Supplied URLs

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. AI/ML
  4. How to Animate a Picture by Leveraging the AI Algorithms

How to Animate a Picture by Leveraging the AI Algorithms

This tutorial explains the process of animating a picture by leveraging AI algorithms. Read below to learn how to do this yourself!

By 
Jackson Jiang
·
Jan. 21, 22 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
4.4K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Ever wondered how to animate a static image?  Wouldn't it be fun to make the facial expressions in the photos move? Such a function adds authentic facial expressions to an image of faces by leveraging the AI algorithms such as face detection, face key point detection, facial expression feature extraction, and facial expression animation. Impressive stuff, right? Let's move on and see how this capability can be integrated.

Integration Procedure

Preparations:

  • Configuring App Information in AppGallery Connect
  • Integrating the HMS Core SDK
  • Configuring Obfuscation Scripts
  • Adding Permission

For more details, we can check this document.

Configuring a Video Editing Project

1. Set the App Authentication Information 

You can set the information through an API key or access token.

Use the setAccessToken method to set an access token during initialization when the app is started. The access token needs to be set only once.

 
MediaApplication.getInstance().setAccessToken("your access token");


Use the setApiKey method to set an API key during initialization when the app is started. The API key needs to be set only once.

 
MediaApplication.getInstance().setApiKey("your ApiKey");


2. Set a License ID

This ID is used to manage your usage quotas, so ensure that the ID is unique.

 
MediaApplication.getInstance().setLicenseId("License ID");


2.1 Initialize the Running Environment for Huaweivideoeditor 

When creating a video editing project, first create a HuaweiVideoEditor object and initialize its running environment. When exiting a video editing project, release the HuaweiVideoEditor object.

Create a HuaweiVideoEditor object.

 
HuaweiVideoEditor editor = HuaweiVideoEditor.create(getApplicationContext());


Specify the position for the preview area.

This area renders video images, which is implemented by creating SurfaceView in the fundamental capability SDK. Ensure that the preview area position on your app is specified before creating this area.

 
<LinearLayout    
    android:id="@+id/video_content_layout"    
    android:layout_width="0dp"    
    android:layout_height="0dp"    
    android:background="@color/video_edit_main_bg_color"    
    android:gravity="center"    
    android:orientation="vertical" />
// Specify the preview area position.
LinearLayout mSdkPreviewContainer = view.findViewById(R.id.video_content_layout);

// Set the layout of the preview area.
editor.setDisplay(mSdkPreviewContainer);


Initialize the running environment. If the license verification fails, LicenseException is thrown.

After the HuaweiVideoEditor object is created, it has not occupied any system resource. You need to manually set the time for initializing the running environment of the object. Then, necessary threads and timers will be created in the fundamental capability SDK.

 
try {
        editor.initEnvironment();
   } catch (LicenseException error) { 
        SmartLog.e(TAG, "initEnvironment failed: " + error.getErrorMsg());    
        finish();
        return;
   }


2.2 Add a Video or Image

Create a video lane and add a video or image to the lane using the file path.

 
// Obtain the HVETimeLine object.
HVETimeLine timeline = editor.getTimeLine();

// Create a video lane.
HVEVideoLane videoLane = timeline.appendVideoLane();

// Add a video to the end of the video lane.
HVEVideoAsset videoAsset = vidoeLane.appendVideoAsset("test.mp4");

// Add an image to the end of the video lane.
HVEImageAsset imageAsset = vidoeLane.appendImageAsset("test.jpg");


2.3 Integrating the Moving Picture Capability

 
// Add the moving picture effect.
videoAsset.addFaceReenactAIEffect(new HVEAIProcessCallback() {
        @Override
        public void onProgress(int progress) {
        // Handling progress.
        }

        @Override
        public void onSuccess() {
        // Handling success.
        }

        @Override
        public void onError(int errorCode, String errorMessage) {
        // Handling failure.
        }
    });

// Remove the moving picture effect.
videoAsset.removeFaceReenactAIEffect();


AI

Opinions expressed by DZone contributors are their own.

Related

  • Beyond Manual Mapping: AI-Orchestrated Governance for Hybrid Cloud
  • Every Generation Fears the Machine. Here Is How the AI Job Panic Usually Ends
  • AI Agents Need an Identity Plane: Rethinking Enterprise Authorization for Autonomous Software
  • Applying Microservices Lessons to Multi-Agent AI Systems

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook