Obtain the feature points in the facial image : # Extract facial feature points in the image, Convert the image into a matrix array, Each element in the matrix corresponds to one in each row x,y coordinate def acquire_landmarks (image ) : # First of all, from the dlib Get a human face detector from the libraryĭetector = dlib. Combine the face masks of the two images Īmong 1、2 For the face image detection part ,3、4、5、6、7、8 For the face image conversion partġ.Fixed the discontinuity of the edge of the face coverage area due to the different skin color and light of the image.The face image is mapped into the head image by affine transformation. ![]() The face image mask is mapped into the head image by affine transformation, Get a new face image mask that matches the coordinates of the head image.Obtain the affine transformation matrix.Obtain the feature points in the facial image :.Press down “Exit” Key to exit the software.Press down “clear” Key will clear all pictures.Press down “Save result as” You can save the picture after changing your face.Then press “Swap” Key to change face, The image after the face change will be in “Result” Show. ![]() Press first “Choose face picture” and “Choose head picture” Key to select face image and head image.OpenCV、dlib、PyQt5、numpy、PIL Such as the library Software usage steps Project address : Software instructions Software runtime dependency Library Known one A The face image of, Enter a new B The face image of, Press the change face button, take A The image is automatically changed to B Face. The name of the software is Picture Faceswap, It means that the picture changes face, Is a picture face changing software. ![]() Other libraries may outperform the OpenCVs rendering system.Intelligent face changing software Basic information introduction Software name PutText(image, "OpenCV", roi, color, fontFace, fontScale, thickness) Īs a result of the PutText() function you can render any text over an arbitrary ROI of the image, such as:Īnd keep in mind that text rendering (with or without this trick) in OpenCV is very expensive and can affect to the runtime of your applications. Int fontFace = cv::FONT_HERSHEY_SCRIPT_SIMPLEX If (color = cv::Scalar::all(0)) cv::threshold(textImgMask, textImgMask, 1, 255, cv::THRESH_BINARY_INV) Įlse cv::threshold(textImgMask, textImgMask, 254, 255, cv::THRESH_BINARY) Īnd call it like: cv::Mat image = cv::imread("C:/opencv_logo.png") Ĭv::Rect roi(5, 5, ls - 5, image.rows - 5) Estimating the resolution of bounding imageĬv::Point textOrg((ls - textSize.width) / 2, (textImg.rows + textSize.height - baseline) / 2) Ĭv::Point tr(textOrg.x, textOrg.y + baseline) Ĭv::Point bl(textOrg.x + textSize.width, textOrg.y - textSize.height) Ĭv::putText(textImg, text, textOrg, fontFace, fontScale, color, thickness) Ĭv::resize(textImg, textImg, roi.size()) Ĭv::cvtColor(textImgMask, textImgMask, cv::COLOR_BGR2GRAY) Ĭv::equalizeHist(textImgMask, textImgMask) Render the text over here (fits to the text size)Ĭv::Mat textImg(textSize.height + baseline, textSize.width, img.type()) Y-coordinate of the baseline relative to the bottom-most text point Calculates the width and height of a text stringĬv::Size textSize = cv::getTextSize(text, fontFace, fontScale, thickness, &baseline) If you'd like to render the text in an arbitrary ROI of an image then you first need to render it into another image (which fits to the text size), resize it to the ROI desired and then put it over the image, such as below: void PutText(cv::Mat& img, const std::string& text, const cv::Rect& roi, const cv::Scalar& color, int fontFace, double fontScale, int thickness = 1, int lineType = 8)ĬV_Assert(!img.empty() & (img.type() = CV_8UC3 || img.type() = CV_8UC1)) ![]() There is a sample code in the description of the function but it only renders some text, the tight box (surrounding the text), and the baseline of it. It's a bit tricky, but you can play with cv::getTextSize().
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |