Skip to main content
Version: 6.0

Virtual background

In video calls, you can use the virtual background feature to either blur the background or replace it with an image. This page describes how to use the virtual background feature.

Supported call typeMinimum SDK version
1-to-1 call, group call (conference)PlanetKit 6.0
Warning

Applying the virtual background effect increases CPU usage.

Overview

The CameraController class provides APIs for the virtual background feature. To get the CameraController object to set the virtual background, use PlanetKitManager::GetCameraController().

PlanetKit::PlanetKitManagerPtr pPlanetKitManager = PlanetKit::PlanetKitManager::GetInstance();
PlanetKit::CameraControllerPtr pCameraController = pPlanetKitManager->GetCameraController();

Set a blurred background

To apply a blur effect to the background, call the SetVirtualBackgroundWithBlur() method.

float blurRadius = 15.0;
pCameraController->SetVirtualBackgroundWithBlur(blurRadius);

The SetVirtualBackgroundWithBlur() method accepts a radius as an argument, which determines the radius for the Gaussian blur applied to the virtual background. The default value of the radius is 15.0, and the recommended range of the setting value is between 1.0 and 25.0. A larger radius results in a blurrier result.

Set an image background

To replace the background with an image, call the SetVirtualBackgroundWithImage() method with a PlanetKit::Image object as an argument.

std::wstring virtualBackgroundPath = L"<PATH_TO_BACKGROUND_IMAGE>";
auto image = PlanetKit::Image::Create(virtualBackgroundPath.c_str());
if (image.HasValue()) {
pCameraController->SetVirtualBackgroundWithImage(*image);
}

Get the virtual background type

To get the type of the virtual background currently in use, call the GetCurrentVirtualBackgroundType() method. This method returns a PlanetKit::EVirtualBackgroundType, which can be PLNK_VIRTUAL_BACKGROUND_NONE, PLNK_VIRTUAL_BACKGROUND_BLUR, or PLNK_VIRTUAL_BACKGROUND_IMAGE.

PlanetKit::EVirtualBackgroundType backgroundType;
backgroundType = pCameraController->GetCurrentVirtualBackgroundType();

Clear the virtual background

To clear the virtual background, call the ClearVirtualBackground() method.

pCameraController->ClearVirtualBackground();

APIs related to the virtual background function are as follows.