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

  • 大小: 18KB
    文件類型: .py
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2023-12-27
  • 語言: Python
  • 標簽: 機器學習??

資源簡介

python的色情圖片識別,利用皮膚裸露度等算法,python智能識別

資源截圖

代碼片段和文件信息

#?-*-?coding:?utf-8?-*-
“““
Created?on?Thu?Jan?11?10:51:44?2018

@author:?liu666
“““
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()
????????#?判斷是否為單通道圖片(也即灰度圖),是則將灰度圖轉(zhuǎn)換為?RGB?圖
????????if?len(bands)?==?1:
????????????#?新建相同大小的?RGB?圖像
????????????new_img?=?Image.new(“RGB“?self.image.size)
????????????#?拷貝灰度圖?self.image?到?RGB圖?new_img.paste?(PIL?自動進行顏色通道轉(zhuǎn)換)
????????????new_img.paste(self.image)
????????????f?=?self.image.filename
????????????#?替換?self.image
????????????self.image?=?new_img
????????????self.image.filename?=?f

????????#?存儲對應(yīng)圖像所有像素的全部?Skin?對象
????????self.skin_map?=?[]
????????#?檢測到的皮膚區(qū)域,元素的索引即為皮膚區(qū)域號,元素都是包含一些?Skin?對象的列表
????????self.detected_regions?=?[]
????????#?元素都是包含一些?int?對象(區(qū)域號)的列表
????????#?這些元素中的區(qū)域號代表的區(qū)域都是待合并的區(qū)域
????????self.merge_regions?=?[]
????????#?整合后的皮膚區(qū)域,元素的索引即為皮膚區(qū)域號,元素都是包含一些?Skin?對象的列表
????????self.skin_regions?=?[]
????????#?最近合并的兩個皮膚區(qū)域的區(qū)域號,初始化為?-1
????????self.last_from?self.last_to?=?-1?-1
????????#?色情圖像判斷結(jié)果
????????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):
????????“““
????????基于最大寬高按比例重設(shè)圖片大小,
????????注意:這可能影響檢測算法的結(jié)果

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

????????maxwidth?-?圖片最大寬度
????????maxheight?-?圖片最大高度
????????傳遞參數(shù)時都可以設(shè)置為?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
????????

評論

共有 條評論