This is a CAPTCHA
Kyawawa
Come on OPPAI The person who drew the most beautiful OPPAI in Python wins
** No **
** No **
** Stupid **
** Pokupittsu **
** Creating text **
py.py
import PIL.Image
import PIL.ImageDraw
import PIL.ImageFont
import cv2
import numpy as np
import matplotlib.pyplot as plt
#Settings for font, size, and text to draw
ttfontname = "/System/Library/Fonts/Supplemental/Arial Unicode.ttf"
fontsize = 36
text = "Pokupittsu"
#Set image size, background color, font color
canvasSize = (300, 150)
backgroundRGB = (255, 255, 255)
textRGB = (0, 0, 0)
#Creating an image to draw characters
img = PIL.Image.new('RGB', canvasSize, backgroundRGB)
draw = PIL.ImageDraw.Draw(img)
#Draw a character string on the prepared image
font = PIL.ImageFont.truetype(ttfontname, fontsize)
textWidth, textHeight = draw.textsize(text,font=font)
textTopLeft = (canvasSize[0]//6, canvasSize[1]//2-textHeight//2) #1 from the front/6, placed in the center of the top and bottom
draw.text(textTopLeft, text, fill=textRGB, font=font)
img.save(text + ".png ")
** Distort the image **
py.py
img_BGR = cv2.imread("Pokupittsu.png ")
img_RGB = cv2.cvtColor(img_BGR, cv2.COLOR_BGR2RGB)
height = np.shape(img_RGB)[0]
width = np.shape(img_RGB)[1]
img_RGB_2 = img_RGB.copy()
#Specifying the center and radius
center = np.array((50,50))
r = 100
#Convert pixel coordinates
for x in range(width):
for y in range(height):
#Distance from the center
d = np.linalg.norm(center - np.array((y,x)))
#If it is smaller than the radius, the coordinates are converted.
if d < r:
#vector is a conversion vector.
vector = (d / r)**1.4 * (np.array((y,x)) - center)
#Convert the converted coordinates to an integer
p = (center + vector).astype(np.int32)
#Color data replacement
img_RGB_2[y,x,:]=img_RGB[p[0],p[1],:]
** Overlay images **
py.py
img1 = cv2.imread('CHAPCHA.png')
img2 = img_RGB_2
img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2RGB)
img1 =cv2.resize(img1,(600,600))
img2 =cv2.resize(img2,(200,80))
#Specify the offset position as the reference for the position where the images are superimposed
x_img=200
y_img=320
img1[y_img:y_img+img2.shape[0], x_img:x_img+img2.shape[1]]=img2
cv2.imwrite(text + "2.png ",img1)
CAPTCHA is cute You can also make taunt patterns, so if you have a propensity to do so, please come
People who want to make Kyapu say HIWAI words are excited about LGTM, no, those who are swearing by Kyapu! People request comments If you think about it, you should follow LGTM.
・ Actually this Introduction to Image Processing with OpenCV Revised 2nd Edition (KS Information Science Specialized Book) <img src = "// ir-jp.amazon-adsystem.com/e/ir?t=samuragouchim-22&l=am2&o=" 9 & a = 4061538292 "width =" 1 "height =" 1 "border =" 0 "alt =" "style =" border: none! Important; margin: 0px! Important; "/>
・ My bible <a target="_blank" href="https://www.amazon.co.jp/gp/product/4797393165/ref=as_li_tl?ie=UTF8&camp=247&creative=1211&creativeASIN=4797393165&linkCode=as2&tag=samuragouchim-22&linkId=89a8b622bcebed48da17a > Systematically learn how to create a secure web application 2nd edition Practice of principles and countermeasures for creating vulnerabilities <img src = "// ir-jp.amazon-adsystem.com/e/ir?t=" samuragouchim-22 & l = am2 & o = 9 & a = 47793393165 "width =" 1 "height =" 1 "border =" 0 "alt =" "style =" border: none! important; margin: 0px! important; "/>
Convert character string to image ・ I tried to use python to distort the image as if it dropped water drops
Recommended Posts