Xg2-1-1

from PIL import Image

---------------------------------------------------------------

Xg2-1-2

im = Image.open('cat.jpg')

---------------------------------------------------------------

Xg2-1-3

from PIL import Image

im = Image.open('cat.jpg')
print(im.filename, im.width, im.height, im.size, im.format, im.mode)

---------------------------------------------------------------

Xg2-1-4

im.resize((300,300))

---------------------------------------------------------------

Xg2-1-5

im_tmp = im.resize((300,300))
im_tmp.save('cat_after.jpg')

---------------------------------------------------------------

Xg2-1-6

im.resize((300,300)).save('cat_after.jpg')

---------------------------------------------------------------

Xg2-1-7

im.thumbnail((300,300))
im.save('cat_after.jpg')

---------------------------------------------------------------

Xg2-1-8

im = Image.open('cat.jpg')
im_tmp = im.crop((100, 300, 400, 600))
im_tmp.save('cat_after.jpg')

---------------------------------------------------------------

Xg2-1-9

im = Image.open('cat.jpg')
im_tmp = im.rotate(45)
im_tmp.save('cat_after.jpg')

---------------------------------------------------------------

Xg2-1-10

im = Image.open('cat.jpg')
im_tmp = im.rotate(45, expand=True)
im_tmp.save('cat_after.jpg')

---------------------------------------------------------------

Xg2-1-11

from PIL import Image, ImageOps

ImageOps.flip(im).show()
ImageOps.mirror(im).show()

---------------------------------------------------------------

Xg2-1-12

from PIL import Image, ImageFilter

im.filter(ImageFilter.BLUR).show()
im.filter(ImageFilter.EMBOSS).show()

---------------------------------------------------------------

pip install opencv-python


C:\Users\[U[\anaconda3\Lib\site-packages\cv2\data


haarcascade_frontalface_default.xml

---------------------------------------------------------------

Xg2-1-13

import cv2

cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
im = cv2.imread('family.jpg')
gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
faces = cascade.detectMultiScale(gray, scaleFactor=1.5)

for (x, y, w, h) in faces:
    cv2.rectangle(im, (x, y), (x + w, y + h), (0, 0, 255))

cv2.imwrite('family_face.jpg', im)

---------------------------------------------------------------
