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

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

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

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



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

分享到微博請遵守國家法律
沧州市| 博白县| 武宁县| 会东县| 平和县| 德阳市| 旌德县| 突泉县| 宁河县| 霍州市| 改则县| 寻甸| 合阳县| 鹰潭市| 尼木县| 西宁市| 伽师县| 和林格尔县| 大足县| 斗六市| 东宁县| 道孚县| 葵青区| 南城县| 灌南县| 桑植县| 崇信县| 祁门县| 新丰县| 始兴县| 长治县| 横峰县| 安平县| 澎湖县| 健康| 九台市| 仙游县| 山西省| 抚顺县| 白山市| 高邑县|