void CSmiley::DrawEyes(CWindowGc &aGc) const { // Draw the eyes TPoint leftEye(iSmileyWidth / 3, iSmileyHeight / 3); TPoint rightEye(iSmileyWidth * 2 / 3, iSmileyHeight / 3); aGc.SetPenSize(TSize(5, 5)); aGc.Plot(iSmileyRect.iTl + leftEye); aGc.Plot(iSmileyRect.iTl + rightEye); }
//multi bool FaceAlignment::alignStasm4(cv::Mat& inputImg, std::vector<cv::Mat>& alignedImg, std::vector<std::vector<cv::Point2d> >& landmarkPoints, std::vector<cv::Point2d>& centersOfLandmarks) { //cv::Mat im_gray; //cv::cvtColor(inputImg,im_gray,CV_RGB2GRAY); //commonTool.log("Performing Active Shape Models with Stasm 4.0 to find features in face."); //cv::namedWindow( "test", CV_WINDOW_NORMAL ); //cv::imshow( "test", inputImg ); std::vector<std::vector<cv::Point2d> > landmarkList; bool success = detectLandmarks(inputImg, landmarkList, centersOfLandmarks); if (!success) { return false; } int numberOfFaces = landmarkList.size(); //commonTool.log(QString("Found number of faces in a single frame --> %1").arg(numberOfFaces)); for (int i=0;i<numberOfFaces;i++) { std::vector<cv::Point2d> points = landmarkList.at(i); //commonTool.log(QString("Extracted %1 landmarks.").arg(points.size())); //DEBUG //commonTool.showImageAndLandMarks(QString("Before Alignment"), inputImg, points, CV_RGB(255, 0, 0), *mutex); //DEBUG cv::Mat resizedImg; cv::Mat rotatedImg = cv::Mat( 250, 200, inputImg.type() ); double ratio = 50/sqrt(pow(points.at(LEFT_EYE_INDEXV4).x - points.at(RIGHT_EYE_INDEXV4).x, 2) + pow(points.at(LEFT_EYE_INDEXV4).y - points.at(RIGHT_EYE_INDEXV4).y, 2)); cv::resize(inputImg, resizedImg, cv::Size(), ratio, ratio, CV_INTER_LINEAR ); //resize all the point for (int i = 0; i < (int)points.size(); i++){ points.at(i) = points.at(i) * ratio; } //DEBUG //commonTool.showImageAndLandMarks(QString("Scaling: %1").arg(ratio), inputImg, points); //DEBUG /* for rotation */ double degree = (atan((points.at(LEFT_EYE_INDEXV4).y - points.at(RIGHT_EYE_INDEXV4).y)/(points.at(LEFT_EYE_INDEXV4).x - points.at(RIGHT_EYE_INDEXV4).x)) * 180)/PI; cv::Mat rotationMat = cv::getRotationMatrix2D(points.at(NOSE_INDEXV4), degree, 1.0); warpAffine( resizedImg, rotatedImg, rotationMat, cv::Size(resizedImg.cols, resizedImg.rows) , cv::INTER_LINEAR, cv::BORDER_REPLICATE); //rotation all the point for (int i = 0; i < (int)points.size(); i++){ points.at(i) = rotatePoint(points.at(i), rotationMat); } //DEBUG //commonTool.showImageAndLandMarks(QString("after rotation"), inputImg, points); //DEBUG //make sure the small image will not outside cv::copyMakeBorder(rotatedImg, rotatedImg, IMAGE_ROW, IMAGE_ROW, IMAGE_COL, IMAGE_COL, cv::BORDER_REPLICATE); for (int i = 0; i < (int)points.size(); i++){ points.at(i).x = points.at(i).x + IMAGE_COL; points.at(i).y = points.at(i).y + IMAGE_ROW; } // Mo did this: bad way, not checking all points! // cv::circle(rotatedImg, points.at(LEFT_EYE_INDEX), 5, cv::Scalar(255, 0, 0)); // cv::circle(rotatedImg, points.at(RIGHT_EYE_INDEX), 5, cv::Scalar(0, 0, 255)); // cv::circle(rotatedImg, points.at(NOSE_INDEX), 5, cv::Scalar(0, 255, 0)); // // cv::imshow("rotatedImg", rotatedImg); // cv::waitKey(0); // //DEBUG //commonTool.showImageAndLandMarks(QString("after copymakeborder"), rotatedImg, points); //DEBUG cv::Rect ROI = cv::Rect(points.at(LEFT_EYE_INDEXV4).x - 75.0, points.at(LEFT_EYE_INDEXV4).y - 125.0, IMAGE_COL, IMAGE_ROW); //There was a bug here previously cv::Point2d leftEye(points.at(LEFT_EYE_INDEXV4)); for (int i = 0; i < (int)points.size(); i++){ points.at(i).x = points.at(i).x - (leftEye.x - 75.0); points.at(i).y = points.at(i).y - (leftEye.y - 125.0); } alignedImg.push_back(rotatedImg(ROI)); landmarkPoints.push_back(points); //DEBUG //commonTool.showImageAndLandMarks(QString("After Alignment"), alignedImg, points); //DEBUG } return true; }