Skip to content

Instantly share code, notes, and snippets.

@pranavghate94
Created September 18, 2018 16:30
Show Gist options
  • Select an option

  • Save pranavghate94/c25941ed75ac0c714124be0ba05601d3 to your computer and use it in GitHub Desktop.

Select an option

Save pranavghate94/c25941ed75ac0c714124be0ba05601d3 to your computer and use it in GitHub Desktop.
Openface
// FaceServer::handle_post does all the pre processing before handing the right image format to the Openface function below this one.
void FaceServer::handle_post(http_request message) {
pplx::task<json::value> img_extract = message.extract_json();
packet = new FaceDataPacket();
img_extract.then([=](json::value value) {
base64_string = value.at(U("image")).as_string();
image_bytes = conversions::from_base64(base64_string);
image = imdecode(image_bytes, IMREAD_COLOR);
*packet = image_analyser.GetKeypointData(image);
message.reply(status_codes::OK, "hey");
});
};
// The OpenFace APIs I use
FaceDataPacket ImageAnalyser::GetKeypointData(cv::Mat image) {
cv::Mat_<uchar> greyscale_image;
cv::cvtColor(image, greyscale_image, CV_BGR2GRAY);
bool success = LandmarkDetector::DetectLandmarksInImage(greyscale_image, *face_model, *det_parameters, greyscale_image);
FaceDataPacket* packet = new FaceDataPacket();
cv::Point3f gazeDirection0(0, 0, -1);
cv::Point3f gazeDirection1(0, 0, -1);
cv::Vec2d gazeAngle(0, 0);
vector<pair<string, double>> au_intensity;
vector<pair<string, double>> au_presence;
if (success) {
GazeAnalysis::EstimateGaze(*face_model, gazeDirection0, 200, 200, image.cols, image.rows, true);
GazeAnalysis::EstimateGaze(*face_model, gazeDirection1, 200, 200, image.cols, image.rows, false);
gazeAngle = GazeAnalysis::GetGazeAngle(gazeDirection0, gazeDirection1);
face_analyser->PredictStaticAUsAndComputeFeatures(image, face_model->detected_landmarks);
au_intensity = face_analyser->GetCurrentAUsReg();
au_presence = face_analyser->GetCurrentAUsClass();
//Create the packet
packet->SetGazeData(gazeDirection0, gazeDirection1, gazeAngle);
packet->SetAUData(&au_intensity, &au_presence);
return *packet;
}
return *packet;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment