Commit fe06bd86 authored by 宋柯's avatar 宋柯

美瞳v1

parent 3c4d801f
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include"Commen.h"
#include"f_BeautyIris.h"
#include"TRGB2YUV.h"
#include"f_MeanFilter.h"
#include"iostream"
#include <opencv2/opencv.hpp>
#include <dlib/opencv.h>
......@@ -12,32 +9,14 @@
#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"
......@@ -325,7 +304,7 @@ std::string base64_encode(const char * bytes_to_encode, unsigned int in_len)
}
int main(int argc, char* argv[]){
int main32(int argc, char* argv[]){
Poco::Stopwatch stopwatch;
stopwatch.start();
string photoPath = string(argv[1]);
......@@ -539,6 +518,246 @@ int main(int argc, char* argv[]){
}
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;
}else{
// std::string stRes;
// StreamCopier::copyToString(istream, stRes);
//
// std::cout<< stRes <<std::endl;
//
// std::cout<< status <<std::endl;
}
}
int main(int argc, char* argv[]){
Poco::Stopwatch stopwatch;
stopwatch.start();
string photoPath = string(argv[1]);
string irisPath = string(argv[2]);
// string outputPath = string(argv[3]);
string direct = string(argv[3]);
// 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,left_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(photoPath));
// 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){
if(true){
// std::string stRes;
// StreamCopier::copyToString(istream, stRes);
// std::cout<< stRes <<std::endl;
try
{
// Grab and process frames until the main window is closed by the user.
cv::Mat temp = imread(photoPath);
// string pointJsonStr = stRes;
string pointJsonStr = "{\"time_used\": 165, \"request_id\": \"1618799646,e6ab8da4-a148-428a-9fbb-5c9dfc0ae4a8\", \"face\": {\"landmark\": {\"right_eye\": {\"right_eye_pupil_center\": {\"y\": 396, \"x\": 493}, \"right_eye_38\": {\"y\": 408, \"x\": 479}, \"right_eye_39\": {\"y\": 408, \"x\": 481}, \"right_eye_36\": {\"y\": 408, \"x\": 476}, \"right_eye_37\": {\"y\": 408, \"x\": 478}, \"right_eye_34\": {\"y\": 407, \"x\": 473}, \"right_eye_35\": {\"y\": 407, \"x\": 474}, \"right_eye_32\": {\"y\": 405, \"x\": 470}, \"right_eye_33\": {\"y\": 406, \"x\": 471}, \"right_eye_30\": {\"y\": 401, \"x\": 470}, \"right_eye_31\": {\"y\": 403, \"x\": 470}, \"right_eye_10\": {\"y\": 387, \"x\": 503}, \"right_eye_11\": {\"y\": 387, \"x\": 501}, \"right_eye_12\": {\"y\": 387, \"x\": 499}, \"right_eye_13\": {\"y\": 387, \"x\": 497}, \"right_eye_14\": {\"y\": 387, \"x\": 495}, \"right_eye_15\": {\"y\": 387, \"x\": 493}, \"right_eye_16\": {\"y\": 387, \"x\": 491}, \"right_eye_17\": {\"y\": 387, \"x\": 489}, \"right_eye_18\": {\"y\": 388, \"x\": 488}, \"right_eye_19\": {\"y\": 388, \"x\": 486}, \"right_eye_56\": {\"y\": 405, \"x\": 509}, \"right_eye_57\": {\"y\": 405, \"x\": 511}, \"right_eye_50\": {\"y\": 409, \"x\": 500}, \"right_eye_51\": {\"y\": 408, \"x\": 501}, \"right_eye_52\": {\"y\": 408, \"x\": 503}, \"right_eye_53\": {\"y\": 407, \"x\": 505}, \"right_eye_pupil_radius\": 13, \"right_eye_8\": {\"y\": 388, \"x\": 506}, \"right_eye_9\": {\"y\": 388, \"x\": 504}, \"right_eye_6\": {\"y\": 389, \"x\": 510}, \"right_eye_7\": {\"y\": 389, \"x\": 508}, \"right_eye_4\": {\"y\": 391, \"x\": 513}, \"right_eye_5\": {\"y\": 390, \"x\": 512}, \"right_eye_2\": {\"y\": 394, \"x\": 516}, \"right_eye_3\": {\"y\": 392, \"x\": 515}, \"right_eye_0\": {\"y\": 397, \"x\": 517}, \"right_eye_1\": {\"y\": 395, \"x\": 517}, \"right_eye_58\": {\"y\": 404, \"x\": 512}, \"right_eye_29\": {\"y\": 399, \"x\": 471}, \"right_eye_28\": {\"y\": 398, \"x\": 472}, \"right_eye_62\": {\"y\": 399, \"x\": 517}, \"right_eye_21\": {\"y\": 390, \"x\": 482}, \"right_eye_20\": {\"y\": 389, \"x\": 484}, \"right_eye_23\": {\"y\": 391, \"x\": 479}, \"right_eye_22\": {\"y\": 390, \"x\": 480}, \"right_eye_25\": {\"y\": 394, \"x\": 476}, \"right_eye_24\": {\"y\": 393, \"x\": 477}, \"right_eye_27\": {\"y\": 396, \"x\": 473}, \"right_eye_26\": {\"y\": 395, \"x\": 474}, \"right_eye_59\": {\"y\": 403, \"x\": 514}, \"right_eye_61\": {\"y\": 400, \"x\": 516}, \"right_eye_60\": {\"y\": 401, \"x\": 515}, \"right_eye_49\": {\"y\": 409, \"x\": 498}, \"right_eye_48\": {\"y\": 409, \"x\": 496}, \"right_eye_47\": {\"y\": 409, \"x\": 495}, \"right_eye_46\": {\"y\": 409, \"x\": 493}, \"right_eye_45\": {\"y\": 409, \"x\": 491}, \"right_eye_44\": {\"y\": 409, \"x\": 489}, \"right_eye_43\": {\"y\": 409, \"x\": 488}, \"right_eye_42\": {\"y\": 409, \"x\": 486}, \"right_eye_41\": {\"y\": 409, \"x\": 484}, \"right_eye_40\": {\"y\": 409, \"x\": 483}, \"right_eye_54\": {\"y\": 407, \"x\": 506}, \"right_eye_55\": {\"y\": 406, \"x\": 508}}, \"left_eye\": {\"left_eye_43\": {\"y\": 409, \"x\": 369}, \"left_eye_42\": {\"y\": 409, \"x\": 370}, \"left_eye_41\": {\"y\": 408, \"x\": 372}, \"left_eye_40\": {\"y\": 408, \"x\": 374}, \"left_eye_47\": {\"y\": 409, \"x\": 362}, \"left_eye_46\": {\"y\": 409, \"x\": 363}, \"left_eye_45\": {\"y\": 409, \"x\": 365}, \"left_eye_32\": {\"y\": 404, \"x\": 386}, \"left_eye_49\": {\"y\": 409, \"x\": 358}, \"left_eye_48\": {\"y\": 409, \"x\": 360}, \"left_eye_pupil_radius\": 13, \"left_eye_61\": {\"y\": 400, \"x\": 340}, \"left_eye_38\": {\"y\": 408, \"x\": 377}, \"left_eye_33\": {\"y\": 406, \"x\": 385}, \"left_eye_60\": {\"y\": 401, \"x\": 341}, \"left_eye_44\": {\"y\": 409, \"x\": 367}, \"left_eye_36\": {\"y\": 407, \"x\": 381}, \"left_eye_37\": {\"y\": 408, \"x\": 379}, \"left_eye_34\": {\"y\": 407, \"x\": 384}, \"left_eye_35\": {\"y\": 407, \"x\": 382}, \"left_eye_18\": {\"y\": 387, \"x\": 368}, \"left_eye_19\": {\"y\": 388, \"x\": 370}, \"left_eye_30\": {\"y\": 401, \"x\": 386}, \"left_eye_31\": {\"y\": 402, \"x\": 387}, \"left_eye_14\": {\"y\": 386, \"x\": 361}, \"left_eye_15\": {\"y\": 386, \"x\": 363}, \"left_eye_16\": {\"y\": 386, \"x\": 365}, \"left_eye_17\": {\"y\": 387, \"x\": 367}, \"left_eye_10\": {\"y\": 387, \"x\": 353}, \"left_eye_11\": {\"y\": 386, \"x\": 355}, \"left_eye_12\": {\"y\": 386, \"x\": 357}, \"left_eye_13\": {\"y\": 386, \"x\": 359}, \"left_eye_50\": {\"y\": 408, \"x\": 356}, \"left_eye_51\": {\"y\": 408, \"x\": 355}, \"left_eye_52\": {\"y\": 408, \"x\": 353}, \"left_eye_53\": {\"y\": 407, \"x\": 351}, \"left_eye_54\": {\"y\": 407, \"x\": 350}, \"left_eye_55\": {\"y\": 406, \"x\": 348}, \"left_eye_56\": {\"y\": 405, \"x\": 346}, \"left_eye_57\": {\"y\": 404, \"x\": 345}, \"left_eye_58\": {\"y\": 404, \"x\": 343}, \"left_eye_59\": {\"y\": 403, \"x\": 342}, \"left_eye_62\": {\"y\": 399, \"x\": 339}, \"left_eye_pupil_center\": {\"y\": 395, \"x\": 363}, \"left_eye_6\": {\"y\": 389, \"x\": 346}, \"left_eye_7\": {\"y\": 388, \"x\": 348}, \"left_eye_4\": {\"y\": 391, \"x\": 342}, \"left_eye_5\": {\"y\": 390, \"x\": 344}, \"left_eye_2\": {\"y\": 394, \"x\": 340}, \"left_eye_3\": {\"y\": 392, \"x\": 341}, \"left_eye_0\": {\"y\": 397, \"x\": 338}, \"left_eye_1\": {\"y\": 395, \"x\": 339}, \"left_eye_8\": {\"y\": 387, \"x\": 349}, \"left_eye_9\": {\"y\": 387, \"x\": 351}, \"left_eye_21\": {\"y\": 389, \"x\": 374}, \"left_eye_20\": {\"y\": 388, \"x\": 372}, \"left_eye_23\": {\"y\": 391, \"x\": 377}, \"left_eye_22\": {\"y\": 390, \"x\": 376}, \"left_eye_25\": {\"y\": 393, \"x\": 380}, \"left_eye_24\": {\"y\": 392, \"x\": 379}, \"left_eye_27\": {\"y\": 396, \"x\": 383}, \"left_eye_26\": {\"y\": 395, \"x\": 382}, \"left_eye_29\": {\"y\": 399, \"x\": 385}, \"left_eye_28\": {\"y\": 397, \"x\": 384}, \"left_eye_39\": {\"y\": 408, \"x\": 375}}}, \"face_rectangle\": {\"width\": 301, \"top\": 342, \"height\": 300, \"left\": 280}}}";
// string pointJsonStr = "{\"time_used\": 96, \"request_id\": \"1618313017,7a5949a9-187d-403b-a7a6-711728ac6335\", \"face\": {\"landmark\": {\"left_eye\": {\"left_eye_43\": {\"y\": 409, \"x\": 369}, \"left_eye_42\": {\"y\": 409, \"x\": 370}, \"left_eye_41\": {\"y\": 408, \"x\": 372}, \"left_eye_40\": {\"y\": 408, \"x\": 374}, \"left_eye_47\": {\"y\": 409, \"x\": 362}, \"left_eye_46\": {\"y\": 409, \"x\": 363}, \"left_eye_45\": {\"y\": 409, \"x\": 365}, \"left_eye_32\": {\"y\": 404, \"x\": 386}, \"left_eye_49\": {\"y\": 409, \"x\": 358}, \"left_eye_48\": {\"y\": 409, \"x\": 360}, \"left_eye_pupil_radius\": 13, \"left_eye_61\": {\"y\": 400, \"x\": 340}, \"left_eye_38\": {\"y\": 408, \"x\": 377}, \"left_eye_33\": {\"y\": 406, \"x\": 385}, \"left_eye_60\": {\"y\": 401, \"x\": 341}, \"left_eye_44\": {\"y\": 409, \"x\": 367}, \"left_eye_36\": {\"y\": 407, \"x\": 381}, \"left_eye_37\": {\"y\": 408, \"x\": 379}, \"left_eye_34\": {\"y\": 407, \"x\": 384}, \"left_eye_35\": {\"y\": 407, \"x\": 382}, \"left_eye_18\": {\"y\": 387, \"x\": 368}, \"left_eye_19\": {\"y\": 388, \"x\": 370}, \"left_eye_30\": {\"y\": 401, \"x\": 386}, \"left_eye_31\": {\"y\": 402, \"x\": 387}, \"left_eye_14\": {\"y\": 386, \"x\": 361}, \"left_eye_15\": {\"y\": 386, \"x\": 363}, \"left_eye_16\": {\"y\": 386, \"x\": 365}, \"left_eye_17\": {\"y\": 387, \"x\": 367}, \"left_eye_10\": {\"y\": 387, \"x\": 353}, \"left_eye_11\": {\"y\": 386, \"x\": 355}, \"left_eye_12\": {\"y\": 386, \"x\": 357}, \"left_eye_13\": {\"y\": 386, \"x\": 359}, \"left_eye_50\": {\"y\": 408, \"x\": 356}, \"left_eye_51\": {\"y\": 408, \"x\": 355}, \"left_eye_52\": {\"y\": 408, \"x\": 353}, \"left_eye_53\": {\"y\": 407, \"x\": 351}, \"left_eye_54\": {\"y\": 407, \"x\": 350}, \"left_eye_55\": {\"y\": 406, \"x\": 348}, \"left_eye_56\": {\"y\": 405, \"x\": 346}, \"left_eye_57\": {\"y\": 404, \"x\": 345}, \"left_eye_58\": {\"y\": 404, \"x\": 343}, \"left_eye_59\": {\"y\": 403, \"x\": 342}, \"left_eye_62\": {\"y\": 399, \"x\": 339}, \"left_eye_pupil_center\": {\"y\": 395, \"x\": 363}, \"left_eye_6\": {\"y\": 389, \"x\": 346}, \"left_eye_7\": {\"y\": 388, \"x\": 348}, \"left_eye_4\": {\"y\": 391, \"x\": 342}, \"left_eye_5\": {\"y\": 390, \"x\": 344}, \"left_eye_2\": {\"y\": 394, \"x\": 340}, \"left_eye_3\": {\"y\": 392, \"x\": 341}, \"left_eye_0\": {\"y\": 397, \"x\": 338}, \"left_eye_1\": {\"y\": 395, \"x\": 339}, \"left_eye_8\": {\"y\": 387, \"x\": 349}, \"left_eye_9\": {\"y\": 387, \"x\": 351}, \"left_eye_21\": {\"y\": 389, \"x\": 374}, \"left_eye_20\": {\"y\": 388, \"x\": 372}, \"left_eye_23\": {\"y\": 391, \"x\": 377}, \"left_eye_22\": {\"y\": 390, \"x\": 376}, \"left_eye_25\": {\"y\": 393, \"x\": 380}, \"left_eye_24\": {\"y\": 392, \"x\": 379}, \"left_eye_27\": {\"y\": 396, \"x\": 383}, \"left_eye_26\": {\"y\": 395, \"x\": 382}, \"left_eye_29\": {\"y\": 399, \"x\": 385}, \"left_eye_28\": {\"y\": 397, \"x\": 384}, \"left_eye_39\": {\"y\": 408, \"x\": 375}}, \"right_eye\": {\"right_eye_pupil_center\": {\"y\": 396, \"x\": 493}, \"right_eye_38\": {\"y\": 408, \"x\": 479}, \"right_eye_39\": {\"y\": 408, \"x\": 481}, \"right_eye_36\": {\"y\": 408, \"x\": 476}, \"right_eye_37\": {\"y\": 408, \"x\": 478}, \"right_eye_34\": {\"y\": 407, \"x\": 473}, \"right_eye_35\": {\"y\": 407, \"x\": 474}, \"right_eye_32\": {\"y\": 405, \"x\": 470}, \"right_eye_33\": {\"y\": 406, \"x\": 471}, \"right_eye_30\": {\"y\": 401, \"x\": 470}, \"right_eye_31\": {\"y\": 403, \"x\": 470}, \"right_eye_10\": {\"y\": 387, \"x\": 503}, \"right_eye_11\": {\"y\": 387, \"x\": 501}, \"right_eye_12\": {\"y\": 387, \"x\": 499}, \"right_eye_13\": {\"y\": 387, \"x\": 497}, \"right_eye_14\": {\"y\": 387, \"x\": 495}, \"right_eye_15\": {\"y\": 387, \"x\": 493}, \"right_eye_16\": {\"y\": 387, \"x\": 491}, \"right_eye_17\": {\"y\": 387, \"x\": 489}, \"right_eye_18\": {\"y\": 388, \"x\": 488}, \"right_eye_19\": {\"y\": 388, \"x\": 486}, \"right_eye_56\": {\"y\": 405, \"x\": 509}, \"right_eye_57\": {\"y\": 405, \"x\": 511}, \"right_eye_50\": {\"y\": 409, \"x\": 500}, \"right_eye_51\": {\"y\": 408, \"x\": 501}, \"right_eye_52\": {\"y\": 408, \"x\": 503}, \"right_eye_53\": {\"y\": 407, \"x\": 505}, \"right_eye_pupil_radius\": 13, \"right_eye_8\": {\"y\": 388, \"x\": 506}, \"right_eye_9\": {\"y\": 388, \"x\": 504}, \"right_eye_6\": {\"y\": 389, \"x\": 510}, \"right_eye_7\": {\"y\": 389, \"x\": 508}, \"right_eye_4\": {\"y\": 391, \"x\": 513}, \"right_eye_5\": {\"y\": 390, \"x\": 512}, \"right_eye_2\": {\"y\": 394, \"x\": 516}, \"right_eye_3\": {\"y\": 392, \"x\": 515}, \"right_eye_0\": {\"y\": 397, \"x\": 517}, \"right_eye_1\": {\"y\": 395, \"x\": 517}, \"right_eye_58\": {\"y\": 404, \"x\": 512}, \"right_eye_29\": {\"y\": 399, \"x\": 471}, \"right_eye_28\": {\"y\": 398, \"x\": 472}, \"right_eye_62\": {\"y\": 399, \"x\": 517}, \"right_eye_21\": {\"y\": 390, \"x\": 482}, \"right_eye_20\": {\"y\": 389, \"x\": 484}, \"right_eye_23\": {\"y\": 391, \"x\": 479}, \"right_eye_22\": {\"y\": 390, \"x\": 480}, \"right_eye_25\": {\"y\": 394, \"x\": 476}, \"right_eye_24\": {\"y\": 393, \"x\": 477}, \"right_eye_27\": {\"y\": 396, \"x\": 473}, \"right_eye_26\": {\"y\": 395, \"x\": 474}, \"right_eye_59\": {\"y\": 403, \"x\": 514}, \"right_eye_61\": {\"y\": 400, \"x\": 516}, \"right_eye_60\": {\"y\": 401, \"x\": 515}, \"right_eye_49\": {\"y\": 409, \"x\": 498}, \"right_eye_48\": {\"y\": 409, \"x\": 496}, \"right_eye_47\": {\"y\": 409, \"x\": 495}, \"right_eye_46\": {\"y\": 409, \"x\": 493}, \"right_eye_45\": {\"y\": 409, \"x\": 491}, \"right_eye_44\": {\"y\": 409, \"x\": 489}, \"right_eye_43\": {\"y\": 409, \"x\": 488}, \"right_eye_42\": {\"y\": 409, \"x\": 486}, \"right_eye_41\": {\"y\": 409, \"x\": 484}, \"right_eye_40\": {\"y\": 409, \"x\": 483}, \"right_eye_54\": {\"y\": 407, \"x\": 506}, \"right_eye_55\": {\"y\": 406, \"x\": 508}}}, \"face_rectangle\": {\"width\": 301, \"top\": 342, \"height\": 300, \"left\": 280}}}";
// string pointJsonStr = "{\"time_used\": 140, \"request_id\": \"1618310140,edce0a1f-74a4-4409-a895-f2944206b945\", \"face\": {\"landmark\": {\"left_eye\": {\"left_eye_43\": {\"y\": 150, \"x\": 258}, \"left_eye_42\": {\"y\": 150, \"x\": 261}, \"left_eye_41\": {\"y\": 150, \"x\": 264}, \"left_eye_40\": {\"y\": 150, \"x\": 267}, \"left_eye_47\": {\"y\": 150, \"x\": 247}, \"left_eye_46\": {\"y\": 150, \"x\": 250}, \"left_eye_45\": {\"y\": 150, \"x\": 253}, \"left_eye_32\": {\"y\": 146, \"x\": 288}, \"left_eye_49\": {\"y\": 149, \"x\": 241}, \"left_eye_48\": {\"y\": 149, \"x\": 244}, \"left_eye_pupil_radius\": 21, \"left_eye_61\": {\"y\": 133, \"x\": 212}, \"left_eye_38\": {\"y\": 150, \"x\": 272}, \"left_eye_33\": {\"y\": 148, \"x\": 286}, \"left_eye_60\": {\"y\": 135, \"x\": 214}, \"left_eye_44\": {\"y\": 150, \"x\": 255}, \"left_eye_36\": {\"y\": 150, \"x\": 278}, \"left_eye_37\": {\"y\": 150, \"x\": 275}, \"left_eye_34\": {\"y\": 149, \"x\": 284}, \"left_eye_35\": {\"y\": 149, \"x\": 281}, \"left_eye_18\": {\"y\": 117, \"x\": 260}, \"left_eye_19\": {\"y\": 118, \"x\": 263}, \"left_eye_30\": {\"y\": 140, \"x\": 288}, \"left_eye_31\": {\"y\": 143, \"x\": 288}, \"left_eye_14\": {\"y\": 114, \"x\": 248}, \"left_eye_15\": {\"y\": 115, \"x\": 251}, \"left_eye_16\": {\"y\": 115, \"x\": 254}, \"left_eye_17\": {\"y\": 116, \"x\": 257}, \"left_eye_10\": {\"y\": 113, \"x\": 236}, \"left_eye_11\": {\"y\": 113, \"x\": 239}, \"left_eye_12\": {\"y\": 113, \"x\": 242}, \"left_eye_13\": {\"y\": 114, \"x\": 245}, \"left_eye_50\": {\"y\": 148, \"x\": 239}, \"left_eye_51\": {\"y\": 147, \"x\": 236}, \"left_eye_52\": {\"y\": 146, \"x\": 233}, \"left_eye_53\": {\"y\": 145, \"x\": 230}, \"left_eye_54\": {\"y\": 144, \"x\": 228}, \"left_eye_55\": {\"y\": 143, \"x\": 225}, \"left_eye_56\": {\"y\": 142, \"x\": 223}, \"left_eye_57\": {\"y\": 140, \"x\": 220}, \"left_eye_58\": {\"y\": 139, \"x\": 218}, \"left_eye_59\": {\"y\": 137, \"x\": 216}, \"left_eye_62\": {\"y\": 130, \"x\": 211}, \"left_eye_pupil_center\": {\"y\": 127, \"x\": 255}, \"left_eye_6\": {\"y\": 116, \"x\": 224}, \"left_eye_7\": {\"y\": 115, \"x\": 227}, \"left_eye_4\": {\"y\": 118, \"x\": 218}, \"left_eye_5\": {\"y\": 117, \"x\": 221}, \"left_eye_2\": {\"y\": 122, \"x\": 214}, \"left_eye_3\": {\"y\": 120, \"x\": 216}, \"left_eye_0\": {\"y\": 128, \"x\": 211}, \"left_eye_1\": {\"y\": 125, \"x\": 212}, \"left_eye_8\": {\"y\": 114, \"x\": 230}, \"left_eye_9\": {\"y\": 114, \"x\": 233}, \"left_eye_21\": {\"y\": 121, \"x\": 269}, \"left_eye_20\": {\"y\": 119, \"x\": 266}, \"left_eye_23\": {\"y\": 124, \"x\": 274}, \"left_eye_22\": {\"y\": 122, \"x\": 271}, \"left_eye_25\": {\"y\": 128, \"x\": 279}, \"left_eye_24\": {\"y\": 126, \"x\": 276}, \"left_eye_27\": {\"y\": 132, \"x\": 283}, \"left_eye_26\": {\"y\": 130, \"x\": 281}, \"left_eye_29\": {\"y\": 137, \"x\": 287}, \"left_eye_28\": {\"y\": 134, \"x\": 285}, \"left_eye_39\": {\"y\": 150, \"x\": 270}}, \"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 eye_pupil_radius;
int eye_pupil_center_x;
int eye_pupil_center_y;
if(!var.isEmpty()){
const JSON::Object::Ptr &objPtr = var.extract<Poco::JSON::Object::Ptr>();
//1000关键点
const JSON::Object::Ptr &facesArrayPtr = objPtr->getObject("face");
JSON::Object::Ptr pointPtr = facesArrayPtr->getObject("landmark");
int x,y;
JSON::Object::Ptr point;
if(direct=="left")
{
int srcPoints[63*2];
string direct = "left";
//1000点
pointPtr = pointPtr->getObject(direct+"_eye");
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;
}
eye_pupil_radius = pointPtr->get(direct+"_eye_pupil_radius");
const JSON::Object::Ptr &ptr = pointPtr->getObject(direct+"_eye_pupil_center");
eye_pupil_center_x = ptr->get("x");
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 << direct+"_eye_pupil_radius=" << eye_pupil_radius << endl;
//美瞳
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,eye_pupil_radius,eye_pupil_center_x,eye_pupil_center_y);
imshow("美瞳", temp);
// imwrite("/Users/edz/Downloads/右眼美瞳后.jpg",temp);
waitKey(0);
}
else if(direct=="right")
{
int srcPoints[63*2];
string direct = "right";
//1000点
direct = "right";
pointPtr = pointPtr->getObject(direct+"_eye");
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;
}
eye_pupil_radius = pointPtr->get(direct+"_eye_pupil_radius");
const JSON::Object::Ptr &ptr = pointPtr->getObject(direct+"_eye_pupil_center");
eye_pupil_center_x = ptr->get("x");
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 << direct+"_eye_pupil_radius=" << eye_pupil_radius << endl;
//美瞳
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,eye_pupil_radius,eye_pupil_center_x,eye_pupil_center_y);
imshow("美瞳", temp);
// imwrite("/Users/edz/Downloads/右眼美瞳后.jpg",temp);
waitKey(0);
}
else
{
int srcPoints[63*2];
string direct;
//1000点
direct = "right";
pointPtr = pointPtr->getObject(direct+"_eye");
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;
}
eye_pupil_radius = pointPtr->get(direct+"_eye_pupil_radius");
JSON::Object::Ptr ptr = pointPtr->getObject(direct+"_eye_pupil_center");
eye_pupil_center_x = ptr->get("x");
eye_pupil_center_y = ptr->get("y");
// circle(temp, cvPoint(eye_pupil_center_x, eye_pupil_center_y), eye_pupil_radius, cv::Scalar(0, 255, 0), 1);
cout << direct+"_eye_pupil_radius=" << eye_pupil_radius << endl;
//美瞳
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,eye_pupil_radius,eye_pupil_center_x,eye_pupil_center_y);
int srcPoints2[63*2];
direct = "left";
pointPtr = facesArrayPtr->getObject("landmark");
pointPtr = pointPtr->getObject(direct+"_eye");
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);
srcPoints2[index++] = x;
srcPoints2[index++] = y;
}
eye_pupil_radius = pointPtr->get(direct+"_eye_pupil_radius");
ptr = pointPtr->getObject(direct+"_eye_pupil_center");
eye_pupil_center_x = ptr->get("x");
eye_pupil_center_y = ptr->get("y");
// circle(temp, cvPoint(eye_pupil_center_x, eye_pupil_center_y), eye_pupil_radius, cv::Scalar(0, 255, 0), 1);
cout << direct+"_eye_pupil_radius=" << eye_pupil_radius << endl;
//美瞳
meitong = imread(irisPath);
maskData = meitong.data;
mWidth = meitong.cols, mHeight = meitong.rows, mStride = mWidth * meitong.channels();
srcData = temp.data;
width = temp.cols, height = temp.rows, stride = width * temp.channels();
f_BeautyIris(srcData,width,height,stride,srcPoints2,maskData,mWidth,mHeight,mStride,NULL,100,eye_pupil_radius,eye_pupil_center_x,eye_pupil_center_y);
}
imshow("美瞳", temp);
// imwrite(outputPath,temp);
// waitKey(0);
// cout << "outputPath =" << outputPath << endl;
cout << "time cost =" << (int)(stopwatch.elapsed()/1000) << endl;
}
//Display it all on the screen
// imshow("Dlib特征点", temp);
// waitKey(0);
}
catch (serialization_error& e)
{
......
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