Idealisan

Python 检查图片对称性并打分

代码

import io

import numpy as np
import requests
from PIL import Image, ImageOps
import scipy.spatial.distance as distance


def getImage(url):
    res=requests.get(url,stream=True)
    img=Image.open(res.raw)
    return img


def checkSymmetry(url):
    img = getImage(url)
    smallImg = img.resize((128, 128,))
    intSeq = smallImg.getdata()
    intArray = np.array(intSeq)
    mirror = ImageOps.mirror(smallImg)
    intArrayMirror = np.array(mirror.getdata())
    similarity = 1 - distance.cosine(intArrayMirror.flatten(), intArray.flatten())
    print(similarity)

# for i in range(0,10):
#     checkSymmetry("https://thispersondoesnotexist.com/image")
url='https://t10.baidu.com/it/u=1398544366,153187409&fm=30&app=106&f=JPEG?w=312&h=208&s=725233C28ED8745743C4B4BA03004081'
checkSymmetry(url)
url='https://t10.baidu.com/it/u=558023227,153175838&fm=30&app=106&f=JPEG?w=312&h=208&s=69E2AB468E98705743CCB4BA03008091'
checkSymmetry(url)

url='https://t10.baidu.com/it/u=627398844,153170385&fm=30&app=106&f=JPEG?w=312&h=208&s=D483D9B6420112FC741EB7B90300D00E'
checkSymmetry(url)
分类

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注