Python基于YCbCr 肤色模型的情色图片检测的简单实现

来源:互联网 发布:mac md文件阅读器 编辑:程序博客网 时间:2024/04/20 07:17

<span style="color: rgb(54, 46, 43); font-family: Arial; font-size: 14px; line-height: 26px;"><strong>Python基于YCbCr 肤色模型的情色图片检测的简单实现</strong></span>
#Detection of Pornographic Digital Images#YCbCr Model#author:Robin chen#input:the dir of an image'''ref:1.http://www.naun.org/multimedia/NAUN/computers/20-462.pdf2.http://blog.csdn.net/gzlaiyonghao/article/details/3166735'''from PIL import Imageimport sysdef image_ifo(image):    try:        img = Image.open(image)    except Exception,e:        print "Can not open the image!"    print 'Image Mode:%s,Image Size:%s,Image Format:%s' % (img.mode,img.size,img.format)    return imgdef preprocessed_image(image):    img = image_ifo(image)    if not img.mode == 'YCbCr':        img = img.convert('YCbCr')    return img    def detector(image):    img = preprocessed_image(image)    ycbcr_data = img.getdata()    W,H = img.size    THRESHOLD = 0.3    count = 0    for i,ycbcr in enumerate(ycbcr_data):        y,cb,cr = ycbcr        #if 80 <= cb <= 120 and 133 <= cr <= 173:        if 86 <= cb <= 127 and 130 <= cr < 168:            count += 1    if count > THRESHOLD*W*H:        print 'The image is pornographic!'    else:        print 'The image is not pornographic!'        if __name__ == '__main__':    image = sys.argv[-1]    print 'Detector is working on it,please wait a second...'    detector(image)    print 'Detecting is done!'        




0 0
原创粉丝点击