最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

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

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

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要寫參數



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

分享到微博請遵守國家法律
宿迁市| 原平市| 绩溪县| 曲阳县| 周口市| 彭泽县| 夏邑县| 盘山县| 错那县| 容城县| 嘉禾县| 武川县| 盐源县| 安岳县| 福泉市| 自贡市| 北碚区| 宣汉县| 湘阴县| 延边| 白水县| 清镇市| 炉霍县| 汤阴县| 星座| 三门县| 博客| 夏河县| 翁源县| 吴堡县| 内乡县| 开江县| 苍梧县| 那曲县| 伊川县| 惠来县| 姚安县| 班戈县| 通榆县| 广东省| 蕉岭县|