Commit e4336789 authored by 宋柯's avatar 宋柯

美瞳v1

parent debb85e0
...@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.17) ...@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.17)
project(BeautyCamera) project(BeautyCamera)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#find_package(nlohmann_json 3.2.0 REQUIRED) #find_package(nlohmann_json 3.2.0 REQUIRED)
#target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json) #target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json)
...@@ -24,29 +25,29 @@ set(CMAKE_CXX_STANDARD 11) ...@@ -24,29 +25,29 @@ set(CMAKE_CXX_STANDARD 11)
#opencv #opencv
find_package(OpenCV) find_package(OpenCV)
include_directories(${OpenCV_INCLUDE_DIRS}) include_directories(${OpenCV_INCLUDE_DIRS})
find_package(Poco CONFIG REQUIRED Util Data Net XML Zip) find_package(Poco CONFIG REQUIRED JSON Foundation Crypto NetSSL Util Data Net XML Zip)
#dlib
find_package(dlib REQUIRED)
include_directories(${dlib_INCLUDE_DIRS})
#FIND_PACKAGE(OpenMP REQUIRED) #FIND_PACKAGE(OpenMP REQUIRED)
#if(OPENMP_FOUND) #if(OPENMP_FOUND)
# set(CMAKE_C_FLAGS "${OpenMP_C_FLAGS}") # set(CMAKE_C_FLAGS "${OpenMP_C_FLAGS}")
#endif() #endif()
#openssl
find_package(OpenSSL REQUIRED)
include_directories(/usr/local/Cellar/openssl@1.1/1.1.1i/include/)
aux_source_directory(. SRCS) aux_source_directory(. SRCS)
include_directories(/usr/local/include) include_directories(/usr/local/include)
link_directories(/usr/local/lib) link_directories(/usr/local/lib)
include_directories(/usr/include)
link_directories(/usr/lib)
link_directories(/var/lib/docker/overlay2/31f90414dac01ae042df89921b78b3ed76fd8f70608cbce2e61e4dbbd61f2a95/diff/usr/lib/x86_64-linux-gnu/)
link_directories(/var/lib/docker/overlay2/c55849720cdefdb5883910c2d019324b1f7ee0f734f455d089976504c8991c50/diff/lib/x86_64-linux-gnu/)
#tenginekit sdk
include_directories(/srv/apps/TengineKit-master/Linux/include)
link_directories(/srv/apps/TengineKit-master/Linux/libs)
#add_executable(main f_BeautyCamera.cpp ${SRCS}) #add_executable(main f_BeautyCamera.cpp ${SRCS})
#target_link_libraries(main ${OpenCV_LIBS} ${Poco_LIBRARIES}) #target_link_libraries(main ${OpenCV_LIBS} ${Poco_LIBRARIES})
#add_executable(gender gender.cpp ${SRCS}) #add_executable(gender gender.cpp ${SRCS})
#target_link_libraries(gender ${OpenCV_LIBS} ${Poco_LIBRARIES}) #target_link_libraries(gender ${OpenCV_LIBS} ${Poco_LIBRARIES})
add_executable(beautyIris f_BeautyIris.cpp ${SRCS}) add_executable(beautyIris f_BeautyIris.cpp ${SRCS})
target_link_libraries(beautyIris ${OpenCV_LIBS} ${Poco_LIBRARIES} TengineKitSDK curl mvec) target_link_libraries(beautyIris ${OpenCV_LIBS} ${Poco_LIBRARIES} PocoFoundation PocoNet PocoUtil ${dlib_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARY})
#target_link_libraries(beautyIris ${OpenCV_LIBS} ${Poco_LIBRARIES} libdlib.a X11 pthread)
#target_link_libraries(helloworld #target_link_libraries(helloworld
# ${Poco_LIBRARIES} # ${Poco_LIBRARIES}
......
...@@ -7,11 +7,45 @@ ...@@ -7,11 +7,45 @@
#include"f_MeanFilter.h" #include"f_MeanFilter.h"
#include"iostream" #include"iostream"
#include <opencv2/opencv.hpp> #include <opencv2/opencv.hpp>
#include "tenginekit_api.h" #include <dlib/opencv.h>
#include "tenginekit_struct.h" #include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing.h>
#include <Poco/URI.h>
#include <Poco/StreamCopier.h>
#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTMLForm.h>
#include <Poco/Net/HTTPResponse.h>
#include <Poco/Net/NetException.h>
#include "Poco/JSON/Parser.h"
#include "Poco/JSON/ParseHandler.h"
#include "Poco/JSON/JSONException.h"
#include "Poco/StreamCopier.h"
#include "Poco/Dynamic/Var.h"
#include "Poco/JSON/Query.h"
#include "Poco/JSON/PrintHandler.h"
#include <Poco/Stopwatch.h>
#include "Poco/URIStreamOpener.h"
#include "Poco/StreamCopier.h"
#include "Poco/URI.h"
#include "Poco/SharedPtr.h"
#include "Poco/Exception.h"
#include "Poco/JSON/Parser.h"
#include "Poco/Net/HTTPSClientSession.h"
#include "Poco/Net/HTTPClientSession.h"
#include "Poco/Net/HTTPRequest.h"
#include "Poco/Net/HTTPResponse.h"
#include "Poco/Net/SSLException.h"
#include "Poco/Net/HTTPBasicCredentials.h"
#include "Poco/Net/HTMLForm.h"
#include "Poco/Net/FilePartSource.h"
#include "vector"
using namespace dlib;
using namespace cv; using namespace cv;
using namespace std; using namespace std;
using namespace Poco;
using namespace Poco::Net;
//void RGB2HSB(unsigned char r, unsigned char g, unsigned char b, float *H, float *S, float* B) //void RGB2HSB(unsigned char r, unsigned char g, unsigned char b, float *H, float *S, float* B)
//{ //{
...@@ -100,23 +134,23 @@ maskPoints: center point of mask. ...@@ -100,23 +134,23 @@ maskPoints: center point of mask.
*ratio: intensity of beauty iris, [0, 100]. *ratio: intensity of beauty iris, [0, 100].
*Return :0-OK,or failed *Return :0-OK,or failed
************************************************************/ ************************************************************/
int f_BeautyIris(unsigned char* srcData, int width, int height, int stride, int srcPoints[], unsigned char* maskData, int mWidth, int mHeight, int mStride, int maskPoints[], int ratio) int f_BeautyIris(unsigned char* srcData, int width, int height, int stride, int srcPoints[], unsigned char* maskData, int mWidth, int mHeight, int mStride, int maskPoints[], int ratio,int eye_pupil_radius,int eye_pupil_center_x,int eye_pupil_center_y,float irisRadiusExpand=1.0)
{ {
int ret = 0; int ret = 0;
unsigned char* pSrc = srcData; int cenx = eye_pupil_center_x;
int cenx = srcPoints[2 * 12]; int ceny = eye_pupil_center_y;
int ceny = srcPoints[2 * 12 + 1];
//compute iris radius. //compute iris radius.
int eyedistance = sqrt((float)(srcPoints[2 * 0] - srcPoints[2 * 6]) * (srcPoints[2 * 0] - srcPoints[2 * 6]) + (srcPoints[2 * 0 + 1] - srcPoints[2 * 6 + 1]) * (srcPoints[2 * 0 + 1] - srcPoints[2 * 6 + 1])) / 2; // int eyedistance = sqrt((float)(srcPoints[2 * 0] - srcPoints[2 * 5]) * (srcPoints[2 * 0] - srcPoints[2 * 5]) + (srcPoints[2 * 0 + 1] - srcPoints[2 * 5 + 1]) * (srcPoints[2 * 0 + 1] - srcPoints[2 * 5 + 1])) / 2;
int irisRadius = eyedistance / 2; int irisRadius = eye_pupil_radius;
irisRadius*=irisRadiusExpand;
//compute the rectangle of eye area. //compute the rectangle of eye area.
int px = CLIP3(cenx - irisRadius, 0, width - 1); int px = CLIP3(cenx - irisRadius, 0, width - 1);
int py = CLIP3(ceny - irisRadius, 0, height - 1); int py = CLIP3(ceny - irisRadius, 0, height - 1);
int pmaxX = CLIP3(cenx + irisRadius, 0, width - 1); int pmaxX = CLIP3(cenx + irisRadius, 0, width - 1);
int pmaxY = CLIP3(ceny + irisRadius, 0, height - 1); int pmaxY = CLIP3(ceny + irisRadius, 0, height - 1);
int w = pmaxX - px; int w = pmaxX - px + 2;
int h = pmaxY - py; int h = pmaxY - py + 2;
const int pointNum = 12; const int pointNum = 63;
int xPoints[pointNum]; int xPoints[pointNum];
int yPoints[pointNum]; int yPoints[pointNum];
int maxX = 0, minX = 100000, maxY = 0, minY = 100000; int maxX = 0, minX = 100000, maxY = 0, minY = 100000;
...@@ -130,34 +164,47 @@ int f_BeautyIris(unsigned char* srcData, int width, int height, int stride, int ...@@ -130,34 +164,47 @@ int f_BeautyIris(unsigned char* srcData, int width, int height, int stride, int
minY = MIN2(srcPoints[2 * i + 1], minY); minY = MIN2(srcPoints[2 * i + 1], minY);
} }
//irisMask feather process //irisMask feather process
unsigned char* irisMask = (unsigned char*)malloc(sizeof(unsigned char) * w * h * 4); unsigned char* irisMask = (unsigned char*)malloc(sizeof(unsigned char) * w * h * 3);
unsigned char* pMask = irisMask; unsigned char* pMask = irisMask;
for(int j = 0; j < h; j++) for(int j = 0; j < h; j++)
{ {
for(int i = 0; i < w; i++) for(int i = 0; i < w; i++)
{ {
int dis = sqrt((float)(i - irisRadius) * (i - irisRadius) + (j - irisRadius) * (j - irisRadius)); int dis = sqrt((float)(i - irisRadius) * (i - irisRadius) + (j - irisRadius) * (j - irisRadius));
if(f_PNPoly_OPT(xPoints, yPoints, pointNum, i + px, j + py, minX, minY, maxX, maxY) && dis < irisRadius-3) if(dis <= irisRadius*irisRadiusExpand&&f_PNPoly_OPT(xPoints, yPoints, pointNum, i + px, j + py, minX, minY, maxX, maxY))
// if(dis <= irisRadius)
pMask[0] = pMask[1] = pMask[2] = 255; pMask[0] = pMask[1] = pMask[2] = 255;
else else
pMask[0] = pMask[1] = pMask[2] = 0; pMask[0] = pMask[1] = pMask[2] = 0;
pMask += 4; pMask += 3;
} }
} }
f_FastMeanFilter(irisMask, w, h, w * 4, 3); // Mat m;
pMask = irisMask; // m.create(h,w,CV_8UC(3));
for(int j = 0; j < h; j++) // m.data = irisMask;
{ // imshow("irisMask",m);
for(int i = 0; i < w; i++) // waitKey(0);
{
if(pMask[0] > 128) // f_FastMeanFilter(irisMask, w, h, w * 3, 3);
pMask[0] = pMask[1] = pMask[2] = 255; //
else // pMask = irisMask;
pMask[0] = pMask[1] = pMask[2] = 0; // for(int j = 0; j < h; j++)
pMask += 4; // {
} // for(int i = 0; i < w; i++)
} // {
f_FastMeanFilter(irisMask, w, h, w * 4, 3); // if(pMask[0] > 128)
// pMask[0] = pMask[1] = pMask[2] = 255;
// else
// pMask[0] = pMask[1] = pMask[2] = 0;
// pMask += 3;
// }
// }
// f_FastMeanFilter(irisMask, w, h, w * 3, 3);
// Mat m;
// m.create(h,w,CV_8UC(3));
// m.data = irisMask;
// imshow("irisMask",m);
// waitKey(0);
//beauty iris process //beauty iris process
pMask = irisMask; pMask = irisMask;
for(int j = 0; j < h; j++) for(int j = 0; j < h; j++)
...@@ -166,10 +213,10 @@ int f_BeautyIris(unsigned char* srcData, int width, int height, int stride, int ...@@ -166,10 +213,10 @@ int f_BeautyIris(unsigned char* srcData, int width, int height, int stride, int
{ {
if((pMask[0] + pMask[1] + pMask[2]) / 3 > 0) if((pMask[0] + pMask[1] + pMask[2]) / 3 > 0)
{ {
int pos_src = (px + i) * 4 + (py + j) * stride; int pos_src = (px + i) * 3 + (py + j) * stride;
int mx = i * mWidth / w; int mx = i * mWidth / w;
int my = j * mHeight / h; int my = j * mHeight / h;
int pos_mask = mx * 4 + my * mStride; int pos_mask = mx * 3 + my * mStride;
int r = srcData[pos_src + 2]; int r = srcData[pos_src + 2];
int g = srcData[pos_src + 1]; int g = srcData[pos_src + 1];
int b = srcData[pos_src]; int b = srcData[pos_src];
...@@ -184,15 +231,15 @@ int f_BeautyIris(unsigned char* srcData, int width, int height, int stride, int ...@@ -184,15 +231,15 @@ int f_BeautyIris(unsigned char* srcData, int width, int height, int stride, int
YUV2RGB(Y, mU, mV, &R, &G, &B); YUV2RGB(Y, mU, mV, &R, &G, &B);
//feather mask process //feather mask process
int a = (pMask[0] + pMask[1] + pMask[2]) / 3; int a = (pMask[0] + pMask[1] + pMask[2]) / 3;
B = CLIP3((b * (255 - a) + B * a) >> 8, 0, 255); // B = CLIP3((b * (255 - a) + B * a) >> 8, 0, 255);
G = CLIP3((g * (255 - a) + G * a) >> 8, 0, 255); // G = CLIP3((g * (255 - a) + G * a) >> 8, 0, 255);
R = CLIP3((r * (255 - a) + R * a) >> 8, 0, 255); // R = CLIP3((r * (255 - a) + R * a) >> 8, 0, 255);
//YUV color correct // //YUV color correct
a = CLIP3((r + g + b) / 3 * 2, 0, 255); // a = CLIP3((r + g + b) / 3 * 2, 0, 255);
R = (R * a + r * (255 - a)) / 255; // R = (R * a + r * (255 - a)) / 255;
G = (G * a + g * (255 - a)) / 255; // G = (G * a + g * (255 - a)) / 255;
B = (B * a + b * (255 - a)) / 255; // B = (B * a + b * (255 - a)) / 255;
//ratio blending // //ratio blending
B = CLIP3((b * (100 - ratio) + B * ratio) / 100, 0, 255); B = CLIP3((b * (100 - ratio) + B * ratio) / 100, 0, 255);
G = CLIP3((g * (100 - ratio) + G * ratio) / 100, 0, 255); G = CLIP3((g * (100 - ratio) + G * ratio) / 100, 0, 255);
R = CLIP3((r * (100 - ratio) + R * ratio) / 100, 0, 255); R = CLIP3((r * (100 - ratio) + R * ratio) / 100, 0, 255);
...@@ -201,117 +248,504 @@ int f_BeautyIris(unsigned char* srcData, int width, int height, int stride, int ...@@ -201,117 +248,504 @@ int f_BeautyIris(unsigned char* srcData, int width, int height, int stride, int
srcData[pos_src + 1] = G; srcData[pos_src + 1] = G;
srcData[pos_src + 2] = R; srcData[pos_src + 2] = R;
} }
pMask += 4; pMask += 3;
} }
} }
free(irisMask); free(irisMask);
return ret; return ret;
}; };
FaceSDKConfig getConfig(int w, int h)
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
using namespace std;
static const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
static inline bool is_base64(const char c)
{ {
FaceSDKConfig config; return (isalnum(c) || (c == '+') || (c == '/'));
config.img_w = w;
config.img_h = h;
config.screen_w = w;
config.screen_h = h;
config.input_format = ImageFormat::BGR;
config.mode = FaceSDKMode::Normal;
config.thread_num = 2;
return config;
} }
std::string base64_encode(const char * bytes_to_encode, unsigned int in_len)
void handle_rgb(std::string path)
{ {
float eye_close_v = 0.75f; std::string ret;
std::string image_file = path; int i = 0;
cv::Mat frame = cv::imread(image_file); int j = 0;
unsigned char char_array_3[3];
int w = frame.cols; unsigned char char_array_4[4];
int h = frame.rows;
FaceSDKConfig config = getConfig(w, h);
facesdk_init(config);
char data[w * h * 3];
memcpy(data, (char *)frame.data, w * h * 3);
facesdk_readModelFromFile(ModelType::Detect, "/srv/apps/TengineKit-master/Linux/models/face_detect.bin", ImageFormat::RGB);
sdkFaces faces = facesdk_detect(data);
std::cout << "faces:" << faces.face_count << std::endl;
for (int i = 0; i < faces.face_count; i++)
{
cv::Point pt1(faces.info[i].face_box.x1, faces.info[i].face_box.y1);
cv::Point pt2(faces.info[i].face_box.x2, faces.info[i].face_box.y2);
cv::rectangle(frame, pt1, pt2, cv::Scalar(255, 0, 0), 2);
}
facesdk_readModelFromFile(ModelType::Landmark, "/srv/apps/TengineKit-master/Linux/models/face_landmark2d.bin", ImageFormat::RGB); while (in_len--)
sdkFaces faces2 = facesdk_landmark();
int index = 0;
for (int j = 0; j < faces2.face_count; j++)
{ {
index++; char_array_3[i++] = *(bytes_to_encode++);
for (int i = 0; i < 424; i = i + 2) if(i == 3)
{ {
cv::Point pt(faces2.info[j].landmarks[i], faces2.info[j].landmarks[i + 1]); char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
cv::circle(frame, pt, 1, cv::Scalar(255, 0, 0), 1); char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for(i = 0; (i <4) ; i++)
{
ret += base64_chars[char_array_4[i]];
}
i = 0;
} }
std::cout << std::endl; }
if(i)
if (faces2.info[j].lefteye_close_state < eye_close_v) {
for(j = i; j < 3; j++)
{ {
std::cout << "左眼开" << std::endl; char_array_3[j] = '\0';
cv::putText(frame, "left eye open",
cv::Point(10, 20 + index * 30), cv::FONT_HERSHEY_DUPLEX, 1, cv::Scalar(0, 255, 255), 2);
} }
else
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for(j = 0; (j < i + 1); j++)
{ {
std::cout << "左眼关" << std::endl; ret += base64_chars[char_array_4[j]];
cv::putText(frame, "left eye close",
cv::Point(10, 20 + index * 30), cv::FONT_HERSHEY_DUPLEX, 1, cv::Scalar(0, 255, 255), 2);
} }
if (faces2.info[j].righteye_close_state < eye_close_v) while((i++ < 3))
{ {
std::cout << "右眼开" << std::endl; ret += '=';
cv::putText(frame, "right eye open",
cv::Point(10, 50 + index * 30), cv::FONT_HERSHEY_DUPLEX, 1, cv::Scalar(0, 255, 255), 2);
} }
else
{ }
std::cout << "右眼关" << std::endl; return ret;
cv::putText(frame, "right eye close", }
cv::Point(10, 50 + index * 30), cv::FONT_HERSHEY_DUPLEX, 1, cv::Scalar(0, 255, 255), 2);
int main29(int argc, char* argv[]){
// std::string stEsQuery = "https://api-cn.faceplusplus.com/facepp/v3/detect";
std::string stEsQuery = "https://api-cn.faceplusplus.com/facepp/v1/face/thousandlandmark";
URI uri(stEsQuery);
const Poco::Net::Context::Ptr context(
new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, "", "", "",
Poco::Net::Context::VERIFY_NONE));
Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort(), context);
string MEGVII_KEY = "-6zs61jR1M4GqzE9jIO3eiL1W1sojaeE";
string MEGVII_SECRET = "J82yKgSplMDppw9oPpHeTVTA4hYxp0iB";
HTTPRequest es_request(HTTPRequest::HTTP_POST,uri.getPathAndQuery(),HTTPRequest::HTTP_1_1);
es_request.setContentType("multipart/form-data");
HTMLForm form;
form.setEncoding(HTMLForm::ENCODING_MULTIPART);
form.add("api_key", MEGVII_KEY);
form.add("api_secret", MEGVII_SECRET);
// form.add("return_landmark", "2");
form.add("return_landmark", "right_eye");
// fstream f;
// f.open("/Users/edz/Downloads/tongshi.png", ios::in|ios::binary);
// f.seekg(0, std::ios_base::end); //设置偏移量至文件结尾
// std::streampos sp = f.tellg(); //获取文件大小
// int size = sp;
// char* buffer = (char*)malloc(sizeof(char)*size);
// f.seekg(0, std::ios_base::beg); //设置偏移量至文件开头
// f.read(buffer,size); //将文件内容读入buffer
// cout << "file size:" << size << endl;
// string imgBase64 = base64_encode(buffer, size); //编码
// form.add("image_base64", imgBase64);
form.addPart("image_file",new FilePartSource("/Users/edz/Downloads/meitonghei.jpeg"));
form.prepareSubmit(es_request);
form.write(session.sendRequest(es_request));
HTTPResponse es_response;
std::istream &istream = session.receiveResponse(es_response);
const HTTPResponse::HTTPStatus &status = es_response.getStatus();
if(HTTPResponse::HTTPStatus::HTTP_OK == status){
std::string stRes;
StreamCopier::copyToString(istream, stRes);
std::cout<< stRes <<std::endl;
}else{
std::string stRes;
StreamCopier::copyToString(istream, stRes);
std::cout<< stRes <<std::endl;
std::cout<< status <<std::endl;
}
}
int main28(int argc, char* argv[]){
try
{
// Load face detection and pose estimation models.
// frontal_face_detector detector = get_frontal_face_detector();
// shape_predictor pose_model;
// deserialize("/Users/edz/Downloads/shape_predictor_68_face_landmarks.dat") >> pose_model;
// Grab and process frames until the main window is closed by the user.
string photoPath = string(argv[1]);
string irisPath = string(argv[2]);
cv::Mat temp = imread(photoPath);
// cv_image<bgr_pixel> cimg(temp);
// Detect faces
// std::vector<dlib::rectangle> faces = detector(cimg);
// Find the pose of each face.
// std::vector<full_object_detection> shapes;
// for (unsigned long i = 0; i < faces.size(); ++i)
// shapes.push_back(pose_model(cimg, faces[i]));
int srcPoints[64*2];
// string pointJsonStr = "{\"request_id\":\"1617882543,a020830b-7fb2-4a6b-ad2f-46b4f85f8d1d\",\"time_used\":65,\"faces\":[{\"face_token\":\"3b4a8cf00f5ffb79d679e79760c8238a\",\"face_rectangle\":{\"top\":87,\"left\":179,\"width\":141,\"height\":141},\"landmark\":{\"contour_chin\":{\"x\":232,\"y\":227},\"contour_left1\":{\"x\":180,\"y\":107},\"contour_left10\":{\"x\":190,\"y\":184},\"contour_left11\":{\"x\":194,\"y\":192},\"contour_left12\":{\"x\":199,\"y\":199},\"contour_left13\":{\"x\":204,\"y\":206},\"contour_left14\":{\"x\":209,\"y\":213},\"contour_left15\":{\"x\":215,\"y\":219},\"contour_left16\":{\"x\":222,\"y\":224},\"contour_left2\":{\"x\":179,\"y\":116},\"contour_left3\":{\"x\":178,\"y\":125},\"contour_left4\":{\"x\":178,\"y\":133},\"contour_left5\":{\"x\":179,\"y\":142},\"contour_left6\":{\"x\":180,\"y\":151},\"contour_left7\":{\"x\":182,\"y\":159},\"contour_left8\":{\"x\":184,\"y\":168},\"contour_left9\":{\"x\":187,\"y\":176},\"contour_right1\":{\"x\":318,\"y\":103},\"contour_right10\":{\"x\":302,\"y\":194},\"contour_right11\":{\"x\":294,\"y\":202},\"contour_right12\":{\"x\":286,\"y\":209},\"contour_right13\":{\"x\":277,\"y\":215},\"contour_right14\":{\"x\":267,\"y\":220},\"contour_right15\":{\"x\":256,\"y\":225},\"contour_right16\":{\"x\":244,\"y\":227},\"contour_right2\":{\"x\":319,\"y\":113},\"contour_right3\":{\"x\":320,\"y\":124},\"contour_right4\":{\"x\":319,\"y\":134},\"contour_right5\":{\"x\":319,\"y\":144},\"contour_right6\":{\"x\":317,\"y\":155},\"contour_right7\":{\"x\":315,\"y\":165},\"contour_right8\":{\"x\":312,\"y\":175},\"contour_right9\":{\"x\":307,\"y\":185},\"left_eye_bottom\":{\"x\":198,\"y\":119},\"left_eye_center\":{\"x\":203,\"y\":114},\"left_eye_left_corner\":{\"x\":188,\"y\":115},\"left_eye_lower_left_quarter\":{\"x\":192,\"y\":118},\"left_eye_lower_right_quarter\":{\"x\":205,\"y\":119},\"left_eye_pupil\":{\"x\":203,\"y\":114},\"left_eye_right_corner\":{\"x\":212,\"y\":118},\"left_eye_top\":{\"x\":199,\"y\":109},\"left_eye_upper_left_quarter\":{\"x\":192,\"y\":110},\"left_eye_upper_right_quarter\":{\"x\":207,\"y\":111},\"left_eyebrow_left_corner\":{\"x\":178,\"y\":98},\"left_eyebrow_lower_left_quarter\":{\"x\":185,\"y\":98},\"left_eyebrow_lower_middle\":{\"x\":193,\"y\":98},\"left_eyebrow_lower_right_corner\":{\"x\":210,\"y\":102},\"left_eyebrow_lower_right_quarter\":{\"x\":202,\"y\":99},\"left_eyebrow_upper_left_quarter\":{\"x\":184,\"y\":91},\"left_eyebrow_upper_middle\":{\"x\":193,\"y\":90},\"left_eyebrow_upper_right_corner\":{\"x\":211,\"y\":97},\"left_eyebrow_upper_right_quarter\":{\"x\":203,\"y\":92},\"mouth_left_corner\":{\"x\":209,\"y\":182},\"mouth_lower_lip_bottom\":{\"x\":230,\"y\":197},\"mouth_lower_lip_left_contour1\":{\"x\":219,\"y\":186},\"mouth_lower_lip_left_contour2\":{\"x\":214,\"y\":189},\"mouth_lower_lip_left_contour3\":{\"x\":220,\"y\":195},\"mouth_lower_lip_right_contour1\":{\"x\":246,\"y\":186},\"mouth_lower_lip_right_contour2\":{\"x\":254,\"y\":189},\"mouth_lower_lip_right_contour3\":{\"x\":243,\"y\":195},\"mouth_lower_lip_top\":{\"x\":229,\"y\":187},\"mouth_right_corner\":{\"x\":263,\"y\":181},\"mouth_upper_lip_bottom\":{\"x\":229,\"y\":186},\"mouth_upper_lip_left_contour1\":{\"x\":222,\"y\":179},\"mouth_upper_lip_left_contour2\":{\"x\":215,\"y\":180},\"mouth_upper_lip_left_contour3\":{\"x\":212,\"y\":183},\"mouth_upper_lip_left_contour4\":{\"x\":219,\"y\":185},\"mouth_upper_lip_right_contour1\":{\"x\":235,\"y\":179},\"mouth_upper_lip_right_contour2\":{\"x\":249,\"y\":180},\"mouth_upper_lip_right_contour3\":{\"x\":258,\"y\":182},\"mouth_upper_lip_right_contour4\":{\"x\":245,\"y\":184},\"mouth_upper_lip_top\":{\"x\":228,\"y\":181},\"nose_bridge1\":{\"x\":225,\"y\":113},\"nose_bridge2\":{\"x\":223,\"y\":127},\"nose_bridge3\":{\"x\":220,\"y\":141},\"nose_left_contour1\":{\"x\":219,\"y\":119},\"nose_left_contour2\":{\"x\":213,\"y\":148},\"nose_left_contour3\":{\"x\":210,\"y\":160},\"nose_left_contour4\":{\"x\":213,\"y\":164},\"nose_left_contour5\":{\"x\":218,\"y\":166},\"nose_middle_contour\":{\"x\":224,\"y\":168},\"nose_right_contour1\":{\"x\":237,\"y\":117},\"nose_right_contour2\":{\"x\":241,\"y\":147},\"nose_right_contour3\":{\"x\":246,\"y\":160},\"nose_right_contour4\":{\"x\":239,\"y\":164},\"nose_right_contour5\":{\"x\":231,\"y\":166},\"nose_tip\":{\"x\":217,\"y\":156},\"right_eye_bottom\":{\"x\":262,\"y\":119},\"right_eye_center\":{\"x\":264,\"y\":112},\"right_eye_left_corner\":{\"x\":246,\"y\":118},\"right_eye_lower_left_quarter\":{\"x\":254,\"y\":119},\"right_eye_lower_right_quarter\":{\"x\":270,\"y\":117},\"right_eye_pupil\":{\"x\":264,\"y\":112},\"right_eye_right_corner\":{\"x\":277,\"y\":113},\"right_eye_top\":{\"x\":261,\"y\":107},\"right_eye_upper_left_quarter\":{\"x\":252,\"y\":111},\"right_eye_upper_right_quarter\":{\"x\":269,\"y\":109},\"right_eyebrow_lower_left_corner\":{\"x\":239,\"y\":99},\"right_eyebrow_lower_left_quarter\":{\"x\":251,\"y\":97},\"right_eyebrow_lower_middle\":{\"x\":264,\"y\":96},\"right_eyebrow_lower_right_quarter\":{\"x\":278,\"y\":97},\"right_eyebrow_right_corner\":{\"x\":292,\"y\":99},\"right_eyebrow_upper_left_corner\":{\"x\":238,\"y\":93},\"right_eyebrow_upper_left_quarter\":{\"x\":250,\"y\":90},\"right_eyebrow_upper_middle\":{\"x\":264,\"y\":89},\"right_eyebrow_upper_right_quarter\":{\"x\":279,\"y\":91}}}],\"image_id\":\"2yT1Ccz7vyIPlJqmEXE+oQ==\",\"face_num\":1}";
string pointJsonStr = "{\"time_used\": 134, \"request_id\": \"1617937070,e4fb445c-50af-4a8c-be39-14c58e946507\", \"face\": {\"landmark\": {\"right_eye\": {\"right_eye_pupil_center\": {\"y\": 113, \"x\": 262}, \"right_eye_38\": {\"y\": 119, \"x\": 253}, \"right_eye_39\": {\"y\": 119, \"x\": 254}, \"right_eye_36\": {\"y\": 118, \"x\": 252}, \"right_eye_37\": {\"y\": 118, \"x\": 253}, \"right_eye_34\": {\"y\": 118, \"x\": 250}, \"right_eye_35\": {\"y\": 118, \"x\": 251}, \"right_eye_32\": {\"y\": 117, \"x\": 249}, \"right_eye_33\": {\"y\": 117, \"x\": 249}, \"right_eye_30\": {\"y\": 115, \"x\": 249}, \"right_eye_31\": {\"y\": 116, \"x\": 249}, \"right_eye_10\": {\"y\": 108, \"x\": 266}, \"right_eye_11\": {\"y\": 108, \"x\": 265}, \"right_eye_12\": {\"y\": 108, \"x\": 264}, \"right_eye_13\": {\"y\": 108, \"x\": 263}, \"right_eye_14\": {\"y\": 108, \"x\": 262}, \"right_eye_15\": {\"y\": 108, \"x\": 261}, \"right_eye_16\": {\"y\": 108, \"x\": 260}, \"right_eye_17\": {\"y\": 108, \"x\": 259}, \"right_eye_18\": {\"y\": 109, \"x\": 258}, \"right_eye_19\": {\"y\": 109, \"x\": 257}, \"right_eye_56\": {\"y\": 117, \"x\": 269}, \"right_eye_57\": {\"y\": 116, \"x\": 270}, \"right_eye_50\": {\"y\": 118, \"x\": 264}, \"right_eye_51\": {\"y\": 118, \"x\": 265}, \"right_eye_52\": {\"y\": 118, \"x\": 266}, \"right_eye_53\": {\"y\": 118, \"x\": 266}, \"right_eye_pupil_radius\": 6, \"right_eye_8\": {\"y\": 109, \"x\": 267}, \"right_eye_9\": {\"y\": 109, \"x\": 266}, \"right_eye_6\": {\"y\": 109, \"x\": 269}, \"right_eye_7\": {\"y\": 109, \"x\": 268}, \"right_eye_4\": {\"y\": 110, \"x\": 271}, \"right_eye_5\": {\"y\": 110, \"x\": 270}, \"right_eye_2\": {\"y\": 111, \"x\": 272}, \"right_eye_3\": {\"y\": 111, \"x\": 272}, \"right_eye_0\": {\"y\": 113, \"x\": 273}, \"right_eye_1\": {\"y\": 112, \"x\": 273}, \"right_eye_58\": {\"y\": 116, \"x\": 270}, \"right_eye_29\": {\"y\": 114, \"x\": 249}, \"right_eye_28\": {\"y\": 113, \"x\": 250}, \"right_eye_62\": {\"y\": 114, \"x\": 273}, \"right_eye_21\": {\"y\": 109, \"x\": 255}, \"right_eye_20\": {\"y\": 109, \"x\": 256}, \"right_eye_23\": {\"y\": 110, \"x\": 254}, \"right_eye_22\": {\"y\": 110, \"x\": 254}, \"right_eye_25\": {\"y\": 111, \"x\": 252}, \"right_eye_24\": {\"y\": 111, \"x\": 253}, \"right_eye_27\": {\"y\": 112, \"x\": 251}, \"right_eye_26\": {\"y\": 112, \"x\": 251}, \"right_eye_59\": {\"y\": 116, \"x\": 271}, \"right_eye_61\": {\"y\": 115, \"x\": 272}, \"right_eye_60\": {\"y\": 115, \"x\": 272}, \"right_eye_49\": {\"y\": 119, \"x\": 263}, \"right_eye_48\": {\"y\": 119, \"x\": 262}, \"right_eye_47\": {\"y\": 119, \"x\": 261}, \"right_eye_46\": {\"y\": 119, \"x\": 260}, \"right_eye_45\": {\"y\": 119, \"x\": 259}, \"right_eye_44\": {\"y\": 119, \"x\": 259}, \"right_eye_43\": {\"y\": 119, \"x\": 258}, \"right_eye_42\": {\"y\": 119, \"x\": 257}, \"right_eye_41\": {\"y\": 119, \"x\": 256}, \"right_eye_40\": {\"y\": 119, \"x\": 255}, \"right_eye_54\": {\"y\": 117, \"x\": 267}, \"right_eye_55\": {\"y\": 117, \"x\": 268}}}, \"face_rectangle\": {\"width\": 143, \"top\": 86, \"height\": 143, \"left\": 177}}}";
Poco::JSON::Parser parser;
const Dynamic::Var &var = parser.parse(pointJsonStr);
int right_eye_pupil_radius;
if(!var.isEmpty()){
const JSON::Object::Ptr &objPtr = var.extract<Poco::JSON::Object::Ptr>();
// const JSON::Array::Ptr &facesArrayPtr = objPtr->getArray("faces");
//1000关键点
const JSON::Object::Ptr &facesArrayPtr = objPtr->getObject("face");
// const SharedPtr<Poco::JSON::Object> &faceItem0 = facesArrayPtr->getObject(0);
JSON::Object::Ptr pointPtr = facesArrayPtr->getObject("landmark");
int x,y;
JSON::Object::Ptr point;
string direct;
direct = "right";
std::vector<string> rightPoints = {direct+"_eye_left_corner",direct+"_eye_upper_left_quarter",direct+"_eye_top",
direct+"_eye_upper_right_quarter",direct+"_eye_right_corner",direct+"_eye_lower_right_quarter",
direct+"_eye_bottom",direct+"_eye_lower_left_quarter",direct+"_eye_pupil"};
direct = "left";
std::vector<string> leftPoints = {direct+"_eye_left_corner",direct+"_eye_upper_left_quarter",direct+"_eye_top",
direct+"_eye_upper_right_quarter",direct+"_eye_right_corner",direct+"_eye_lower_right_quarter",
direct+"_eye_bottom",direct+"_eye_lower_left_quarter",direct+"_eye_pupil"};
// for(int i=0,index=0;i<rightPoints.size();++i){
// point = pointPtr->getObject(rightPoints.at(i));
// x = point->get("x");
// y = point->get("y");
//// putText(temp, to_string(i), cvPoint(x - 10, y - 10),FONT_HERSHEY_SIMPLEX, 0.2, (0, 255, 0), 1);
//// circle(temp, cvPoint(x, y), 1, cv::Scalar(0, 0, 255), -1);
// srcPoints[index++] = x;
// srcPoints[index++] = y;
// }
//1000点
pointPtr = pointPtr->getObject("right_eye");
const JSON::Object::NameList &names = pointPtr->getNames();
cout << names.size() << endl;
int right_eye_pupil_center_x;
int right_eye_pupil_center_y;
for(int i=0,index=0;i<names.size();++i){
string key = names.at(i);
if("right_eye_pupil_radius"==key){
right_eye_pupil_radius = pointPtr->get(key);
continue;
}
point = pointPtr->getObject(key);
if("right_eye_pupil_center"==key){
right_eye_pupil_center_x = point->get("x");
right_eye_pupil_center_y = point->get("y");
srcPoints[2*63] = right_eye_pupil_center_x;
srcPoints[2*63+1] = right_eye_pupil_center_y;
continue;
}
x = point->get("x");
y = point->get("y");
// putText(temp, to_string(i), cvPoint(x - 10, y - 10),FONT_HERSHEY_SIMPLEX, 0.2, (0, 255, 0), 1);
// circle(temp, cvPoint(x, y), 1, cv::Scalar(0, 0, 255), -1);
srcPoints[index++] = x;
srcPoints[index++] = y;
}
// circle(temp, cvPoint(right_eye_pupil_center_x, right_eye_pupil_center_y), right_eye_pupil_radius, cv::Scalar(0, 255, 0), 1);
cout << "right_eye_pupil_radius=" << right_eye_pupil_radius << endl;
} }
std::cout << std::endl; // if (!shapes.empty()) {
// for (int i = 0,index = 0; i < 68; i++) {
// if(i>=36&&i<=41){
// cout << "编号"<< i << "," << "x=" << shapes[0].part(i).x() << ",y=" << shapes[0].part(i).y() << endl;
// circle(temp, cvPoint(shapes[0].part(i).x(), shapes[0].part(i).y()), 3, cv::Scalar(0, 0, 255), -1);
// srcPoints[index++] = shapes[0].part(i).x();
// srcPoints[index++] = shapes[0].part(i).y();
// }
// }
// int cenx = (srcPoints[2 * 0] + srcPoints[2 * 3])/2;
// int ceny = (srcPoints[2 * 0 + 1] + srcPoints[2 * 3 + 1])/2;
// circle(temp, cvPoint(cenx, ceny), 3, cv::Scalar(0, 0, 255), -1);
// }
//Display it all on the screen
// imshow("Dlib特征点", temp);
// waitKey(0);
//美瞳
cv::Mat meitong = imread(irisPath);
unsigned char* maskData = meitong.data;
int mWidth = meitong.cols, mHeight = meitong.rows, mStride = mWidth * meitong.channels();
unsigned char* srcData = temp.data;
int width = temp.cols, height = temp.rows, stride = width * temp.channels();
// f_BeautyIris(srcData,width,height,stride,srcPoints,maskData,mWidth,mHeight,mStride,NULL,100,right_eye_pupil_radius);
imshow("美瞳", temp);
waitKey(0);
}
catch (serialization_error& e)
{
cout << "You need dlib's default face landmarking model file to run this example." << endl;
cout << "You can get it from the following URL: " << endl;
cout << " http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl;
cout << endl << e.what() << endl;
} }
facesdk_readModelFromFile(ModelType::Attribution, "/srv/apps/TengineKit-master/Linux/models/face_attr.bin", ImageFormat::RGB); catch (exception& e)
sdkFaces faces3 = facesdk_attribute();
std::cout << faces3.face_count << std::endl;
for (int i = 0; i < faces3.face_count; i++)
{ {
std::cout << "age: " << faces3.info[i].attribution.age << std::endl; cout << e.what() << endl;
std::cout << "gender: " << faces3.info[i].attribution.gender << std::endl;
std::cout << "glasses: " << faces3.info[i].attribution.glasses << std::endl;
std::cout << "smile: " << faces3.info[i].attribution.smile << std::endl;
std::cout << "beauty_man_look: " << faces3.info[i].attribution.beauty_man_look << std::endl;
std::cout << "beauty_woman_look: " << faces3.info[i].attribution.beauty_woman_look << std::endl;
} }
cv::imwrite("output/output.jpg", frame);
facesdk_release(); // Mat face = imread("/Users/edz/Downloads/tongshi.png");
// imshow("face",face);
// waitKey(0);
// cout << "aaa" << endl;
} }
int main30(int argc, char* argv[]){
try
{
// Load face detection and pose estimation models.
frontal_face_detector detector = get_frontal_face_detector();
shape_predictor pose_model;
deserialize("/Users/edz/Downloads/shape_predictor_68_face_landmarks.dat") >> pose_model;
// Grab and process frames until the main window is closed by the user.
string photoPath = string(argv[1]);
string irisPath = string(argv[2]);
cv::Mat temp = imread(photoPath);
cv_image<bgr_pixel> cimg(temp);
// Detect faces
std::vector<dlib::rectangle> faces = detector(cimg);
// Find the pose of each face.
std::vector<full_object_detection> shapes;
for (unsigned long i = 0; i < faces.size(); ++i)
shapes.push_back(pose_model(cimg, faces[i]));
int srcPoints[6*2];
// string pointJsonStr = "{\"request_id\":\"1617882543,a020830b-7fb2-4a6b-ad2f-46b4f85f8d1d\",\"time_used\":65,\"faces\":[{\"face_token\":\"3b4a8cf00f5ffb79d679e79760c8238a\",\"face_rectangle\":{\"top\":87,\"left\":179,\"width\":141,\"height\":141},\"landmark\":{\"contour_chin\":{\"x\":232,\"y\":227},\"contour_left1\":{\"x\":180,\"y\":107},\"contour_left10\":{\"x\":190,\"y\":184},\"contour_left11\":{\"x\":194,\"y\":192},\"contour_left12\":{\"x\":199,\"y\":199},\"contour_left13\":{\"x\":204,\"y\":206},\"contour_left14\":{\"x\":209,\"y\":213},\"contour_left15\":{\"x\":215,\"y\":219},\"contour_left16\":{\"x\":222,\"y\":224},\"contour_left2\":{\"x\":179,\"y\":116},\"contour_left3\":{\"x\":178,\"y\":125},\"contour_left4\":{\"x\":178,\"y\":133},\"contour_left5\":{\"x\":179,\"y\":142},\"contour_left6\":{\"x\":180,\"y\":151},\"contour_left7\":{\"x\":182,\"y\":159},\"contour_left8\":{\"x\":184,\"y\":168},\"contour_left9\":{\"x\":187,\"y\":176},\"contour_right1\":{\"x\":318,\"y\":103},\"contour_right10\":{\"x\":302,\"y\":194},\"contour_right11\":{\"x\":294,\"y\":202},\"contour_right12\":{\"x\":286,\"y\":209},\"contour_right13\":{\"x\":277,\"y\":215},\"contour_right14\":{\"x\":267,\"y\":220},\"contour_right15\":{\"x\":256,\"y\":225},\"contour_right16\":{\"x\":244,\"y\":227},\"contour_right2\":{\"x\":319,\"y\":113},\"contour_right3\":{\"x\":320,\"y\":124},\"contour_right4\":{\"x\":319,\"y\":134},\"contour_right5\":{\"x\":319,\"y\":144},\"contour_right6\":{\"x\":317,\"y\":155},\"contour_right7\":{\"x\":315,\"y\":165},\"contour_right8\":{\"x\":312,\"y\":175},\"contour_right9\":{\"x\":307,\"y\":185},\"left_eye_bottom\":{\"x\":198,\"y\":119},\"left_eye_center\":{\"x\":203,\"y\":114},\"left_eye_left_corner\":{\"x\":188,\"y\":115},\"left_eye_lower_left_quarter\":{\"x\":192,\"y\":118},\"left_eye_lower_right_quarter\":{\"x\":205,\"y\":119},\"left_eye_pupil\":{\"x\":203,\"y\":114},\"left_eye_right_corner\":{\"x\":212,\"y\":118},\"left_eye_top\":{\"x\":199,\"y\":109},\"left_eye_upper_left_quarter\":{\"x\":192,\"y\":110},\"left_eye_upper_right_quarter\":{\"x\":207,\"y\":111},\"left_eyebrow_left_corner\":{\"x\":178,\"y\":98},\"left_eyebrow_lower_left_quarter\":{\"x\":185,\"y\":98},\"left_eyebrow_lower_middle\":{\"x\":193,\"y\":98},\"left_eyebrow_lower_right_corner\":{\"x\":210,\"y\":102},\"left_eyebrow_lower_right_quarter\":{\"x\":202,\"y\":99},\"left_eyebrow_upper_left_quarter\":{\"x\":184,\"y\":91},\"left_eyebrow_upper_middle\":{\"x\":193,\"y\":90},\"left_eyebrow_upper_right_corner\":{\"x\":211,\"y\":97},\"left_eyebrow_upper_right_quarter\":{\"x\":203,\"y\":92},\"mouth_left_corner\":{\"x\":209,\"y\":182},\"mouth_lower_lip_bottom\":{\"x\":230,\"y\":197},\"mouth_lower_lip_left_contour1\":{\"x\":219,\"y\":186},\"mouth_lower_lip_left_contour2\":{\"x\":214,\"y\":189},\"mouth_lower_lip_left_contour3\":{\"x\":220,\"y\":195},\"mouth_lower_lip_right_contour1\":{\"x\":246,\"y\":186},\"mouth_lower_lip_right_contour2\":{\"x\":254,\"y\":189},\"mouth_lower_lip_right_contour3\":{\"x\":243,\"y\":195},\"mouth_lower_lip_top\":{\"x\":229,\"y\":187},\"mouth_right_corner\":{\"x\":263,\"y\":181},\"mouth_upper_lip_bottom\":{\"x\":229,\"y\":186},\"mouth_upper_lip_left_contour1\":{\"x\":222,\"y\":179},\"mouth_upper_lip_left_contour2\":{\"x\":215,\"y\":180},\"mouth_upper_lip_left_contour3\":{\"x\":212,\"y\":183},\"mouth_upper_lip_left_contour4\":{\"x\":219,\"y\":185},\"mouth_upper_lip_right_contour1\":{\"x\":235,\"y\":179},\"mouth_upper_lip_right_contour2\":{\"x\":249,\"y\":180},\"mouth_upper_lip_right_contour3\":{\"x\":258,\"y\":182},\"mouth_upper_lip_right_contour4\":{\"x\":245,\"y\":184},\"mouth_upper_lip_top\":{\"x\":228,\"y\":181},\"nose_bridge1\":{\"x\":225,\"y\":113},\"nose_bridge2\":{\"x\":223,\"y\":127},\"nose_bridge3\":{\"x\":220,\"y\":141},\"nose_left_contour1\":{\"x\":219,\"y\":119},\"nose_left_contour2\":{\"x\":213,\"y\":148},\"nose_left_contour3\":{\"x\":210,\"y\":160},\"nose_left_contour4\":{\"x\":213,\"y\":164},\"nose_left_contour5\":{\"x\":218,\"y\":166},\"nose_middle_contour\":{\"x\":224,\"y\":168},\"nose_right_contour1\":{\"x\":237,\"y\":117},\"nose_right_contour2\":{\"x\":241,\"y\":147},\"nose_right_contour3\":{\"x\":246,\"y\":160},\"nose_right_contour4\":{\"x\":239,\"y\":164},\"nose_right_contour5\":{\"x\":231,\"y\":166},\"nose_tip\":{\"x\":217,\"y\":156},\"right_eye_bottom\":{\"x\":262,\"y\":119},\"right_eye_center\":{\"x\":264,\"y\":112},\"right_eye_left_corner\":{\"x\":246,\"y\":118},\"right_eye_lower_left_quarter\":{\"x\":254,\"y\":119},\"right_eye_lower_right_quarter\":{\"x\":270,\"y\":117},\"right_eye_pupil\":{\"x\":264,\"y\":112},\"right_eye_right_corner\":{\"x\":277,\"y\":113},\"right_eye_top\":{\"x\":261,\"y\":107},\"right_eye_upper_left_quarter\":{\"x\":252,\"y\":111},\"right_eye_upper_right_quarter\":{\"x\":269,\"y\":109},\"right_eyebrow_lower_left_corner\":{\"x\":239,\"y\":99},\"right_eyebrow_lower_left_quarter\":{\"x\":251,\"y\":97},\"right_eyebrow_lower_middle\":{\"x\":264,\"y\":96},\"right_eyebrow_lower_right_quarter\":{\"x\":278,\"y\":97},\"right_eyebrow_right_corner\":{\"x\":292,\"y\":99},\"right_eyebrow_upper_left_corner\":{\"x\":238,\"y\":93},\"right_eyebrow_upper_left_quarter\":{\"x\":250,\"y\":90},\"right_eyebrow_upper_middle\":{\"x\":264,\"y\":89},\"right_eyebrow_upper_right_quarter\":{\"x\":279,\"y\":91}}}],\"image_id\":\"2yT1Ccz7vyIPlJqmEXE+oQ==\",\"face_num\":1}";
// string pointJsonStr = "{\"time_used\": 134, \"request_id\": \"1617937070,e4fb445c-50af-4a8c-be39-14c58e946507\", \"face\": {\"landmark\": {\"right_eye\": {\"right_eye_pupil_center\": {\"y\": 113, \"x\": 262}, \"right_eye_38\": {\"y\": 119, \"x\": 253}, \"right_eye_39\": {\"y\": 119, \"x\": 254}, \"right_eye_36\": {\"y\": 118, \"x\": 252}, \"right_eye_37\": {\"y\": 118, \"x\": 253}, \"right_eye_34\": {\"y\": 118, \"x\": 250}, \"right_eye_35\": {\"y\": 118, \"x\": 251}, \"right_eye_32\": {\"y\": 117, \"x\": 249}, \"right_eye_33\": {\"y\": 117, \"x\": 249}, \"right_eye_30\": {\"y\": 115, \"x\": 249}, \"right_eye_31\": {\"y\": 116, \"x\": 249}, \"right_eye_10\": {\"y\": 108, \"x\": 266}, \"right_eye_11\": {\"y\": 108, \"x\": 265}, \"right_eye_12\": {\"y\": 108, \"x\": 264}, \"right_eye_13\": {\"y\": 108, \"x\": 263}, \"right_eye_14\": {\"y\": 108, \"x\": 262}, \"right_eye_15\": {\"y\": 108, \"x\": 261}, \"right_eye_16\": {\"y\": 108, \"x\": 260}, \"right_eye_17\": {\"y\": 108, \"x\": 259}, \"right_eye_18\": {\"y\": 109, \"x\": 258}, \"right_eye_19\": {\"y\": 109, \"x\": 257}, \"right_eye_56\": {\"y\": 117, \"x\": 269}, \"right_eye_57\": {\"y\": 116, \"x\": 270}, \"right_eye_50\": {\"y\": 118, \"x\": 264}, \"right_eye_51\": {\"y\": 118, \"x\": 265}, \"right_eye_52\": {\"y\": 118, \"x\": 266}, \"right_eye_53\": {\"y\": 118, \"x\": 266}, \"right_eye_pupil_radius\": 6, \"right_eye_8\": {\"y\": 109, \"x\": 267}, \"right_eye_9\": {\"y\": 109, \"x\": 266}, \"right_eye_6\": {\"y\": 109, \"x\": 269}, \"right_eye_7\": {\"y\": 109, \"x\": 268}, \"right_eye_4\": {\"y\": 110, \"x\": 271}, \"right_eye_5\": {\"y\": 110, \"x\": 270}, \"right_eye_2\": {\"y\": 111, \"x\": 272}, \"right_eye_3\": {\"y\": 111, \"x\": 272}, \"right_eye_0\": {\"y\": 113, \"x\": 273}, \"right_eye_1\": {\"y\": 112, \"x\": 273}, \"right_eye_58\": {\"y\": 116, \"x\": 270}, \"right_eye_29\": {\"y\": 114, \"x\": 249}, \"right_eye_28\": {\"y\": 113, \"x\": 250}, \"right_eye_62\": {\"y\": 114, \"x\": 273}, \"right_eye_21\": {\"y\": 109, \"x\": 255}, \"right_eye_20\": {\"y\": 109, \"x\": 256}, \"right_eye_23\": {\"y\": 110, \"x\": 254}, \"right_eye_22\": {\"y\": 110, \"x\": 254}, \"right_eye_25\": {\"y\": 111, \"x\": 252}, \"right_eye_24\": {\"y\": 111, \"x\": 253}, \"right_eye_27\": {\"y\": 112, \"x\": 251}, \"right_eye_26\": {\"y\": 112, \"x\": 251}, \"right_eye_59\": {\"y\": 116, \"x\": 271}, \"right_eye_61\": {\"y\": 115, \"x\": 272}, \"right_eye_60\": {\"y\": 115, \"x\": 272}, \"right_eye_49\": {\"y\": 119, \"x\": 263}, \"right_eye_48\": {\"y\": 119, \"x\": 262}, \"right_eye_47\": {\"y\": 119, \"x\": 261}, \"right_eye_46\": {\"y\": 119, \"x\": 260}, \"right_eye_45\": {\"y\": 119, \"x\": 259}, \"right_eye_44\": {\"y\": 119, \"x\": 259}, \"right_eye_43\": {\"y\": 119, \"x\": 258}, \"right_eye_42\": {\"y\": 119, \"x\": 257}, \"right_eye_41\": {\"y\": 119, \"x\": 256}, \"right_eye_40\": {\"y\": 119, \"x\": 255}, \"right_eye_54\": {\"y\": 117, \"x\": 267}, \"right_eye_55\": {\"y\": 117, \"x\": 268}}}, \"face_rectangle\": {\"width\": 143, \"top\": 86, \"height\": 143, \"left\": 177}}}";
string pointJsonStr = "{\"time_used\": 163, \"request_id\": \"1617953825,2bfa2aa7-07df-4bec-bbc2-712b04fd1aae\", \"face\": {\"landmark\": {\"right_eye\": {\"right_eye_pupil_center\": {\"y\": 162, \"x\": 476}, \"right_eye_38\": {\"y\": 178, \"x\": 449}, \"right_eye_39\": {\"y\": 179, \"x\": 452}, \"right_eye_36\": {\"y\": 176, \"x\": 444}, \"right_eye_37\": {\"y\": 177, \"x\": 446}, \"right_eye_34\": {\"y\": 174, \"x\": 439}, \"right_eye_35\": {\"y\": 175, \"x\": 441}, \"right_eye_32\": {\"y\": 170, \"x\": 435}, \"right_eye_33\": {\"y\": 172, \"x\": 437}, \"right_eye_30\": {\"y\": 164, \"x\": 437}, \"right_eye_31\": {\"y\": 167, \"x\": 436}, \"right_eye_10\": {\"y\": 154, \"x\": 494}, \"right_eye_11\": {\"y\": 153, \"x\": 491}, \"right_eye_12\": {\"y\": 153, \"x\": 488}, \"right_eye_13\": {\"y\": 152, \"x\": 485}, \"right_eye_14\": {\"y\": 151, \"x\": 482}, \"right_eye_15\": {\"y\": 151, \"x\": 479}, \"right_eye_16\": {\"y\": 151, \"x\": 476}, \"right_eye_17\": {\"y\": 151, \"x\": 473}, \"right_eye_18\": {\"y\": 151, \"x\": 470}, \"right_eye_19\": {\"y\": 151, \"x\": 467}, \"right_eye_56\": {\"y\": 184, \"x\": 499}, \"right_eye_57\": {\"y\": 183, \"x\": 502}, \"right_eye_50\": {\"y\": 185, \"x\": 482}, \"right_eye_51\": {\"y\": 185, \"x\": 485}, \"right_eye_52\": {\"y\": 185, \"x\": 488}, \"right_eye_53\": {\"y\": 185, \"x\": 491}, \"right_eye_pupil_radius\": 21, \"right_eye_8\": {\"y\": 157, \"x\": 499}, \"right_eye_9\": {\"y\": 155, \"x\": 497}, \"right_eye_6\": {\"y\": 160, \"x\": 505}, \"right_eye_7\": {\"y\": 158, \"x\": 502}, \"right_eye_4\": {\"y\": 163, \"x\": 510}, \"right_eye_5\": {\"y\": 161, \"x\": 507}, \"right_eye_2\": {\"y\": 168, \"x\": 514}, \"right_eye_3\": {\"y\": 165, \"x\": 512}, \"right_eye_0\": {\"y\": 173, \"x\": 515}, \"right_eye_1\": {\"y\": 171, \"x\": 515}, \"right_eye_58\": {\"y\": 182, \"x\": 505}, \"right_eye_29\": {\"y\": 162, \"x\": 439}, \"right_eye_28\": {\"y\": 160, \"x\": 441}, \"right_eye_62\": {\"y\": 176, \"x\": 514}, \"right_eye_21\": {\"y\": 152, \"x\": 461}, \"right_eye_20\": {\"y\": 151, \"x\": 464}, \"right_eye_23\": {\"y\": 154, \"x\": 455}, \"right_eye_22\": {\"y\": 153, \"x\": 458}, \"right_eye_25\": {\"y\": 156, \"x\": 449}, \"right_eye_24\": {\"y\": 155, \"x\": 452}, \"right_eye_27\": {\"y\": 159, \"x\": 444}, \"right_eye_26\": {\"y\": 157, \"x\": 447}, \"right_eye_59\": {\"y\": 181, \"x\": 507}, \"right_eye_61\": {\"y\": 178, \"x\": 512}, \"right_eye_60\": {\"y\": 179, \"x\": 510}, \"right_eye_49\": {\"y\": 185, \"x\": 479}, \"right_eye_48\": {\"y\": 185, \"x\": 477}, \"right_eye_47\": {\"y\": 184, \"x\": 474}, \"right_eye_46\": {\"y\": 184, \"x\": 471}, \"right_eye_45\": {\"y\": 183, \"x\": 468}, \"right_eye_44\": {\"y\": 183, \"x\": 465}, \"right_eye_43\": {\"y\": 182, \"x\": 463}, \"right_eye_42\": {\"y\": 181, \"x\": 460}, \"right_eye_41\": {\"y\": 180, \"x\": 457}, \"right_eye_40\": {\"y\": 180, \"x\": 454}, \"right_eye_54\": {\"y\": 185, \"x\": 494}, \"right_eye_55\": {\"y\": 184, \"x\": 496}}}, \"face_rectangle\": {\"width\": 464, \"top\": 59, \"height\": 464, \"left\": 147}}}";
Poco::JSON::Parser parser;
const Dynamic::Var &var = parser.parse(pointJsonStr);
int right_eye_pupil_radius;
int right_eye_pupil_center_x;
int right_eye_pupil_center_y;
if(!var.isEmpty()){
const JSON::Object::Ptr &objPtr = var.extract<Poco::JSON::Object::Ptr>();
// const JSON::Array::Ptr &facesArrayPtr = objPtr->getArray("faces");
//1000关键点
const JSON::Object::Ptr &facesArrayPtr = objPtr->getObject("face");
// const SharedPtr<Poco::JSON::Object> &faceItem0 = facesArrayPtr->getObject(0);
JSON::Object::Ptr pointPtr = facesArrayPtr->getObject("landmark");
int x,y;
JSON::Object::Ptr point;
string direct;
direct = "right";
std::vector<string> rightPoints = {direct+"_eye_left_corner",direct+"_eye_upper_left_quarter",direct+"_eye_top",
direct+"_eye_upper_right_quarter",direct+"_eye_right_corner",direct+"_eye_lower_right_quarter",
direct+"_eye_bottom",direct+"_eye_lower_left_quarter",direct+"_eye_pupil"};
direct = "left";
std::vector<string> leftPoints = {direct+"_eye_left_corner",direct+"_eye_upper_left_quarter",direct+"_eye_top",
direct+"_eye_upper_right_quarter",direct+"_eye_right_corner",direct+"_eye_lower_right_quarter",
direct+"_eye_bottom",direct+"_eye_lower_left_quarter",direct+"_eye_pupil"};
// for(int i=0,index=0;i<rightPoints.size();++i){
// point = pointPtr->getObject(rightPoints.at(i));
// x = point->get("x");
// y = point->get("y");
//// putText(temp, to_string(i), cvPoint(x - 10, y - 10),FONT_HERSHEY_SIMPLEX, 0.2, (0, 255, 0), 1);
//// circle(temp, cvPoint(x, y), 1, cv::Scalar(0, 0, 255), -1);
// srcPoints[index++] = x;
// srcPoints[index++] = y;
// }
//1000点
pointPtr = pointPtr->getObject("right_eye");
const JSON::Object::NameList &names = pointPtr->getNames();
cout << names.size() << endl;
for(int i=0,index=0;i<names.size();++i){
string key = names.at(i);
if("right_eye_pupil_radius"==key){
right_eye_pupil_radius = pointPtr->get(key);
continue;
}
point = pointPtr->getObject(key);
if("right_eye_pupil_center"==key){
right_eye_pupil_center_x = point->get("x");
right_eye_pupil_center_y = point->get("y");
// srcPoints[2*63] = right_eye_pupil_center_x;
// srcPoints[2*63+1] = right_eye_pupil_center_y;
continue;
}
// x = point->get("x");
// y = point->get("y");
// putText(temp, to_string(i), cvPoint(x - 10, y - 10),FONT_HERSHEY_SIMPLEX, 0.2, (0, 255, 0), 1);
// circle(temp, cvPoint(x, y), 1, cv::Scalar(0, 0, 255), -1);
// srcPoints[index++] = x;
// srcPoints[index++] = y;
}
// circle(temp, cvPoint(right_eye_pupil_center_x, right_eye_pupil_center_y), right_eye_pupil_radius, cv::Scalar(0, 255, 0), 1);
cout << "right_eye_pupil_radius=" << right_eye_pupil_radius << endl;
}
if (!shapes.empty()) {
for (int i = 0,index = 0; i < 68; i++) {
if(i>=42&&i<=47){
cout << "编号"<< i << "," << "x=" << shapes[0].part(i).x() << ",y=" << shapes[0].part(i).y() << endl;
// circle(temp, cvPoint(shapes[0].part(i).x(), shapes[0].part(i).y()), 1, cv::Scalar(0, 0, 255), -1);
srcPoints[index++] = shapes[0].part(i).x();
srcPoints[index++] = shapes[0].part(i).y();
}
}
// int cenx = (srcPoints[2 * 0] + srcPoints[2 * 3])/2;
// int ceny = (srcPoints[2 * 0 + 1] + srcPoints[2 * 3 + 1])/2;
// circle(temp, cvPoint(right_eye_pupil_center_x, right_eye_pupil_center_y), 1, cv::Scalar(0, 0, 255), -1);
}
//Display it all on the screen
// imshow("Dlib特征点", temp);
// waitKey(0);
//美瞳
cv::Mat meitong = imread(irisPath);
unsigned char* maskData = meitong.data;
int mWidth = meitong.cols, mHeight = meitong.rows, mStride = mWidth * meitong.channels();
unsigned char* srcData = temp.data;
int width = temp.cols, height = temp.rows, stride = width * temp.channels();
f_BeautyIris(srcData,width,height,stride,srcPoints,maskData,mWidth,mHeight,mStride,NULL,100,right_eye_pupil_radius,right_eye_pupil_center_x,right_eye_pupil_center_y);
imshow("美瞳", temp);
waitKey(0);
}
catch (serialization_error& e)
{
cout << "You need dlib's default face landmarking model file to run this example." << endl;
cout << "You can get it from the following URL: " << endl;
cout << " http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl;
cout << endl << e.what() << endl;
}
catch (exception& e)
{
cout << e.what() << endl;
}
// Mat face = imread("/Users/edz/Downloads/tongshi.png");
// imshow("face",face);
// waitKey(0);
// cout << "aaa" << endl;
}
int main(int argc, char* argv[]){ int main(int argc, char* argv[]){
try
{
// Load face detection and pose estimation models.
// frontal_face_detector detector = get_frontal_face_detector();
// shape_predictor pose_model;
// deserialize("/Users/edz/Downloads/shape_predictor_68_face_landmarks.dat") >> pose_model;
// Grab and process frames until the main window is closed by the user.
string photoPath = string(argv[1]);
string irisPath = string(argv[2]);
cv::Mat temp = imread(photoPath);
// cv_image<bgr_pixel> cimg(temp);
// Detect faces
// std::vector<dlib::rectangle> faces = detector(cimg);
// Find the pose of each face.
// std::vector<full_object_detection> shapes;
// for (unsigned long i = 0; i < faces.size(); ++i)
// shapes.push_back(pose_model(cimg, faces[i]));
int srcPoints[63*2];
// string pointJsonStr = "{\"request_id\":\"1617882543,a020830b-7fb2-4a6b-ad2f-46b4f85f8d1d\",\"time_used\":65,\"faces\":[{\"face_token\":\"3b4a8cf00f5ffb79d679e79760c8238a\",\"face_rectangle\":{\"top\":87,\"left\":179,\"width\":141,\"height\":141},\"landmark\":{\"contour_chin\":{\"x\":232,\"y\":227},\"contour_left1\":{\"x\":180,\"y\":107},\"contour_left10\":{\"x\":190,\"y\":184},\"contour_left11\":{\"x\":194,\"y\":192},\"contour_left12\":{\"x\":199,\"y\":199},\"contour_left13\":{\"x\":204,\"y\":206},\"contour_left14\":{\"x\":209,\"y\":213},\"contour_left15\":{\"x\":215,\"y\":219},\"contour_left16\":{\"x\":222,\"y\":224},\"contour_left2\":{\"x\":179,\"y\":116},\"contour_left3\":{\"x\":178,\"y\":125},\"contour_left4\":{\"x\":178,\"y\":133},\"contour_left5\":{\"x\":179,\"y\":142},\"contour_left6\":{\"x\":180,\"y\":151},\"contour_left7\":{\"x\":182,\"y\":159},\"contour_left8\":{\"x\":184,\"y\":168},\"contour_left9\":{\"x\":187,\"y\":176},\"contour_right1\":{\"x\":318,\"y\":103},\"contour_right10\":{\"x\":302,\"y\":194},\"contour_right11\":{\"x\":294,\"y\":202},\"contour_right12\":{\"x\":286,\"y\":209},\"contour_right13\":{\"x\":277,\"y\":215},\"contour_right14\":{\"x\":267,\"y\":220},\"contour_right15\":{\"x\":256,\"y\":225},\"contour_right16\":{\"x\":244,\"y\":227},\"contour_right2\":{\"x\":319,\"y\":113},\"contour_right3\":{\"x\":320,\"y\":124},\"contour_right4\":{\"x\":319,\"y\":134},\"contour_right5\":{\"x\":319,\"y\":144},\"contour_right6\":{\"x\":317,\"y\":155},\"contour_right7\":{\"x\":315,\"y\":165},\"contour_right8\":{\"x\":312,\"y\":175},\"contour_right9\":{\"x\":307,\"y\":185},\"left_eye_bottom\":{\"x\":198,\"y\":119},\"left_eye_center\":{\"x\":203,\"y\":114},\"left_eye_left_corner\":{\"x\":188,\"y\":115},\"left_eye_lower_left_quarter\":{\"x\":192,\"y\":118},\"left_eye_lower_right_quarter\":{\"x\":205,\"y\":119},\"left_eye_pupil\":{\"x\":203,\"y\":114},\"left_eye_right_corner\":{\"x\":212,\"y\":118},\"left_eye_top\":{\"x\":199,\"y\":109},\"left_eye_upper_left_quarter\":{\"x\":192,\"y\":110},\"left_eye_upper_right_quarter\":{\"x\":207,\"y\":111},\"left_eyebrow_left_corner\":{\"x\":178,\"y\":98},\"left_eyebrow_lower_left_quarter\":{\"x\":185,\"y\":98},\"left_eyebrow_lower_middle\":{\"x\":193,\"y\":98},\"left_eyebrow_lower_right_corner\":{\"x\":210,\"y\":102},\"left_eyebrow_lower_right_quarter\":{\"x\":202,\"y\":99},\"left_eyebrow_upper_left_quarter\":{\"x\":184,\"y\":91},\"left_eyebrow_upper_middle\":{\"x\":193,\"y\":90},\"left_eyebrow_upper_right_corner\":{\"x\":211,\"y\":97},\"left_eyebrow_upper_right_quarter\":{\"x\":203,\"y\":92},\"mouth_left_corner\":{\"x\":209,\"y\":182},\"mouth_lower_lip_bottom\":{\"x\":230,\"y\":197},\"mouth_lower_lip_left_contour1\":{\"x\":219,\"y\":186},\"mouth_lower_lip_left_contour2\":{\"x\":214,\"y\":189},\"mouth_lower_lip_left_contour3\":{\"x\":220,\"y\":195},\"mouth_lower_lip_right_contour1\":{\"x\":246,\"y\":186},\"mouth_lower_lip_right_contour2\":{\"x\":254,\"y\":189},\"mouth_lower_lip_right_contour3\":{\"x\":243,\"y\":195},\"mouth_lower_lip_top\":{\"x\":229,\"y\":187},\"mouth_right_corner\":{\"x\":263,\"y\":181},\"mouth_upper_lip_bottom\":{\"x\":229,\"y\":186},\"mouth_upper_lip_left_contour1\":{\"x\":222,\"y\":179},\"mouth_upper_lip_left_contour2\":{\"x\":215,\"y\":180},\"mouth_upper_lip_left_contour3\":{\"x\":212,\"y\":183},\"mouth_upper_lip_left_contour4\":{\"x\":219,\"y\":185},\"mouth_upper_lip_right_contour1\":{\"x\":235,\"y\":179},\"mouth_upper_lip_right_contour2\":{\"x\":249,\"y\":180},\"mouth_upper_lip_right_contour3\":{\"x\":258,\"y\":182},\"mouth_upper_lip_right_contour4\":{\"x\":245,\"y\":184},\"mouth_upper_lip_top\":{\"x\":228,\"y\":181},\"nose_bridge1\":{\"x\":225,\"y\":113},\"nose_bridge2\":{\"x\":223,\"y\":127},\"nose_bridge3\":{\"x\":220,\"y\":141},\"nose_left_contour1\":{\"x\":219,\"y\":119},\"nose_left_contour2\":{\"x\":213,\"y\":148},\"nose_left_contour3\":{\"x\":210,\"y\":160},\"nose_left_contour4\":{\"x\":213,\"y\":164},\"nose_left_contour5\":{\"x\":218,\"y\":166},\"nose_middle_contour\":{\"x\":224,\"y\":168},\"nose_right_contour1\":{\"x\":237,\"y\":117},\"nose_right_contour2\":{\"x\":241,\"y\":147},\"nose_right_contour3\":{\"x\":246,\"y\":160},\"nose_right_contour4\":{\"x\":239,\"y\":164},\"nose_right_contour5\":{\"x\":231,\"y\":166},\"nose_tip\":{\"x\":217,\"y\":156},\"right_eye_bottom\":{\"x\":262,\"y\":119},\"right_eye_center\":{\"x\":264,\"y\":112},\"right_eye_left_corner\":{\"x\":246,\"y\":118},\"right_eye_lower_left_quarter\":{\"x\":254,\"y\":119},\"right_eye_lower_right_quarter\":{\"x\":270,\"y\":117},\"right_eye_pupil\":{\"x\":264,\"y\":112},\"right_eye_right_corner\":{\"x\":277,\"y\":113},\"right_eye_top\":{\"x\":261,\"y\":107},\"right_eye_upper_left_quarter\":{\"x\":252,\"y\":111},\"right_eye_upper_right_quarter\":{\"x\":269,\"y\":109},\"right_eyebrow_lower_left_corner\":{\"x\":239,\"y\":99},\"right_eyebrow_lower_left_quarter\":{\"x\":251,\"y\":97},\"right_eyebrow_lower_middle\":{\"x\":264,\"y\":96},\"right_eyebrow_lower_right_quarter\":{\"x\":278,\"y\":97},\"right_eyebrow_right_corner\":{\"x\":292,\"y\":99},\"right_eyebrow_upper_left_corner\":{\"x\":238,\"y\":93},\"right_eyebrow_upper_left_quarter\":{\"x\":250,\"y\":90},\"right_eyebrow_upper_middle\":{\"x\":264,\"y\":89},\"right_eyebrow_upper_right_quarter\":{\"x\":279,\"y\":91}}}],\"image_id\":\"2yT1Ccz7vyIPlJqmEXE+oQ==\",\"face_num\":1}";
// string pointJsonStr = "{\"time_used\": 134, \"request_id\": \"1617937070,e4fb445c-50af-4a8c-be39-14c58e946507\", \"face\": {\"landmark\": {\"right_eye\": {\"right_eye_pupil_center\": {\"y\": 113, \"x\": 262}, \"right_eye_38\": {\"y\": 119, \"x\": 253}, \"right_eye_39\": {\"y\": 119, \"x\": 254}, \"right_eye_36\": {\"y\": 118, \"x\": 252}, \"right_eye_37\": {\"y\": 118, \"x\": 253}, \"right_eye_34\": {\"y\": 118, \"x\": 250}, \"right_eye_35\": {\"y\": 118, \"x\": 251}, \"right_eye_32\": {\"y\": 117, \"x\": 249}, \"right_eye_33\": {\"y\": 117, \"x\": 249}, \"right_eye_30\": {\"y\": 115, \"x\": 249}, \"right_eye_31\": {\"y\": 116, \"x\": 249}, \"right_eye_10\": {\"y\": 108, \"x\": 266}, \"right_eye_11\": {\"y\": 108, \"x\": 265}, \"right_eye_12\": {\"y\": 108, \"x\": 264}, \"right_eye_13\": {\"y\": 108, \"x\": 263}, \"right_eye_14\": {\"y\": 108, \"x\": 262}, \"right_eye_15\": {\"y\": 108, \"x\": 261}, \"right_eye_16\": {\"y\": 108, \"x\": 260}, \"right_eye_17\": {\"y\": 108, \"x\": 259}, \"right_eye_18\": {\"y\": 109, \"x\": 258}, \"right_eye_19\": {\"y\": 109, \"x\": 257}, \"right_eye_56\": {\"y\": 117, \"x\": 269}, \"right_eye_57\": {\"y\": 116, \"x\": 270}, \"right_eye_50\": {\"y\": 118, \"x\": 264}, \"right_eye_51\": {\"y\": 118, \"x\": 265}, \"right_eye_52\": {\"y\": 118, \"x\": 266}, \"right_eye_53\": {\"y\": 118, \"x\": 266}, \"right_eye_pupil_radius\": 6, \"right_eye_8\": {\"y\": 109, \"x\": 267}, \"right_eye_9\": {\"y\": 109, \"x\": 266}, \"right_eye_6\": {\"y\": 109, \"x\": 269}, \"right_eye_7\": {\"y\": 109, \"x\": 268}, \"right_eye_4\": {\"y\": 110, \"x\": 271}, \"right_eye_5\": {\"y\": 110, \"x\": 270}, \"right_eye_2\": {\"y\": 111, \"x\": 272}, \"right_eye_3\": {\"y\": 111, \"x\": 272}, \"right_eye_0\": {\"y\": 113, \"x\": 273}, \"right_eye_1\": {\"y\": 112, \"x\": 273}, \"right_eye_58\": {\"y\": 116, \"x\": 270}, \"right_eye_29\": {\"y\": 114, \"x\": 249}, \"right_eye_28\": {\"y\": 113, \"x\": 250}, \"right_eye_62\": {\"y\": 114, \"x\": 273}, \"right_eye_21\": {\"y\": 109, \"x\": 255}, \"right_eye_20\": {\"y\": 109, \"x\": 256}, \"right_eye_23\": {\"y\": 110, \"x\": 254}, \"right_eye_22\": {\"y\": 110, \"x\": 254}, \"right_eye_25\": {\"y\": 111, \"x\": 252}, \"right_eye_24\": {\"y\": 111, \"x\": 253}, \"right_eye_27\": {\"y\": 112, \"x\": 251}, \"right_eye_26\": {\"y\": 112, \"x\": 251}, \"right_eye_59\": {\"y\": 116, \"x\": 271}, \"right_eye_61\": {\"y\": 115, \"x\": 272}, \"right_eye_60\": {\"y\": 115, \"x\": 272}, \"right_eye_49\": {\"y\": 119, \"x\": 263}, \"right_eye_48\": {\"y\": 119, \"x\": 262}, \"right_eye_47\": {\"y\": 119, \"x\": 261}, \"right_eye_46\": {\"y\": 119, \"x\": 260}, \"right_eye_45\": {\"y\": 119, \"x\": 259}, \"right_eye_44\": {\"y\": 119, \"x\": 259}, \"right_eye_43\": {\"y\": 119, \"x\": 258}, \"right_eye_42\": {\"y\": 119, \"x\": 257}, \"right_eye_41\": {\"y\": 119, \"x\": 256}, \"right_eye_40\": {\"y\": 119, \"x\": 255}, \"right_eye_54\": {\"y\": 117, \"x\": 267}, \"right_eye_55\": {\"y\": 117, \"x\": 268}}}, \"face_rectangle\": {\"width\": 143, \"top\": 86, \"height\": 143, \"left\": 177}}}";
string pointJsonStr = "{\"time_used\": 163, \"request_id\": \"1617953825,2bfa2aa7-07df-4bec-bbc2-712b04fd1aae\", \"face\": {\"landmark\": {\"right_eye\": {\"right_eye_pupil_center\": {\"y\": 162, \"x\": 476}, \"right_eye_38\": {\"y\": 178, \"x\": 449}, \"right_eye_39\": {\"y\": 179, \"x\": 452}, \"right_eye_36\": {\"y\": 176, \"x\": 444}, \"right_eye_37\": {\"y\": 177, \"x\": 446}, \"right_eye_34\": {\"y\": 174, \"x\": 439}, \"right_eye_35\": {\"y\": 175, \"x\": 441}, \"right_eye_32\": {\"y\": 170, \"x\": 435}, \"right_eye_33\": {\"y\": 172, \"x\": 437}, \"right_eye_30\": {\"y\": 164, \"x\": 437}, \"right_eye_31\": {\"y\": 167, \"x\": 436}, \"right_eye_10\": {\"y\": 154, \"x\": 494}, \"right_eye_11\": {\"y\": 153, \"x\": 491}, \"right_eye_12\": {\"y\": 153, \"x\": 488}, \"right_eye_13\": {\"y\": 152, \"x\": 485}, \"right_eye_14\": {\"y\": 151, \"x\": 482}, \"right_eye_15\": {\"y\": 151, \"x\": 479}, \"right_eye_16\": {\"y\": 151, \"x\": 476}, \"right_eye_17\": {\"y\": 151, \"x\": 473}, \"right_eye_18\": {\"y\": 151, \"x\": 470}, \"right_eye_19\": {\"y\": 151, \"x\": 467}, \"right_eye_56\": {\"y\": 184, \"x\": 499}, \"right_eye_57\": {\"y\": 183, \"x\": 502}, \"right_eye_50\": {\"y\": 185, \"x\": 482}, \"right_eye_51\": {\"y\": 185, \"x\": 485}, \"right_eye_52\": {\"y\": 185, \"x\": 488}, \"right_eye_53\": {\"y\": 185, \"x\": 491}, \"right_eye_pupil_radius\": 21, \"right_eye_8\": {\"y\": 157, \"x\": 499}, \"right_eye_9\": {\"y\": 155, \"x\": 497}, \"right_eye_6\": {\"y\": 160, \"x\": 505}, \"right_eye_7\": {\"y\": 158, \"x\": 502}, \"right_eye_4\": {\"y\": 163, \"x\": 510}, \"right_eye_5\": {\"y\": 161, \"x\": 507}, \"right_eye_2\": {\"y\": 168, \"x\": 514}, \"right_eye_3\": {\"y\": 165, \"x\": 512}, \"right_eye_0\": {\"y\": 173, \"x\": 515}, \"right_eye_1\": {\"y\": 171, \"x\": 515}, \"right_eye_58\": {\"y\": 182, \"x\": 505}, \"right_eye_29\": {\"y\": 162, \"x\": 439}, \"right_eye_28\": {\"y\": 160, \"x\": 441}, \"right_eye_62\": {\"y\": 176, \"x\": 514}, \"right_eye_21\": {\"y\": 152, \"x\": 461}, \"right_eye_20\": {\"y\": 151, \"x\": 464}, \"right_eye_23\": {\"y\": 154, \"x\": 455}, \"right_eye_22\": {\"y\": 153, \"x\": 458}, \"right_eye_25\": {\"y\": 156, \"x\": 449}, \"right_eye_24\": {\"y\": 155, \"x\": 452}, \"right_eye_27\": {\"y\": 159, \"x\": 444}, \"right_eye_26\": {\"y\": 157, \"x\": 447}, \"right_eye_59\": {\"y\": 181, \"x\": 507}, \"right_eye_61\": {\"y\": 178, \"x\": 512}, \"right_eye_60\": {\"y\": 179, \"x\": 510}, \"right_eye_49\": {\"y\": 185, \"x\": 479}, \"right_eye_48\": {\"y\": 185, \"x\": 477}, \"right_eye_47\": {\"y\": 184, \"x\": 474}, \"right_eye_46\": {\"y\": 184, \"x\": 471}, \"right_eye_45\": {\"y\": 183, \"x\": 468}, \"right_eye_44\": {\"y\": 183, \"x\": 465}, \"right_eye_43\": {\"y\": 182, \"x\": 463}, \"right_eye_42\": {\"y\": 181, \"x\": 460}, \"right_eye_41\": {\"y\": 180, \"x\": 457}, \"right_eye_40\": {\"y\": 180, \"x\": 454}, \"right_eye_54\": {\"y\": 185, \"x\": 494}, \"right_eye_55\": {\"y\": 184, \"x\": 496}}}, \"face_rectangle\": {\"width\": 464, \"top\": 59, \"height\": 464, \"left\": 147}}}";
// string pointJsonStr = "{\"time_used\": 244, \"request_id\": \"1617958929,46cc922f-79e7-4fa4-9c3d-38049509d080\", \"face\": {\"landmark\": {\"right_eye\": {\"right_eye_pupil_center\": {\"y\": 567, \"x\": 588}, \"right_eye_38\": {\"y\": 591, \"x\": 552}, \"right_eye_39\": {\"y\": 592, \"x\": 555}, \"right_eye_36\": {\"y\": 589, \"x\": 544}, \"right_eye_37\": {\"y\": 590, \"x\": 548}, \"right_eye_34\": {\"y\": 586, \"x\": 537}, \"right_eye_35\": {\"y\": 587, \"x\": 541}, \"right_eye_32\": {\"y\": 580, \"x\": 533}, \"right_eye_33\": {\"y\": 584, \"x\": 534}, \"right_eye_30\": {\"y\": 573, \"x\": 534}, \"right_eye_31\": {\"y\": 576, \"x\": 533}, \"right_eye_10\": {\"y\": 557, \"x\": 611}, \"right_eye_11\": {\"y\": 556, \"x\": 607}, \"right_eye_12\": {\"y\": 555, \"x\": 603}, \"right_eye_13\": {\"y\": 554, \"x\": 599}, \"right_eye_14\": {\"y\": 554, \"x\": 595}, \"right_eye_15\": {\"y\": 554, \"x\": 591}, \"right_eye_16\": {\"y\": 553, \"x\": 587}, \"right_eye_17\": {\"y\": 553, \"x\": 583}, \"right_eye_18\": {\"y\": 554, \"x\": 579}, \"right_eye_19\": {\"y\": 554, \"x\": 574}, \"right_eye_56\": {\"y\": 595, \"x\": 620}, \"right_eye_57\": {\"y\": 594, \"x\": 624}, \"right_eye_50\": {\"y\": 598, \"x\": 597}, \"right_eye_51\": {\"y\": 598, \"x\": 601}, \"right_eye_52\": {\"y\": 597, \"x\": 605}, \"right_eye_53\": {\"y\": 597, \"x\": 609}, \"right_eye_pupil_radius\": 33, \"right_eye_8\": {\"y\": 560, \"x\": 619}, \"right_eye_9\": {\"y\": 558, \"x\": 615}, \"right_eye_6\": {\"y\": 564, \"x\": 627}, \"right_eye_7\": {\"y\": 562, \"x\": 623}, \"right_eye_4\": {\"y\": 568, \"x\": 634}, \"right_eye_5\": {\"y\": 566, \"x\": 630}, \"right_eye_2\": {\"y\": 574, \"x\": 639}, \"right_eye_3\": {\"y\": 571, \"x\": 637}, \"right_eye_0\": {\"y\": 581, \"x\": 642}, \"right_eye_1\": {\"y\": 577, \"x\": 641}, \"right_eye_58\": {\"y\": 593, \"x\": 627}, \"right_eye_29\": {\"y\": 570, \"x\": 537}, \"right_eye_28\": {\"y\": 567, \"x\": 540}, \"right_eye_62\": {\"y\": 585, \"x\": 640}, \"right_eye_21\": {\"y\": 555, \"x\": 566}, \"right_eye_20\": {\"y\": 554, \"x\": 570}, \"right_eye_23\": {\"y\": 557, \"x\": 558}, \"right_eye_22\": {\"y\": 556, \"x\": 562}, \"right_eye_25\": {\"y\": 561, \"x\": 551}, \"right_eye_24\": {\"y\": 559, \"x\": 554}, \"right_eye_27\": {\"y\": 565, \"x\": 543}, \"right_eye_26\": {\"y\": 562, \"x\": 547}, \"right_eye_59\": {\"y\": 591, \"x\": 631}, \"right_eye_61\": {\"y\": 588, \"x\": 638}, \"right_eye_60\": {\"y\": 590, \"x\": 634}, \"right_eye_49\": {\"y\": 598, \"x\": 593}, \"right_eye_48\": {\"y\": 597, \"x\": 589}, \"right_eye_47\": {\"y\": 597, \"x\": 585}, \"right_eye_46\": {\"y\": 597, \"x\": 582}, \"right_eye_45\": {\"y\": 596, \"x\": 578}, \"right_eye_44\": {\"y\": 596, \"x\": 574}, \"right_eye_43\": {\"y\": 595, \"x\": 570}, \"right_eye_42\": {\"y\": 594, \"x\": 566}, \"right_eye_41\": {\"y\": 593, \"x\": 563}, \"right_eye_40\": {\"y\": 593, \"x\": 559}, \"right_eye_54\": {\"y\": 596, \"x\": 612}, \"right_eye_55\": {\"y\": 596, \"x\": 616}}}, \"face_rectangle\": {\"width\": 629, \"top\": 432, \"height\": 629, \"left\": 126}}}";
Poco::JSON::Parser parser;
const Dynamic::Var &var = parser.parse(pointJsonStr);
int right_eye_pupil_radius;
int right_eye_pupil_center_x;
int right_eye_pupil_center_y;
if(!var.isEmpty()){
const JSON::Object::Ptr &objPtr = var.extract<Poco::JSON::Object::Ptr>();
// const JSON::Array::Ptr &facesArrayPtr = objPtr->getArray("faces");
//1000关键点
const JSON::Object::Ptr &facesArrayPtr = objPtr->getObject("face");
// const SharedPtr<Poco::JSON::Object> &faceItem0 = facesArrayPtr->getObject(0);
JSON::Object::Ptr pointPtr = facesArrayPtr->getObject("landmark");
int x,y;
JSON::Object::Ptr point;
string direct;
direct = "right";
std::vector<string> rightPoints = {direct+"_eye_left_corner",direct+"_eye_upper_left_quarter",direct+"_eye_top",
direct+"_eye_upper_right_quarter",direct+"_eye_right_corner",direct+"_eye_lower_right_quarter",
direct+"_eye_bottom",direct+"_eye_lower_left_quarter",direct+"_eye_pupil"};
direct = "left";
std::vector<string> leftPoints = {direct+"_eye_left_corner",direct+"_eye_upper_left_quarter",direct+"_eye_top",
direct+"_eye_upper_right_quarter",direct+"_eye_right_corner",direct+"_eye_lower_right_quarter",
direct+"_eye_bottom",direct+"_eye_lower_left_quarter",direct+"_eye_pupil"};
// for(int i=0,index=0;i<rightPoints.size();++i){
// point = pointPtr->getObject(rightPoints.at(i));
// x = point->get("x");
// y = point->get("y");
//// putText(temp, to_string(i), cvPoint(x - 10, y - 10),FONT_HERSHEY_SIMPLEX, 0.2, (0, 255, 0), 1);
//// circle(temp, cvPoint(x, y), 1, cv::Scalar(0, 0, 255), -1);
// srcPoints[index++] = x;
// srcPoints[index++] = y;
// }
//1000点
pointPtr = pointPtr->getObject("right_eye");
const JSON::Object::NameList &names = pointPtr->getNames();
cout << names.size() << endl;
direct = "right";
for(int i=0,index=0;i<63;++i){
const JSON::Object::Ptr &ptr = pointPtr->getObject(direct + "_eye_" + to_string(i));
x = ptr->get("x");
y = ptr->get("y");
// putText(temp, to_string(i), cvPoint(x - 10, y - 10),FONT_HERSHEY_SIMPLEX, 0.2, (0, 255, 0), 1);
// circle(temp, cvPoint(x, y), 1, cv::Scalar(0, 0, 255), -1);
srcPoints[index++] = x;
srcPoints[index++] = y;
}
right_eye_pupil_radius = pointPtr->get("right_eye_pupil_radius");
const JSON::Object::Ptr &ptr = pointPtr->getObject("right_eye_pupil_center");
right_eye_pupil_center_x = ptr->get("x");
right_eye_pupil_center_y = ptr->get("y");
// circle(temp, cvPoint(right_eye_pupil_center_x, right_eye_pupil_center_y), right_eye_pupil_radius, cv::Scalar(0, 255, 0), 1);
cout << "right_eye_pupil_radius=" << right_eye_pupil_radius << endl;
}
//Display it all on the screen
// imshow("Dlib特征点", temp);
// waitKey(0);
handle_rgb("/home/gmuser/images/tongshi.png"); //美瞳
cv::Mat meitong = imread(irisPath);
unsigned char* maskData = meitong.data;
int mWidth = meitong.cols, mHeight = meitong.rows, mStride = mWidth * meitong.channels();
unsigned char* srcData = temp.data;
int width = temp.cols, height = temp.rows, stride = width * temp.channels();
f_BeautyIris(srcData,width,height,stride,srcPoints,maskData,mWidth,mHeight,mStride,NULL,100,right_eye_pupil_radius,right_eye_pupil_center_x,right_eye_pupil_center_y);
imshow("美瞳", temp);
// imwrite("/Users/edz/Downloads/右眼美瞳后.jpg",temp);
waitKey(0);
}
catch (serialization_error& e)
{
cout << "You need dlib's default face landmarking model file to run this example." << endl;
cout << "You can get it from the following URL: " << endl;
cout << " http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl;
cout << endl << e.what() << endl;
}
catch (exception& e)
{
cout << e.what() << endl;
}
// Mat face = imread("/Users/edz/Downloads/tongshi.png"); // Mat face = imread("/Users/edz/Downloads/tongshi.png");
// imshow("face",face); // imshow("face",face);
// waitKey(0); // waitKey(0);
cout << "aaa" << endl; // cout << "aaa" << endl;
} }
//int f_BeautyIris(unsigned char* srcData, int width, int height, int stride, int srcPoints[], unsigned char* maskData, int mWidth, int mHeight, int mStride, int maskPoints[], int ratio) //int f_BeautyIris(unsigned char* srcData, int width, int height, int stride, int srcPoints[], unsigned char* maskData, int mWidth, int mHeight, int mStride, int maskPoints[], int ratio)
//{ //{
......
...@@ -14,7 +14,7 @@ int f_FastMeanFilter(unsigned char* srcData, int width, int height ,int stride, ...@@ -14,7 +14,7 @@ int f_FastMeanFilter(unsigned char* srcData, int width, int height ,int stride,
if(radius > MIN2(width,height) / 2) if(radius > MIN2(width,height) / 2)
radius = (MIN2(width, height) / 2-0.5); radius = (MIN2(width, height) / 2-0.5);
unsigned char* dstData = (unsigned char*)malloc(sizeof(unsigned char) * height * stride); unsigned char* dstData = (unsigned char*)malloc(sizeof(unsigned char) * height * stride);
int unit = 4, t = 0, t1 = 0; int unit = 3, t = 0, t1 = 0;
int i,j,k,len = width * height * unit; int i,j,k,len = width * height * unit;
int block = (radius << 1) + 1; int block = (radius << 1) + 1;
int winSize = block * block; int winSize = block * block;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment