国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網 會員登陸 & 注冊

在大圖中分辨出小圖位置的程序

2023-05-24 18:46 作者:小大小深  | 我要投稿

閑暇時寫了一個可以在大圖中分辨出小圖位置的程序。

懶~~

用法:傳入兩個參數,都為PIL庫的Image庫的Image類,傳出一個列表,內含小圖正中坐標。

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

from PIL import Image


def findpixel(image1=Image.Image(), image2=Image.Image()):

? ? wantrgb = image2.getpixel((0, 0))

? ? wantsize = image2.size

? ? stoper = []

? ? for y in range(image1.size[1]):

? ? ? ? for x in range(image1.size[0]):

? ? ? ? ? ? rgb = image1.getpixel((x, y))


? ? ? ? ? ? if rgb == wantrgb:

? ? ? ? ? ? ? ? print("--------------------")

? ? ? ? ? ? ? ? print(

? ? ? ? ? ? ? ? ? ? f"find importend pixel at image1 ({x},{y}) by {rgb}")


? ? ? ? ? ? ? ? cox = x+wantsize[0]

? ? ? ? ? ? ? ? coy = y+wantsize[1]

? ? ? ? ? ? ? ? if cox >= image1.size[0] or coy >= image1.size[1]:

? ? ? ? ? ? ? ? ? ? continue

? ? ? ? ? ? ? ? copy = image1.crop((x, y, x+wantsize[0], y+wantsize[1]))


? ? ? ? ? ? ? ? metter = False

? ? ? ? ? ? ? ? for by in range(copy.size[1]):

? ? ? ? ? ? ? ? ? ? for bx in range(copy.size[0]):

? ? ? ? ? ? ? ? ? ? ? ? if copy.getpixel((bx, by)) != image2.getpixel((bx, by)):

? ? ? ? ? ? ? ? ? ? ? ? ? ? print(f"not pixel at ({bx},{by}) , not by {copy.getpixel((bx, by))} of {image2.getpixel((bx, by))}")

? ? ? ? ? ? ? ? ? ? ? ? ? ? metter = True

? ? ? ? ? ? ? ? ? ? ? ? if metter:

? ? ? ? ? ? ? ? ? ? ? ? ? ? break

? ? ? ? ? ? ? ? ? ? if metter:

? ? ? ? ? ? ? ? ? ? ? ? break


? ? ? ? ? ? ? ? if not metter:

? ? ? ? ? ? ? ? ? ? print("find a ok image!")

? ? ? ? ? ? ? ? ? ? stoper.append([x + int((cox-x)//2), y + int((coy-y)//2)])

? ? return stoper


print(findpixel())#error要寫參數



在大圖中分辨出小圖位置的程序的評論 (共 條)

分享到微博請遵守國家法律
北流市| 开平市| 南漳县| 西宁市| 武胜县| 永靖县| 逊克县| 深泽县| 石柱| 阿荣旗| 麻城市| 石嘴山市| 嵊泗县| 老河口市| 广西| 贺兰县| 平陆县| 抚顺县| 昌平区| 大同县| 潞城市| 昭苏县| 临高县| 安乡县| 嘉祥县| 台南县| 县级市| 巧家县| 镇康县| 朝阳县| 鄂托克前旗| 锡林郭勒盟| 凭祥市| 邓州市| 双辽市| 彭州市| 会泽县| 湘乡市| 苏州市| 墨江| 瑞丽市|