This is the 19th day of my participation in the August Wenwen Challenge.More challenges in August

One, foreword

First of all, please don’t take the following nonsense seriously.

In everyone’s impression, programmer is a well-paid career, often think programmer is an elite group. I’m telling you right now, it’s true. Because of this, programmers are very popular, and usually a programmer will get 10 or 11 girls (binary numbers here). So most programmers are not single, and this is where programmers get really upset. So many programmers are trying to break up with their girlfriends, read this article you are lucky, today let you learn to put into practice, write a break up small program, let you enjoy the freedom of being single.

Second, huh? Go to travel?

Yesterday was May 20th, the reason why it was not sent yesterday was for personal safety. Programmer xiao Wang has such a worry.

He said: “My girlfriend ah, very annoyed, every day stick to me, code has no time to play. Just yesterday SHE said she was going on a trip for peach. I’ve got such a big project I don’t have time for peach. ‘ .

After hearing Xiao Wang’s complaint, I thought for a while and asked, “Are you eager to be single?” .

Xiao Wang replied, “That would be great, so THAT I can write my project in peace.”

So I gave programmer xiao Wang an idea, xiao Wang with the following gesture to give me good news:

It looks like he succeeded. I asked Xiao Wang: “arranged?”

Xiao Wang slightly depressed: “failed, DO not know which process out of the problem”.

I asked Xiao Wang to show me what I asked him to do. After reading it, I shook my head: “This is no good. It’s too beautiful.

I let small wang changed the code, after a period of time, small wang changed a pair of appearance. This time, his hair was glowing, and judging by his expression, he was okay:

His face was still a little ruddy, and his lips were bloodshot, but he could not conceal his joy. He said: “Thank you eldest brother’s guidance, has been divided. The screen was smashed, the keyboard sprained and the mouse lost its tail, but it was worth it.”

Disclaimer

See here many programmers compatriots must be very curious, I in the end let small wang do what. Don’t worry, everyone. I’ll tell everyone. You need to read the following statement before doing so:

The risks that come with using content have nothing to do with the author. Visitors may use the content or services provided herein for personal study, research or appreciation, as well as other non-commercial or non-profit purposes, provided that the content or services shall comply with the provisions of the copyright law and other relevant laws, and shall not infringe on the legal rights of the website and related rights holders.

If you have any questions, please do not write zuan. Thank you very much.

Iv. What happened

My suggestion to Xiao Wang is that since his girlfriend wants to travel, you can show the charm of a man (stingy or stingy). You can get detailed description from their chat:

Xiao Wang said: “What are you traveling to do? You can eat anywhere except for eating and taking pictures.”

Wang’s wife replied: “When they first fell in love, they were all called little sweet, but now they are still cruel. I just want to take a picture.”

This sentence just in the middle of the small wang of the trap, small wang said: “that good, I give you pat the total line!”

Say that finish, small wang sits in front of computer. Wang’s wife thought he was booking a green train ticket and was secretly pleased. So in the side of the brush up douyin. To my surprise, Xiao Wang turned on PyCharm and his wife, who was brushing Douyin, did not notice. First, Xiao Wang entered CMD by pressing Win +R, and then entered the following two codes on the command line:

python -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
pip install -i https://mirror.baidu.com/pypi/simple paddlehub
Copy the code

Xiao Wang mused: “Big brother said to install paddlePaddle and PaddleHub first, look at these two sentences.” Small wang thought for a while: “matting how to write the newcomer?” He opened his browser and typed in this url: Stop minting yourself. Python does this in five lines of code. “Big Brother’s writing is so good that you can understand it immediately.” So he continued to write:

from PIL import Image
import paddlehub as hub
# loading comments
humanseg = hub.Module(name='deeplabv3p_xception65_humanseg')
A humanseg_output directory is generated. PNG image has the same name as the original image
results = humanseg.segmentation(data={'image': ['master.jpg']})
# Read PNG images
im = Image.open('humanseg_output/master.png')
# Channel separation
r, g, b, a = im.split()
# Read background image
bg = Image.open('bg.jpg')

Get the paste position
size1 = im.size
size2 = bg.size
im.resize((size2[1], size2[1]))
x = size2[0]-size1[0]
y = size2[1]-size1[1]

Paste the PNG image onto the background
bg.paste(im, (x, y), mask=a)
# Save the resulting graph
bg.save('result.jpg')
Copy the code

Xiao Wang ran the program, found unexpectedly error, came to ask me, found that there is no module installed, he also in CMD to execute the following code:

pip install pillow
Copy the code

It worked fine. Wang stroked his beard and scratched what was left of his hair, which, I reckon, killed a few bytes of hair follicles. He looked at the pictures below (not wang’s girlfriend) :

Xiao Wang thought, this should be no problem, so the realization of good pictures to his girlfriend. Wang wife great anger: “you don’t want to take me to play you say, but also make a program fool me!” “And then slapped xiao Wang with a big mouth. Xiao Wang was pleased, but xiao Wang could not be happy for long. “What’s it like to have a boyfriend who’s a programmer? At the moment she saw the code, Wang’s wife felt she had misunderstood Xiao Wang, so they made up again, and Xiao Wang tearfully accepted her apology.

After going out of the small wang found me again, I gave small wang an idea. Xiao Wang went home, opened the browser and entered the official website of OpenCV: opencv.org/releases/. He downloaded the corresponding version of the software and installed it. He found the source\ Data \ Haarcascades directory in the installation directory and took out the haarcascade_frontalface_default. XML file. Confused and unconcerned, he just opened the page in his browser: OpenCv identifies Robert Downey Jr. Thought, what won’t check it out.

Then xiao Wang executes the following two lines of code in CMD:

pip install opencv-python
pip install opencv-contrib-python
Copy the code

Then Wang thought about what I said and changed his girlfriend’s face into an ugly one. Write the following code again:

import cv2

def face_detect(im) :
    """ Face detection """
    im = cv2.imread(im)
    grey = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
    face_detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
    faces = face_detector.detectMultiScale(grey)
    # Return a face
    return faces[0]
Copy the code

At this point, Haarcascade_frontalface_default. XML is used here, so he copies the file to the project. “This,” he thought to himself, “will test faces!” . But it wasn’t enough. He went on:

def change_face(im, face_loc, face_im) :
    x, y, w, h = face_loc
	# Read girlfriend picture
    im = cv2.imread(im)
	
    # Read the face to change
    face_im = cv2.imread(face_im)
    face_im = cv2.resize(face_im, (w, h))

    # Face region switch
    im[y:y + h, x:x + w] = face_im

    # save
    cv2.imwrite('result.jpg', im)
Copy the code

Xiao Wang also wrote in main:

if __name__ == '__main__':
    face = face_detect('master.jpg')
    change_face('master.jpg', face, 'face.jpg')
Copy the code

After running, the result graph came out. Xiao Wang clicked the result graph and laughed loudly:

Attracted by the laughter, Wang’s wife flew into a rage when she saw the pictures on the screen. Sprained the keyboard, smashed the screen, broke the mouse, and beat wang so badly that he bled but couldn’t stop laughing. Wang’s wife broke up decisively. To this matter is to draw on a perfect end.

5. Is it over?

A lot of people wondered why Xiao Wang did this, everyone thought xiao Wang did this very radical. But in fact, Xiao Wang is the most sober one, xiao Wang wrote in his diary: “Others laugh at me too crazy, I laugh at others do not see.” At this time, small wang’s girlfriend came back: “I just brush a shake sound, the original is I don’t understand programmer’s humor, I’m wrong, can you forgive me?”