[PYTHON] I want CAPTCHA to say HIWAI words

Is there a CAPTCHA? That's cute, isn't it cute! ?? !! ?? (confusion)

This is a CAPTCHA image.png

Kyawawa

Come on OPPAI The person who drew the most beautiful OPPAI in Python wins

result

** No ** image.png

** No ** image.png

** Stupid ** image.png

** Pokupittsu ** image.png

code

** 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)

Summary

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.

reference

・ 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

I want CAPTCHA to say HIWAI words
Even beginners want to say "I fully understand Python"
I want to solve Sudoku (Sudoku)
I want to say that there is data preprocessing ~
I want to scrape images to learn
I want to do ○○ with Pandas
I want to copy yolo annotations
I want to pin Spyder to the taskbar
I want to detect objects with OpenCV
I want to output to the console coolly
I want to print in a comprehension
I want to scrape them all together.
I want to handle the rhyme part1
I want to know how LINUX works!
I want to blog with Jupyter Notebook
I want to handle the rhyme part3
I want to use jar from python
I want to build a Python environment
I want to use Linux on mac
I want to pip install with PythonAnywhere
I want to analyze logs with Python
I want to play with aws with python
I want to use IPython Qt Console
I want to display the progress bar
I want to make an automation program!
I want to embed Matplotlib in PySimpleGUI
I want to handle the rhyme part2
I want to handle the rhyme part5
I want to handle the rhyme part4
I want to make matplotlib a dark theme
I want to connect to PostgreSQL from various languages
I want to do Dunnett's test in Python
I want to have recursion come to my mind
I want to easily create a Noise Model
I want to use MATLAB feval with python
I want to analyze songs with Spotify API 2
I want to INSERT a DataFrame into MSSQL
I want to create a window in Python
Anyway, I want to check JSON data easily
I want to email from Gmail using Python.
[Python] I want to manage 7DaysToDie from Discord! 1/3
I want to perform SageMaker inference from PHP
I want to display multiple images with matplotlib.
I want to make a game with Python
I want to visualize csv files using Vega-Lite!
I want to handle the rhyme part7 (BOW)
I want to be an OREMO with setParam!
I don't want to take a coding test
I want to store DB information in list
I want to analyze songs with Spotify API 1
I want to merge nested dicts in Python
I want to make fits from my head
I want to manage systemd by time zone! !!
I want to use Temporary Directory with Python2
I want to get League of Legends data ③
I don't want to use -inf with np.log
#Unresolved I want to compile gobject-introspection with Python3
I want to create a plug-in type implementation
I want to use ip vrf with SONiC
I want to solve APG4b with Python (Chapter 2)
I want to start over with Django's Migrate