适配 整形
This commit is contained in:
parent
a3a7ab7f56
commit
cfa7fcd7aa
|
@ -653,6 +653,14 @@ Filter::Property* Filter::_getProperty(const std::string& name) {
|
|||
return &_stringProperties[name];
|
||||
}
|
||||
|
||||
if (_vec2ArrayProperties.find(name) != _vec2ArrayProperties.end()) {
|
||||
return &_vec2ArrayProperties[name];
|
||||
}
|
||||
|
||||
if (_vec2Properties.find(name) != _vec2Properties.end()) {
|
||||
return &_vec2Properties[name];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -170,6 +170,13 @@ namespace Opipe
|
|||
_olaBeautyFilter->setProperty("slim", slimFactor);
|
||||
}
|
||||
}
|
||||
|
||||
void FaceMeshBeautyRender::setEye(float eyeFactor) {
|
||||
_eyeFactor = eyeFactor;
|
||||
if (_olaBeautyFilter) {
|
||||
_olaBeautyFilter->setProperty("eye", eyeFactor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -115,7 +115,21 @@ namespace Opipe
|
|||
|
||||
/// 美白
|
||||
virtual float getWhitening() = 0;
|
||||
|
||||
|
||||
/// 瘦脸
|
||||
virtual float getSlim() = 0;
|
||||
|
||||
virtual float getEye() = 0;
|
||||
|
||||
/// 瘦鼻
|
||||
virtual float getNose() = 0;
|
||||
|
||||
virtual void setSlim(float slim) = 0;
|
||||
|
||||
|
||||
virtual void setNose(float nose) = 0;
|
||||
|
||||
virtual void setEye(float eye) = 0;
|
||||
|
||||
/// 磨皮
|
||||
/// @param smoothing 磨皮 0.0 - 1.0
|
||||
|
|
|
@ -290,9 +290,8 @@ namespace Opipe
|
|||
facePoints.emplace_back( _lastLandmark.landmark(i).x(), _lastLandmark.landmark(i).y());
|
||||
}
|
||||
Log("FaceMeshModule", "检测到人脸输完毕");
|
||||
} else {
|
||||
_render->setFacePoints(facePoints);
|
||||
}
|
||||
_render->setFacePoints(facePoints);
|
||||
return textureInfo;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,20 +96,42 @@ namespace Opipe
|
|||
return _render->getWhitening();
|
||||
}
|
||||
|
||||
float getEye() override {
|
||||
return _render->getEye();
|
||||
}
|
||||
|
||||
float getSlim() override {
|
||||
return _render->getFace();
|
||||
}
|
||||
|
||||
float getNose() override {
|
||||
return _render->getNose();
|
||||
}
|
||||
|
||||
/// 磨皮
|
||||
/// @param smoothing 磨皮 0.0 - 1.0
|
||||
void setSmoothing(float smoothing) {
|
||||
void setSmoothing(float smoothing) override {
|
||||
_render->setSmoothing(smoothing);
|
||||
}
|
||||
|
||||
|
||||
/// 美白
|
||||
/// @param whitening 美白 0.0 - 1.0
|
||||
void setWhitening(float whitening) {
|
||||
void setWhitening(float whitening) override {
|
||||
_render->setWhitening(whitening);
|
||||
}
|
||||
|
||||
void setEye(float eye) override {
|
||||
_render->setEye(eye);
|
||||
}
|
||||
|
||||
void setSlim(float slim) override {
|
||||
_render->setFaceSlim(slim);
|
||||
}
|
||||
|
||||
void setNose(float nose) override {
|
||||
_render->setNoseFactor(nose);
|
||||
}
|
||||
|
||||
OpipeDispatch* currentDispatch() {
|
||||
return _dispatch.get();
|
||||
}
|
||||
|
|
|
@ -225,6 +225,12 @@ namespace Opipe
|
|||
return angle;
|
||||
}
|
||||
|
||||
Vector2 FaceDistortionFilter::_positionAt(int index) {
|
||||
float x = (_facePoints[index].x - 0.5) * 2.0;
|
||||
float y = (_facePoints[index].y - 0.5) * 2.0;
|
||||
return Vector2(x, y);
|
||||
}
|
||||
|
||||
void FaceDistortionFilter::setUniform()
|
||||
{
|
||||
if (_facePoints.size() > 60)
|
||||
|
@ -236,15 +242,14 @@ namespace Opipe
|
|||
_filterProgram->setUniformValue("aspectRatio",
|
||||
height /
|
||||
width);
|
||||
|
||||
_filterProgram->setUniformValue("eye", _eye);
|
||||
_filterProgram->setUniformValue("slim", _slim);
|
||||
_filterProgram->setUniformValue("nose", _nose);
|
||||
//左眼放大
|
||||
{
|
||||
Vector2 point1 = Vector2(_facePoints[362].x, _facePoints[362].y);
|
||||
Vector2 point2 = Vector2(_facePoints[263].x, _facePoints[263].y);
|
||||
Vector2 point3 = Vector2(_facePoints[417].x, _facePoints[417].y);
|
||||
Vector2 point1 = _positionAt(362);
|
||||
Vector2 point2 = _positionAt(263);
|
||||
Vector2 point3 = _positionAt(417);
|
||||
Vector2 center = point1.getCenter(point2);
|
||||
float distance = center.distance(point3);
|
||||
addPoint(center, distance / 2, distance / 2, 0.3, 1, 0.0f, 0.0f, 1);
|
||||
|
@ -252,9 +257,9 @@ namespace Opipe
|
|||
|
||||
//右眼放大
|
||||
{
|
||||
Vector2 point1 = Vector2(_facePoints[33].x, _facePoints[33].y);
|
||||
Vector2 point2 = Vector2(_facePoints[133].x, _facePoints[133].y);
|
||||
Vector2 point3 = Vector2(_facePoints[193].x, _facePoints[193].y);
|
||||
Vector2 point1 = _positionAt(33);
|
||||
Vector2 point2 = _positionAt(133);
|
||||
Vector2 point3 = _positionAt(193);
|
||||
Vector2 center = point1.getCenter(point2);
|
||||
float distance = center.distance(point3);
|
||||
addPoint(center, distance / 2, distance / 2, 0.3, 1, 0.0f, 0.0f, 1);
|
||||
|
@ -262,10 +267,10 @@ namespace Opipe
|
|||
//瘦左脸
|
||||
{
|
||||
|
||||
Vector2 point1 = Vector2(_facePoints[136].x, _facePoints[136].y);
|
||||
Vector2 point2 = Vector2(_facePoints[19].x, _facePoints[19].y);
|
||||
Vector2 point3 = Vector2(_facePoints[234].x, _facePoints[234].y);
|
||||
Vector2 point4 = Vector2(_facePoints[152].x, _facePoints[152].y);
|
||||
Vector2 point1 = _positionAt(136);
|
||||
Vector2 point2 = _positionAt(19);
|
||||
Vector2 point3 = _positionAt(234);
|
||||
Vector2 point4 = _positionAt(152);
|
||||
|
||||
float angle = getRadius(point2, point1);
|
||||
addPoint(point1, point1.distance(point3), point1.distance(point4), 0.02, 2, angle,
|
||||
|
@ -274,10 +279,10 @@ namespace Opipe
|
|||
}
|
||||
//瘦右脸
|
||||
{
|
||||
Vector2 point1 = Vector2(_facePoints[379].x, _facePoints[379].y);
|
||||
Vector2 point2 = Vector2(_facePoints[19].x, _facePoints[19].y);
|
||||
Vector2 point3 = Vector2(_facePoints[454].x, _facePoints[454].y);
|
||||
Vector2 point4 = Vector2(_facePoints[152].x, _facePoints[152].y);
|
||||
Vector2 point1 = _positionAt(379);
|
||||
Vector2 point2 = _positionAt(19);
|
||||
Vector2 point3 = _positionAt(454);
|
||||
Vector2 point4 = _positionAt(152);
|
||||
|
||||
float angle = getRadius(point2, point1);
|
||||
addPoint(point1, point1.distance(point3), point1.distance(point4), 0.02, 2, angle,
|
||||
|
|
|
@ -70,7 +70,9 @@ namespace Opipe
|
|||
float _u_min[20];
|
||||
float _u_max[20];
|
||||
int _types[20];
|
||||
float _u_facePoints[212];
|
||||
float _u_facePoints[980];
|
||||
|
||||
Vector2 _positionAt(int index);
|
||||
|
||||
private:
|
||||
void generateDistoritionVBO(int numX, int numY, const GLfloat *imageTexUV);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="vhS-oS-Fej">
|
||||
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="vhS-oS-Fej">
|
||||
<rect key="frame" x="55" y="632" width="304" height="31"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="300" id="YLm-AJ-oyY"/>
|
||||
|
@ -26,12 +26,81 @@
|
|||
<action selector="beautyChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="j3u-PR-SZh"/>
|
||||
</connections>
|
||||
</slider>
|
||||
<slider opaque="NO" tag="1" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="Qqv-lK-sGM">
|
||||
<rect key="frame" x="55" y="703" width="304" height="31"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="300" id="RfD-NJ-btk"/>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="300" id="YrT-Ue-dTy"/>
|
||||
</constraints>
|
||||
<connections>
|
||||
<action selector="beautyChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="nM1-Gf-7Zs"/>
|
||||
</connections>
|
||||
</slider>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="美白磨皮" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="S8B-AB-YC8">
|
||||
<rect key="frame" x="172" y="601" width="70" height="21"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="瘦脸" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Xqq-mI-Nvq">
|
||||
<rect key="frame" x="189.5" y="672" width="35" height="21"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="大眼" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vgF-XJ-zVO">
|
||||
<rect key="frame" x="189.5" y="743" width="35" height="21"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="整形-缩鼻翼" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Mom-9E-xEB">
|
||||
<rect key="frame" x="159.5" y="814" width="95" height="20.5"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<slider opaque="NO" tag="2" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="wEp-us-rWn">
|
||||
<rect key="frame" x="55" y="774" width="304" height="31"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="300" id="SU3-lS-UVj"/>
|
||||
<constraint firstAttribute="width" constant="300" id="d1T-V2-Y4S"/>
|
||||
</constraints>
|
||||
<connections>
|
||||
<action selector="beautyChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="Kax-jU-pOr"/>
|
||||
</connections>
|
||||
</slider>
|
||||
<slider opaque="NO" tag="3" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="axw-O5-vck">
|
||||
<rect key="frame" x="55" y="844.5" width="304" height="31"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" relation="lessThanOrEqual" constant="300" id="cWo-IZ-VC0"/>
|
||||
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="300" id="goO-a8-B8f"/>
|
||||
<constraint firstAttribute="width" constant="300" id="tXo-vs-G4j"/>
|
||||
</constraints>
|
||||
<connections>
|
||||
<action selector="beautyChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="WZa-J4-ckO"/>
|
||||
</connections>
|
||||
</slider>
|
||||
</subviews>
|
||||
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
|
||||
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
|
||||
<constraints>
|
||||
<constraint firstItem="Mom-9E-xEB" firstAttribute="top" secondItem="wEp-us-rWn" secondAttribute="bottom" constant="10" id="AJK-dn-fkm"/>
|
||||
<constraint firstItem="vgF-XJ-zVO" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="DZZ-ez-8TZ"/>
|
||||
<constraint firstItem="vhS-oS-Fej" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="JJ0-gj-buS"/>
|
||||
<constraint firstItem="wEp-us-rWn" firstAttribute="top" secondItem="vgF-XJ-zVO" secondAttribute="bottom" constant="10" id="NHk-jR-ewD"/>
|
||||
<constraint firstItem="vhS-oS-Fej" firstAttribute="top" secondItem="S8B-AB-YC8" secondAttribute="bottom" constant="10" id="PL7-5c-jQt"/>
|
||||
<constraint firstItem="Mom-9E-xEB" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="TYW-Gr-uFp"/>
|
||||
<constraint firstItem="vgF-XJ-zVO" firstAttribute="top" secondItem="Qqv-lK-sGM" secondAttribute="bottom" constant="10" id="VIL-NW-R20"/>
|
||||
<constraint firstItem="axw-O5-vck" firstAttribute="top" secondItem="Mom-9E-xEB" secondAttribute="bottom" constant="10" id="Vcm-Ek-dn6"/>
|
||||
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="vhS-oS-Fej" secondAttribute="bottom" constant="200" id="cTV-Ue-aqY"/>
|
||||
<constraint firstItem="Xqq-mI-Nvq" firstAttribute="top" secondItem="vhS-oS-Fej" secondAttribute="bottom" constant="10" id="d5V-Bk-AdN"/>
|
||||
<constraint firstItem="axw-O5-vck" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="dS4-8m-TsB"/>
|
||||
<constraint firstItem="Xqq-mI-Nvq" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="elq-CK-DpX"/>
|
||||
<constraint firstItem="S8B-AB-YC8" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="frG-6h-1EA"/>
|
||||
<constraint firstItem="Qqv-lK-sGM" firstAttribute="top" secondItem="Xqq-mI-Nvq" secondAttribute="bottom" constant="10" id="juk-TL-vmD"/>
|
||||
<constraint firstItem="wEp-us-rWn" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="of9-0R-JYD"/>
|
||||
<constraint firstItem="Qqv-lK-sGM" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="vqt-Eo-Zus"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<navigationItem key="navigationItem" id="95p-Qv-uS6"/>
|
||||
|
|
|
@ -88,6 +88,8 @@ AVCaptureAudioDataOutputSampleBufferDelegate> {
|
|||
[super viewWillAppear:animated];
|
||||
[self startCapture];
|
||||
[[OlaFaceUnity sharedInstance] resume];
|
||||
[OlaFaceUnity sharedInstance].whiten = 0.0;
|
||||
[OlaFaceUnity sharedInstance].smooth = 0.0;
|
||||
}
|
||||
|
||||
- (void)setupSession {
|
||||
|
@ -289,8 +291,16 @@ AVCaptureAudioDataOutputSampleBufferDelegate> {
|
|||
|
||||
- (IBAction)beautyChanged:(UISlider *)sender
|
||||
{
|
||||
[OlaFaceUnity sharedInstance].whiten = sender.value;
|
||||
[OlaFaceUnity sharedInstance].smooth = sender.value;
|
||||
if (sender.tag == 0) {
|
||||
[OlaFaceUnity sharedInstance].whiten = sender.value;
|
||||
[OlaFaceUnity sharedInstance].smooth = sender.value;
|
||||
} else if (sender.tag == 1) {
|
||||
[OlaFaceUnity sharedInstance].slim = sender.value;
|
||||
} else if (sender.tag == 2) {
|
||||
[OlaFaceUnity sharedInstance].eyeFactor = sender.value;
|
||||
} else if (sender.tag == 3) {
|
||||
[OlaFaceUnity sharedInstance].nose = sender.value;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -16,6 +16,9 @@ typedef struct {
|
|||
|
||||
@property (nonatomic) CGFloat whiten;
|
||||
@property (nonatomic) CGFloat smooth;
|
||||
@property (nonatomic) CGFloat slim;
|
||||
@property (nonatomic) CGFloat nose;
|
||||
@property (nonatomic) CGFloat eyeFactor;
|
||||
|
||||
|
||||
+ (instancetype)sharedInstance;
|
||||
|
|
|
@ -113,6 +113,36 @@
|
|||
_face_module->setSmoothing(smooth);
|
||||
}
|
||||
|
||||
- (CGFloat)slim
|
||||
{
|
||||
return _face_module->getSlim();
|
||||
}
|
||||
|
||||
- (void)setSlim:(CGFloat)slim
|
||||
{
|
||||
_face_module->setSlim(slim);
|
||||
}
|
||||
|
||||
- (CGFloat)eyeFactor
|
||||
{
|
||||
return _face_module->getEye();
|
||||
}
|
||||
|
||||
- (void)setEyeFactor:(CGFloat)eyeFactor
|
||||
{
|
||||
_face_module->setEye(eyeFactor);
|
||||
}
|
||||
|
||||
- (CGFloat)nose
|
||||
{
|
||||
return _face_module->getNose();
|
||||
}
|
||||
|
||||
- (void)setNose:(CGFloat)nose
|
||||
{
|
||||
_face_module->setNose(nose);
|
||||
}
|
||||
|
||||
- (void)resume
|
||||
{
|
||||
if (!_face_module) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user