Home How do you make a face symmetric using openCV and C++?
 I was looking at this tutorial, and it said "You can make a symmetric face, by averaging a face and its mirror reflection." - and there was an example of Obama's face being made symmetrical. I tried doing the same with openCV and C++, but these are the results I'm getting using the following code: Mat3b getMean(const vector& images) { Mat m(images[0].rows, images[0].cols, CV_64FC3); // Create a 0 initialized image to use as accumulator m.setTo(Scalar(0, 0, 0, 0)); //set all image elements to 0 Mat temp; // Use a temp image to hold the conversion of each input image to CV_64FC3 for (int i = 0; i < images.size(); ++i) { //loop through the images images[i].convertTo(temp, CV_64FC3); // Convert the input images to CV_64FC3... m += temp; //...so you can accumulate } m.convertTo(m, CV_8U, 1. / images.size()); // Convert back to CV_8UC3 type, applying the division to get the actual mean return m; } int main() { Mat img1 = imread("E:/barack-obama.jpg"), img2, img4; resize(img1, img1, Size(0.4 * img1.cols, 0.4 * img1.rows), 1, 1, INTER_LINEAR); flip(img1, img2, +1); vector imgs; imgs.push_back(img1); imgs.push_back(img2); Mat3b img3 = getMean(imgs); // Compute the mean //img3 = (img1 + img2)*0.5; double alpha = 0.5, beta; beta = (1.0 - alpha); addWeighted(img1, alpha, img2, beta, 0.0, img4); imshow("Original", img1); imshow("getMean", img3); imshow("AddWeighted", img4); waitKey(0); }