91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 0.02M
    文件類型: .py
    金幣: 1
    下載: 0 次
    發布日期: 2021-05-27
  • 語言: Python
  • 標簽: 其他??

資源簡介

nude.py

資源截圖

代碼片段和文件信息

import?sys
import?os
import?_io
from?collections?import?namedtuple
from?PIL?import?Image

class?Nude(object):

????Skin?=?namedtuple(“Skin“?“id?skin?region?x?y“)

????def?__init__(self?path_or_image):
????????#?若?path_or_image?為?Image.Image?類型的實例,直接賦值
????????if?isinstance(path_or_image?Image.Image):
????????????self.image?=?path_or_image
????????#?若?path_or_image?為?str?類型的實例,打開圖片
????????elif?isinstance(path_or_image?str):
????????????self.image?=?Image.open(path_or_image)

????????#?獲得圖片所有顏色通道
????????bands?=?self.image.getbands()
????????#?判斷是否為單通道圖片(也即灰度圖),是則將灰度圖轉換為?RGB?圖
????????if?len(bands)?==?1:
????????????#?新建相同大小的?RGB?圖像
????????????new_img?=?Image.new(“RGB“?self.image.size)
????????????#?拷貝灰度圖?self.image?到?RGB圖?new_img.paste?(PIL?自動進行顏色通道轉換)
????????????new_img.paste(self.image)
????????????f?=?self.image.filename
????????????#?替換?self.image
????????????self.image?=?new_img
????????????self.image.filename?=?f

????????#?存儲對應圖像所有像素的全部?Skin?對象
????????self.skin_map?=?[]
????????#?檢測到的皮膚區域,元素的索引即為皮膚區域號,元素都是包含一些?Skin?對象的列表
????????self.detected_regions?=?[]
????????#?元素都是包含一些?int?對象(區域號)的列表
????????#?這些元素中的區域號代表的區域都是待合并的區域
????????self.merge_regions?=?[]
????????#?整合后的皮膚區域,元素的索引即為皮膚區域號,元素都是包含一些?Skin?對象的列表
????????self.skin_regions?=?[]
????????#?最近合并的兩個皮膚區域的區域號,初始化為?-1
????????self.last_from?self.last_to?=?-1?-1
????????#?色情圖像判斷結果
????????self.result?=?None
????????#?處理得到的信息
????????self.message?=?None
????????#?圖像寬高
????????self.width?self.height?=?self.image.size
????????#?圖像總像素
????????self.total_pixels?=?self.width?*?self.height

????def?resize(self?maxwidth=1000?maxheight=1000):
????????“““
????????基于最大寬高按比例重設圖片大小,
????????注意:這可能影響檢測算法的結果

????????如果沒有變化返回?0
????????原寬度大于?maxwidth?返回?1
????????原高度大于?maxheight?返回?2
????????原寬高大于?maxwidth?maxheight?返回?3

????????maxwidth?-?圖片最大寬度
????????maxheight?-?圖片最大高度
????????傳遞參數時都可以設置為?False?來忽略
????????“““
????????#?存儲返回值
????????ret?=?0
????????if?maxwidth:
????????????if?self.width?>?maxwidth:
????????????????wpercent?=?(maxwidth?/?self.width)
????????????????hsize?=?int((self.height?*?wpercent))
????????????????fname?=?self.image.filename
????????????????#?Image.LANCZOS?是重采樣濾波器,用于抗鋸齒
????????????????self.image?=?self.image.resize((maxwidth?hsize)?Image.LANCZOS)
????????????????self.image.filename?=?fname
????????????????self.width?self.height?=?self.image.size
????????????????self.total_pixels?=?self.width?*?self.height
????????????????ret?+=?1
????????if?maxheight:
????????????if?self.height?>?maxheight:
????????????????hpercent?=?(maxheight?/?float(self.height))
????????????????wsize?=?int((float(self.width)?*?float(hpercent)))
????????????????fname?=?self.image.filename
????????????????self.image?=?self.image.resize((wsize?maxheight)?Image.LANCZOS)
????????????????self.image.filename?=?fname
????????????????self.width?self.height?=?self.image.size
????????????????self.total_pixels?=?self

評論

共有 條評論