Skip to content

Commit

Permalink
first blood of monalisa
Browse files Browse the repository at this point in the history
  • Loading branch information
iFinVer committed Dec 28, 2016
1 parent 663ce4c commit 75ef3e8
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 31 deletions.
Binary file removed finengine/src/main/assets/mona.png
Binary file not shown.
Binary file added finengine/src/main/assets/monalisa.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion finengine/src/main/cpp/effects/faceswap/faceswap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ unsigned char *effect_swapFace(jbyte *data, jint width, jint height, long long i
facePointBob.push_back(Point2i(ptIndex.x, ptIndex.y));
}

cvtColor(*yuvFrame, *rgbFrame, CV_YUV2RGB_NV21);
cvtColor(*yuvFrame, *rgbFrame, CV_YUV2BGR_NV21);

try {
face_swapper->swapFaces(*rgbFrame, *faceRectAnn, *faceRectBob, facePointAnn, facePointBob);
Expand Down
14 changes: 12 additions & 2 deletions finengine/src/main/cpp/facedetect/arcsoft/arcsoft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,37 @@ int ArcSoftSpotlight::processSingleFrame(void *data, int width, int height, MPOI
return -1;
}

ASVLOFFSCREEN offScreenIn;
ASL_SetProcessModel(m_hEngine, ASL_PROCESS_MODEL_FACEOUTLINE);

ASVLOFFSCREEN offScreenIn = {0};
offScreenIn.u32PixelArrayFormat = ASVL_PAF_RGB24_B8G8R8;
offScreenIn.i32Width = width;
offScreenIn.i32Height = height;
offScreenIn.pi32Pitch[0] = width * 3;
offScreenIn.ppu8Plane[0] = (MUInt8 *) data;

int faceInOut = 1;
MInt32 faceInOut = 1;
LOGE("%s","here we go 1");
MRESULT hr = ASL_Process(m_hEngine,
&offScreenIn,
MNull,
&faceInOut,
faceOutlinePointOut,
faceRectOut,
faceOrientOut);
LOGE("%s","here we go 2");

ASL_SetProcessModel(m_hEngine, processModel);

if (hr == MOK) {
if(faceInOut == 1){
LOGE("%s", "检测成功..");
return 0;
}
LOGE("%s", "没有识别出人脸..");
return 1;
}
LOGE("%s", "检测出错");
return -2;
}

Expand Down
4 changes: 3 additions & 1 deletion finengine/src/main/cpp/finengine/GLContextHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <jni.h>
#include <string>
#include <amcomdef.h>
#include <opencv2/core/mat.hpp>
#include "shaders.h"

class GLContextHolder{
Expand Down Expand Up @@ -60,9 +61,10 @@ class GLContextHolder{

int engineMode;
std::string monaFilePath;
MPOINT *pFaceOutlinePointOut;
MPOINT *pFaceOutlinePointOut = nullptr;
MRECT *rcFaceRectOut;
MFloat *faceOrientOut;
cv::Mat monaMat;
};

#endif //MYOPENGLES_GL_CONTEXT_H
42 changes: 18 additions & 24 deletions finengine/src/main/cpp/finengine/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,48 +227,43 @@ JNIEXPORT void JNICALL Java_com_ifinver_finengine_FinEngine_nativeSwitchFilter(J
engineHolder->currentFilter = mFilterType;
}

JNIEXPORT void JNICALL Java_com_ifinver_finengine_FinEngine_nativeSwitchToModeNormal(JNIEnv *env, jobject instance, jlong engine){
JNIEXPORT void JNICALL Java_com_ifinver_finengine_FinEngine_nativeSwitchToModeNormal(JNIEnv *env, jobject instance, jlong engine) {
GLContextHolder *engineHolder = (GLContextHolder *) engine;
engineHolder->engineMode = ENGINE_MODE_NORMAL;
LOGI("%s","switched mode to normal!");
LOGI("%s", "switched mode to normal!");
}

JNIEXPORT void JNICALL Java_com_ifinver_finengine_FinEngine_nativeSwitchToModeFaceSwap(JNIEnv *env, jobject instance, jlong engine){
JNIEXPORT void JNICALL Java_com_ifinver_finengine_FinEngine_nativeSwitchToModeFaceSwap(JNIEnv *env, jobject instance, jlong engine) {
GLContextHolder *engineHolder = (GLContextHolder *) engine;
engineHolder->engineMode = ENGINE_MODE_FACE_SWAP;
LOGI("%s","switched mode to swap face!");
LOGI("%s", "switched mode to swap face!");
}

JNIEXPORT void JNICALL
Java_com_ifinver_finengine_FinEngine_nativeSwitchToModeMonaLisa(JNIEnv *env, jobject, jlong engine, jstring filePath_) {
const char *filePath = env->GetStringUTFChars(filePath_, 0);
LOGI("%s","switching mode to mona lisa ..");
LOGI("%s", "switching mode to mona lisa ..");
GLContextHolder *engineHolder = (GLContextHolder *) engine;
if (engineHolder->monaFilePath.compare(filePath)) {
//不相等才会走进来
const Mat &monaMat = imread(filePath);
engineHolder->monaMat = imread(filePath);
if (engineHolder->pFaceOutlinePointOut == nullptr) {
engineHolder->pFaceOutlinePointOut = new MPOINT[101];
engineHolder->rcFaceRectOut = new MRECT();
engineHolder->rcFaceRectOut = new MRECT[1];
engineHolder->faceOrientOut = new MFloat[3];
}

int rc = face_processSingleFrame(monaMat.data, monaMat.cols, monaMat.rows, engineHolder->pFaceOutlinePointOut, engineHolder->rcFaceRectOut,
LOGE("mona width:%d,height:%d,channels:%d,is continuous:%s", engineHolder->monaMat.cols, engineHolder->monaMat.rows,
engineHolder->monaMat.channels(), engineHolder->monaMat.isContinuous() ? "continuous" : "no-continuous");
int rc = face_processSingleFrame(engineHolder->monaMat.data, engineHolder->monaMat.cols, engineHolder->monaMat.rows,
engineHolder->pFaceOutlinePointOut, engineHolder->rcFaceRectOut,
engineHolder->faceOrientOut);
if (rc == 0) {
LOGE("%s", "检测图片成功!");

engineHolder->monaFilePath = filePath;
// engineHolder->engineMode = ENGINE_MODE_MONA_LISA;
} else if (rc == 1) {
LOGE("%s", "没有识别出人脸..");
} else if (rc == -1) {
LOGE("%s", "检测引擎未初始化");
} else if (rc == -2) {
LOGE("%s", "检测出错");
}
}

engineHolder->engineMode = ENGINE_MODE_MONA_LISA;

env->ReleaseStringUTFChars(filePath_, filePath);
}
Expand Down Expand Up @@ -333,12 +328,12 @@ void renderFrame(GLContextHolder *engineHolder, jbyte *data, jint width, jint he
break;
}
case ENGINE_MODE_MONA_LISA: {
unsigned char *monaLisaFrame = effect_monaLisa(data, width, height);
if (monaLisaFrame == NULL) {
renderYuv(engineHolder, data, width, height, degree, mirror, outWidth, outHeight, facePtr);
} else {
renderRgb(engineHolder, monaLisaFrame, width, height, degree, mirror, outWidth, outHeight, facePtr);
}
// unsigned char *monaLisaFrame = effect_monaLisa(data, width, height);
// if (monaLisaFrame == NULL) {
// renderYuv(engineHolder, data, width, height, degree, mirror, outWidth, outHeight, facePtr);
// } else {
renderRgb(engineHolder, engineHolder->monaMat.data, engineHolder->monaMat.cols, engineHolder->monaMat.rows, 0, 0, outWidth, outHeight, facePtr);
// }
break;
}
}
Expand Down Expand Up @@ -481,5 +476,4 @@ void releaseGLContext(GLContextHolder *engineHolder) {
eglDestroyContext(engineHolder->eglDisplay, engineHolder->eglContext);
delete (engineHolder);
}

}
2 changes: 1 addition & 1 deletion finengine/src/main/cpp/finengine/shaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class ShaderRGB : public ShaderBase {
" \n"
"void main(){ \n"
" vec2 mirrorCoord = mirrorUV(); \n"
" gl_FragColor = texture2D(sTexture,mirrorCoord); \n"
" gl_FragColor = vec4(texture2D(sTexture,mirrorCoord).bgr,1.0); \n"
"} \n";
}
};
Expand Down
4 changes: 2 additions & 2 deletions finengine/src/main/java/com/ifinver/finengine/FinEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public void switchModeToSwapFace(){

public void switchModeToMonaLisa(Context ctx) {
synchronized (this) {
File monaFile = new File(ctx.getFilesDir() + "/mona.png");
File monaFile = new File(ctx.getFilesDir() + "/monalisa.jpg");
if (!monaFile.exists()) {
//不存在了
try {
InputStream in = ctx.getAssets().open("mona.png");
InputStream in = ctx.getAssets().open("monalisa.jpg");
FileOutputStream fos = new FileOutputStream(monaFile);
byte[] buffer = new byte[1024];
int readCount;
Expand Down
Binary file modified release/finengine-release.aar
Binary file not shown.

0 comments on commit 75ef3e8

Please sign in to comment.