#include"Trent.h"
#include "mtcnn.h"
#include
static char* model_path = "C:/Users/Administrator/Desktop/mtcnn/001_TestDemo/TestDemo/TestDemo_C/models";
MTCNN* mtcnn;
int FD_Initialize()
{
mtcnn = new MTCNN(model_path);
return 0;
};
int FD_Process(unsigned char* srcData, int width, int height, int stride, int faceInfos[15])
{
unsigned char* data = (unsigned char*)malloc(sizeof(unsigned char) * height * width * 3);
unsigned char* pSrc = srcData;
unsigned char* pData = data;
for (int j = 0; j {
for (int i = 0; i {
pData[0] = pSrc[0];
pData[1] = pSrc[1];
pData[2] = pSrc[2];
pData += 3;
pSrc += 4;
}
}
ncnn::Mat ncnn_img = ncnn::Mat::from_pixels(data, ncnn::Mat::PIXEL_RGB, width, height);
std::vector finalBbox;
mtcnn->detect(ncnn_img, finalBbox);
if(finalBbox.size() > 0)
{
faceInfos[0] = 1;
faceInfos[1
] = finalBbox[0].x1;
faceInfos[2] = finalBbox[0].y1;
faceInfos[3] = finalBbox[0].x2 - finalBbox[0].x1;
faceInfos[4] = finalBbox[0].y2 - finalBbox[0].y1;
faceInfos[5] = finalBbox[0].ppoint[0];
faceInfos[6] = finalBbox[0].ppoint[5];
faceInfos[7] = finalBbox[0].ppoint[1];
faceInfos[8] = finalBbox[0].ppoint[6];
faceInfos[9] = finalBbox[0].ppoint[2];
faceInfos[10] = finalBbox[0].ppoint[7];
faceInfos[11] = finalBbox[0].ppoint[3];
faceInfos[12] = finalBbox[0].ppoint[8];
faceInfos[13] = finalBbox[0].ppoint[4];
faceInfos[14] = finalBbox[0].ppoint[9];
}
free(data);
return 0;
};
void FD_Unitialize()
{
if(model_path != NULL)
free(model_path);
delete(mtcnn);
}
void GetTexTransMatrix(float x1, float y1, float x2, float y2, float x3, float y3,float tx1, float
ty1, float tx2, float ty2, float tx3, float ty3, float*texMatrix)
{
float detA;
detA = tx1*ty2 + tx2*ty3 + tx3*ty1 - tx3*ty2 - tx1*ty3 - tx2*ty1;
float A11, A12, A13, A21, A22, A23, A31, A32, A33;
A11 = ty2 - ty3;
A21 = -(ty1 - ty3);
A31 = ty1 - ty2;
A12 = -(tx2 - tx3);
A22 = tx1 - tx3;
A32 = -(tx1 - tx2);
A13 = tx2*ty3 - tx3*ty2;
A23 = -(tx1*ty3 - tx3*ty1);
A33 = tx1*ty2 - tx2*ty1;
texMatrix[0] = (x1*A11 + x2*A21 + x3*A31) / detA;
texMatrix[1] = (x1*A12 + x2*A22 + x3*A32) / detA;
texMatrix[2] = (x1*A13 + x2*A23 + x3*A33) / detA;
texMatrix[3] = (y1*A11 + y2*A21 + y3*A31) / detA;
texMatrix[4] = (y1*A12 + y2*A22 + y3*A32) / detA;
texMatrix[5] = (y1*A13 + y2*A23 + y3*A33) / detA;
#include"Trent_Sticker.h"
#include"Trent.h"
void GetTexTransMatrix(float x1, float y1, float x2, float y2, float x3, float y3,float tx1, float ty1, float tx2, float ty2, float tx3, float ty3, float*texMatrix)
{
float detA;
detA = tx1*ty2 + tx2*ty3 + tx3*ty1 - tx3*ty2 - tx1*ty3 - tx2*ty1;
float A11, A12, A13, A21, A22, A23, A31, A32, A33;
A11 = ty2 - ty3;
A21 = -(ty1 - ty3);
A31 = ty1 - ty2;
A12 = -(tx2 - tx3);
A22 = tx1 - tx3;
A32 = -(tx1 - tx2);
A13 = tx2*ty3 - tx3*ty2;
A23 = -(tx1*ty3 - tx3*ty1);
A33 = tx1*ty2 - tx2*ty1;
texMatrix[0] = (x1*A11 + x2*A21 + x3*A31) / detA;
texMatrix[1] = (x1*A12 + x2*A22 + x3*A32) / detA;
texMatrix[2] = (x1*A13 + x2*A23 + x3*A33) / detA;
texMatrix[3] = (y1*A11 + y2*A21 + y3*A31) / detA;
texMatrix[4] = (y1*A12 + y2*A22 + y3*A32) / detA;
texMatrix[5] = (y1*A13 + y2*A23 + y3*A33) / detA;
}
int Trent_Sticker(unsigned char* srcData, int width, int height, int stride, unsigned char* mask, int maskWidth, int maskHeight, int maskStride, int srcFacePoints[6], int maskFacePoints[6], int ratio)
{
int ret = 0;
float H[6];
GetTexTransMatrix(maskFacePoints[0], maskFacePoints[1], maskFacePoints[2], maskFacePoints[3], maskFacePoints[4], maskFacePoints[5], srcFacePoints[0], srcFacePoints[1], srcFacePoints[2], srcFacePoints[3], srcFacePoints[4], srcFacePoints[5], H);
for (int j = 0; j {
for (int i = 0; i {
float x = (float)i;
float y = (float)j;
float tx = 0;
float ty = 0;
tx = (int)((H[0] * (x)+H[1] * (y)+H[2]) + 0.5);
ty = (int)((H[3] * (x)+H[4] * (y)+H[5]) + 0.5);
tx = CLIP3(tx, 0, maskWidth - 1);
ty = CLIP3(ty, 0, maskHeight - 1);
int mb = mask[(int)tx * 4 + (int)ty * maskStride];
int mg = mask[(int)tx * 4 + (int)ty * maskStride + 1];
int mr = mask[(int)tx * 4 + (int)ty * maskStride + 2];
int alpha = mask[(int)tx * 4 + (int)ty * maskStride + 3];
int b = srcData[i * 4 + j * stride];
int g = srcData[i * 4 + j * stride + 1];
int r = srcData[i * 4