目前,美颜sdk在对人像进行美型美体等编辑处理的时候,想要保证背景不受影响,是比较困难的,如果需要在手机端上进行处理,难度更大,主要有以下几点:
一、难点分析
1、拍摄背景多变,背景图像内容复杂,矫正算法要适用各种场景,这给算法的适用性带来了极大的挑战。
2、用户在做美型时,可能会多项美型效果叠加。例如用户在脸部美型的时候可能叠加了“小头”、“瘦脸”、“调整太阳穴”、“调整下巴”等多项美型操作。很难用统一的规则来矫正多项美型功能叠加后导致的背景扭曲。
3、当用户在手机上调整美型程度大小的时候,用户需要实时预览美型以及矫正后的效果,所以矫正算法需要实时处理,这对算法的性能要求会非常高。
二、算法解释
关于背景扭曲矫正算法的解释,为了更加清晰,小编会用几个关键点给大家捋一下:
1、输入原图。
2、美颜sdk人脸特征点检测、背景图像网格划分、线段检测。
3、综合第二点判断线段在三角网格的分布。
4、根据第三点来对处理做出判断:利用斜率保持约束建立优化方程或者利用三角形形状保持约束建立优化方程。
5、建立整体最优化目标函数。
6、对应三角形仿射变换。
三、代码分析
//
// MHOpenDemoTests.m
// MHOpenDemoTests
//
// Created by Apple on 2021/5/31.
//
//
//
#import <XCTest/XCTest.h>
@interface MHOpenDemoTests : XCTestCase
@end
@implementation MHOpenDemoTests
-
(void)setUp {
// Put setup code here. This method is called before the invocation of each test method in the class.
} -
(void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
} -
(void)testExample {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
} -
(void)testPerformanceExample {
// This is an example of a performance test case.
[self measureBlock:^{
// Put the code you want to measure the time of here.
}];
}
@end