// ------------------------------ void Moustachizer::process(Mat frame) { //circle(frame, Point(300,300), 300, Scalar(255,0,0), 3); Mat grayFrame = frame.clone(); cvtColor(frame, grayFrame, CV_RGB2GRAY); equalizeHist(grayFrame, grayFrame); imshow("grayFrame", grayFrame); faceTracker.search( grayFrame ); for(int i=0; i<faceTracker.faces.size(); i++) { Face face = faceTracker.faces[i]; face.draw( frame ); float scale = (float)face.boundingBox.width / stache.size().width; Mat stache_resized; Mat mask_resized; resize(stache, stache_resized, Size(), scale, scale); resize(mask, mask_resized, Size(), scale, scale); float xpos = face.boundingBox.x; float ypos = face.boundingBox.y + (face.boundingBox.height * .60); Rect pos = Rect(xpos, ypos, stache_resized.size().width, stache_resized.size().height); /* Rect frame = Rect(0, 0, input.size().width, input.size().height); Rect intersection = pos & frame; Mat fg = stache_resized(Rect(0,0,intersection.width,intersection.height)); Mat bg = input(Rect(xpos,ypos,intersection.width,intersection.height)); */ Mat bg = frame(pos); stache_resized.copyTo(bg, mask_resized); } //cvtColor(input, input, CV_GRAY2RGB); imshow("preview", frame); cvWaitKey(1); }