[exclusive for Valentine's day] dog food is sprinkled in the circle of friends, which is a high force artifact
Reprinted from AI Studio
Title item link https://aistudio.baidu.com/aistudio/projectdetail/3472196
The annual Valentine's Day is coming. Are all those who have objects worried about how to make a high-profile circle of friends. As a male compatriot, in order to take a beautiful picture of his girlfriend, it really takes a lot of time and energy. He not only needs to carefully select from many pictures, but also needs to have strong picture refinement ability to get pictures that meet his girlfriend's requirements. It's really not easy. A picture sent out by the circle of friends seems very thin, Many photos don't know how to arrange them. Don't panic. You can generate the image you want with one click through the following items. And there are many options for you to choose! (single compatriots can also send "wives")
It's not too late to see the fresh plan first.
Scheme I (love):
Usage suggestion: try to use square pattern (10 + photos are better), and group photos in the center are better!!!
Changeable background color
(PS: some photos of love may appear during the execution of the program, and some will be vacant. It is because the photos that cannot be opened are skipped during the execution of the program. Just execute it several times more (select photos randomly))
Scheme II (520):
Usage suggestion: try to use square pattern (20 + photos are better)
Scheme 3 (Jiugong grid):
Converted
In this scheme, the original picture is cut into 9 small pictures, which can be added in order when sending a circle of friends
Of course, you can also use the love picture of scheme 1 for Jiugong grid segmentation
Scheme 1: love pattern
Usage suggestion: try to use square pattern (10 + photos are better), and group photos in the center are better!!!
from PIL import Image import os, sys import random mw =256 #Size of each picture toImage = Image.new('RGBA', (mw*9, mw*9),'white') #canvas size #Picture shape construction heart =[ [0,0,1,1,0,1,1,0,0], [0,1,0,0,1,0,0,1,0], [1,0,0,0,0,0,0,0,1], [1,0,0,0,1,0,0,0,1], [0,1,0,0,0,0,0,1,0], [0,0,1,0,0,0,1,0,0], [0,0,0,1,0,1,0,0,0], [0,0,0,0,1,0,0,0,0], [0,0,0,0,0,0,0,0,0] ] dir1 = r'work/AI'#Absolute path of heart puzzle picture folder list1= os.listdir(dir1) dir2 = r'work/center/joy_16.jpg'#Absolute path of middleman picture # print(list1) for x in range(0, 9): for y in range(0, 9): #blank if heart[y][x]==0: continue #Group photo in the middle if y==3 and x==4: fromImage = Image.open(dir2) fromImage =fromImage.resize((500, 500), Image.ANTIALIAS) toImage.paste(fromImage, (x * mw-150, 50+y * mw))#Move down as a whole to make the graphics better displayed in the center continue #Heart shaped photos try: path = random.choice(list1) fromImage = Image.open(dir1+'/'+path) fromImage =fromImage.resize((mw,mw), Image.ANTIALIAS) toImage.paste(fromImage, (x * mw, 200+y * mw))#Move down as a whole to make the graphics better displayed in the center except IOError: pass toImage.show() toImage= toImage.convert('RGB') toImage.save('Picture_AI.jpg')
Scheme 2: Digital 520
Usage suggestion: try to use square pattern (20 + photos are better)
from PIL import Image import os, sys import random mw =200 #Size of each picture toImage = Image.new('RGBA', (mw*20, mw*8),'white') #canvas size #Picture shape construction heart =[ [0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,0], [0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0], [0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0], [0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,0,0,1,0], [0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,1,0], [0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,1,0], [0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,0], [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], ] dir1 = r'work/520'#520 absolute path of puzzle picture folder list1= os.listdir(dir1) for x in range(0, 20): for y in range(0, 8): #blank if heart[y][x]==0: continue #520 photos try: path = random.choice(list1) fromImage = Image.open(dir1+'/'+path) fromImage =fromImage.resize((mw, mw), Image.ANTIALIAS) toImage.paste(fromImage, (x * mw, 100+y * mw))#Move down as a whole to make the graphics better displayed in the center except IOError: pass toImage.show() toImage= toImage.convert('RGB') toImage.save('Picture_520.jpg')
Scheme 3: Jiugong grid
Circle of friends Jiugongge picture making
# Circle of friends Jiugongge picture making from PIL import Image import sys # First fill the input image with a square def fill_image(image): width, height = image.size #Select the larger value of the length and width of the original picture as the radius of the Jiugong grid of the new picture new_image_length = width if width > height else height #Production of new pictures [white background] new_image = Image.new(image.mode,(new_image_length, new_image_length), color='white') #Paste the original image on the new image, and the position is centered if width > height: new_image.paste(image,(0, int((new_image_length-heigth) / 2))) else: new_image.paste(image,(int((new_image_length-width) / 2), 0)) return new_image # Cut the picture into nine squares def cut_image(image): width, height = image.size #Three pictures in a row item_width = int(width / 3) box_list = [] for i in range(0,3): for j in range(0,3): box = (j*item_width,i*item_width,(j+1)*item_width,(i+1)*item_width) box_list.append(box) image_list = [image.crop(box) for box in box_list] return image_list #Save picture def save_images(image_list): index = 1 for image in image_list: image.save('9_save/'+str(index) + '.jpg', 'JPEG') index += 1 if __name__ == '__main__': file_path = "work/data/meiyan_1.jpg" image = Image.open(file_path) #image.show() image = fill_image(image) image_list = cut_image(image) _1.jpg" image = Image.open(file_path) #image.show() image = fill_image(image) image_list = cut_image(image) save_images(image_list)
Reference article:
Jiugong grid heart puzzle - Python 3
Python project Jiugongge image generation
About the author
- The directions of interest are: target detection, image classification, image segmentation and so on.
- Update the CV game baseline of interest from time to time
- Personal honor: propeller developer technical expert (PPDE)
- Welcome everyone to leave a message with questions, exchange and learn, and make progress and growth together.
More projects you may be interested in
- Nanny tutorial:
[paddedetection nanny tutorial] using custom data sets to realize fall recognition and prediction
[PP-YOLOV2 nanny level tutorial] using custom data sets to realize smoking recognition prediction
[Xiaobai tutorial] PaddleX flame detection training, prediction and server-side service deployment wait
- CV game baseline:
AGCN optimization model of figure skaters' bone point action recognition competition
iFLYTEK leafy vegetable pest image recognition challenge baseline (Unofficial) wait
- Interesting items:
Reverse thinking: realistic cartoon photos
The first Korean women's group small card egg twisting machine with flying oars
Halloween portrait generator (PaddleHub Implementation) wait