python鑒黃程式

來源:互聯網
上載者:User

標籤:os.path   目標   sdi   服務   not   for   pat   客戶   col   

最近有客戶向伺服器上傳了些垃圾圖片,和正常圖片混合在一起,大概有10W張的數量,在經曆了大概3個小時翻了2000多張的時候,手指抽了下,感覺很不舒服,硬著頭皮上,寫個程式鑒別下吧,但是怎麼搞呢,經過從網上翻閱資料和同事的協助,終於把這個命中率不高的程式弄好了:

代碼如下:

# -*- coding: utf8 -*-# Author:wxq#python 2.7import sysimport osimport os.path as pimport shutilimport _iofrom collections import namedtuplefrom PIL import Imagedef check_porn(file):    img = Image.open(file).convert(‘YCbCr‘)    w, h = img.size    data = img.getdata()    cnt = 0    for i, ycbcr in enumerate(data):        y, cb, cr = ycbcr        if 86 <= cb <= 117 and 140 <= cr <= 168:            cnt += 1    if cnt > w * h * 0.1:        return True    else:        return Falseif __name__ == ‘__main__‘:    imgdir = sys.argv[1]    dstdir = sys.argv[2]    if imgdir == ‘‘ or dstdir == ‘‘:        raise Exception(‘參數不可為空, 用法: porn_check.py <圖片目錄> <目標目錄>‘)    if p.isdir(imgdir):        filelist = [p.join(imgdir, file) for file in os.listdir(imgdir)]    else:        raise Exception(‘參數錯誤, 圖片目錄不合法‘)        sys.exit(1)    if not p.isdir(dstdir):        raise Exception(‘參數錯誤, 目標目錄不合法‘)    for file in filelist:        if p.isfile(file):            is_porn = check_porn(file)            if is_porn:                print(file, ‘is porn‘)                shutil.move(file, dstdir)            else:                print(file, ‘is not porn‘)

正在空餘時間學習python,期待最佳化,爭取把鑒黃率提高至100%,杜絕一切危害公司利益和危害公用網路安全的事情發生。

python鑒黃程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.