Prerequisites
- A working iOS quickstart
- Advanced filters enabled for the project
- A bundled image or local video URL
Replace with an image
NosmaiBackgroundSegmentationConfig *config =
[[NosmaiBackgroundSegmentationConfig alloc] init];
config.mode = NosmaiBackgroundSegmentationModeImage;
config.replacementImage = [UIImage imageNamed:@"studio_background"];
[[NosmaiCore shared].effects setBackgroundSegmentation:config];
For a color, use NosmaiBackgroundSegmentationModeColor and set replacementColor. For a looping video, use NosmaiBackgroundSegmentationModeVideo and a readable local replacementVideoURL.
Change or clear it
Apply another configuration to switch the background. Clear manual segmentation when leaving the feature:
[[NosmaiCore shared].effects clearBackgroundSegmentation];
Quality guidance
Use a well-lit subject, a background that contrasts with hair and clothing, and an asset near the preview aspect ratio. Low light, motion blur, transparent objects, and heavy occlusion can soften the segmentation edge.
Verify it worked
The subject should remain visible while the source background is replaced. Rotate the device and test both cameras before release.
Common errors
| Symptom | Cause | Fix |
|---|---|---|
| Image does not appear | Asset was not added to the application bundle | Check target membership and imageNamed: result |
| Video does not start | URL is remote or unreadable | Copy the supported video into a readable local URL |
| Edge quality is unstable | Lighting or motion is unsuitable | Improve lighting, reduce motion blur, and test at 720p |