Python Yellow Program

Source: Internet
Author: User

Recently a customer to the server uploaded some junk pictures, and normal pictures mixed together, there are about 10W of the number, in the past about 3 hours over more than 2000 Zhang, the finger smoke, feel very uncomfortable, bite the bullet, write a program to identify it, but how to do it, After reading the information from the Internet and the assistance of colleagues, finally the low-hit program is done:

The code is as follows:

#-*-Coding:utf8-*-#AUTHOR:WXQ#Python 2.7ImportSYSImportOSImportOs.path as PImportShutilImport_io fromCollectionsImportNamedtuple fromPILImportImagedefCheck_porn (file): IMG= Image.open (file). CONVERT ('YCbCr') W, H=img.size Data=img.getdata () CNT=0 forI, YCbCrinchEnumerate (data): Y, CB, CR=YCbCrif<= CB <= 117 and<= CR <= 168: CNT+ = 1ifCNT > W * H * 0.1:        returnTrueElse:        returnFalseif __name__=='__main__': Imgdir= Sys.argv[1] Dstdir= Sys.argv[2]    ifImgdir = ="' orDstdir = ="':        RaiseException ('parameter cannot be empty, usage: porn_check.py < picture catalog > < target directory >')    ifP.isdir (imgdir): FileList= [P.join (imgdir, file) forFileinchOs.listdir (imgdir)]Else:        RaiseException ('wrong parameter, the picture directory is illegal') Sys.exit (1)    if  notP.isdir (dstdir):RaiseException ('wrong parameter, the target directory is not valid')     forFileinchfilelist:ifp.isfile (file): Is_porn=check_porn (file)ifIs_porn:Print(File,'is porn') shutil.move (file, Dstdir)Else:                Print(File,'is not porn')

Learning Python in free time, looking forward to optimization, and strive to increase the yellow rate to 100%, to eliminate all harm to the interests of the company and endanger the security of the public network occurs.

Python Yellow Program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.