コード例 #1
0
        private void data_grid_view_porn_pics_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }
            DataGridView dgView = (DataGridView)(sender);

            // no need to add TaskTime...
            if (e.ColumnIndex == dgView.Columns["created_at"].Index)
            {
                DateTime dsutc = (DateTime)e.Value;
                e.Value = TimeZoneInfo.ConvertTimeFromUtc(dsutc, TimeZoneInfo.Local);
            }
            else if (e.ColumnIndex == dgView.Columns["type"].Index)
            {
                PornClassifier.ImageType type = (PornClassifier.ImageType)(Int64) e.Value;
                if (type == PornClassifier.ImageType.P**n)
                {
                    e.Value = "色情";
                }
                else if (type == PornClassifier.ImageType.Disguise)
                {
                    e.Value = "暴露";
                }
            }
        }
コード例 #2
0
 private void ProgressChangedMethod(int percentage, string filename, PornClassifier.ImageType type)
 {
     progressBar.Value    = percentage;
     currentFileName.Text = filename;
     if (type == PornClassifier.ImageType.P**n)
     {
         bindingSource.Add(new PornFile(filename, type));
     }
 }
コード例 #3
0
        public bool ClassifyVideoFile(string filename, out Exception excep)
        {
            log.Info("Classify Video File: " + filename);
            FFMPEGWrapper ffmpeg = new FFMPEGWrapper();

            if (!ffmpeg.Open(filename))
            {
                log.Info("Video File Cannot Open: " + filename);
                excep = new Exception("Cannot Open File!");
                ffmpeg.Dispose();
                return(false);
            }
            log.Debug("Video File Opened: " + filename);
            if (ffmpeg.FileInfo.nb_frames < MinFrames)
            {
                log.Info("Video File Short of Frames: " + filename + " frames: " + ffmpeg.FileInfo.nb_frames);;
                ffmpeg.Dispose();
                excep = new Exception("Video File Too Short");
                return(false);
            }
            Int64 step = ffmpeg.FileInfo.duration / VideoSegments;

            PornClassifier.ImageType [] types = new PornClassifier.ImageType[VideoSegments - 1];
            int pornNum = 0;

            for (Int64 ts = step; ts < ffmpeg.FileInfo.duration - step / 2; ts += step)
            {
                if (ffmpeg.ReadFrame(ts))
                {
                    if (Instance.Classify(ffmpeg.FileInfo.pdata, ffmpeg.FileInfo.width, ffmpeg.FileInfo.height, ffmpeg.FileInfo.linesize)
                        == ImageType.P**n)
                    {
                        pornNum++;
                    }
                }
            }
            ffmpeg.Dispose();
            excep = null;
            if (pornNum >= PornNumThd)
            {
                log.Info("P**n Video File: " + filename);
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
        public void InsertPornPic(String url, PornClassifier.ImageType prop)
        {
            try
            {
                SQLiteCommand cmd = new SQLiteCommand(String.Format(kPornItemInsertOrReplace, url, (Int64)PornItemType.NetworkImage,
                                                                    "网络不良图片", (Int64)PornItemStatus.Normal), PornDBConnection);
                int rowsInsert = cmd.ExecuteNonQuery();
                log.Debug("PornPicInserted: " + rowsInsert);
                _TableChangedProgressInt.Report("porn_items");
                //lock (PornPicsTable)

                //{
                //    PornPicsTable.Rows.Add(null, url, (int)prop);
                //    PornPicsDataAdapter.Update(PornPicsTable);
                //}
            }
            catch (Exception e)
            {
                log.Error(e.ToString());
            }
        }
コード例 #5
0
 public PornFile(String p, PornClassifier.ImageType t)
 {
     path = p;
     type = t;
 }
コード例 #6
0
        protected void ProcessImage()
        {
            log.Info("Process Image: " + RequestLine.URI);
            byte[] response = GetContent();

            // From now on, the default State.NextStep ( == SendResponse()
            // at this point) must not be called, since we already read
            // the response.
            State.NextStep = null;

            // Decompress the message stream, if necessary
            using (Stream stream = GetResponseMessageStream(response))
            {
                using (Bitmap bm = new Bitmap(stream))
                {
                    PornClassifier.ImageType imgType         = PornClassifier.Instance.Classify(bm);
                    IProgress <PornDatabase.PornItemType> ip = MainForm.Instance.TargetProcessedProgress as IProgress <PornDatabase.PornItemType>;
                    bool isImageBad = false;
                    if (imgType == PornClassifier.ImageType.P**n)
                    {
                        isImageBad = true;
                        //添加到不良网页中,以进行不良网站检查,只针对色情图片进行处理
                        //只在启用了色情网站侦测时才处理,但实际上由于未启用色情网站侦测时
                        //html不处理,这里其实即使处理也无法hit
                        if (Properties.Settings.Default.IsPornWebsiteProtectionTurnOn)
                        {
                            AddPorn();
                        }
                    }
                    else if (imgType == PornClassifier.ImageType.Disguise &&
                             Properties.Settings.Default.IsStrongNetworkImageFilter)
                    {
                        isImageBad = true;
                    }
                    else
                    {
                        ip.Report(PornDatabase.PornItemType.Undefined);
                    }

                    //if (p != null)
                    //只在图片过滤功能开启时才将色情图片加入数据库,并替换图片
                    Bitmap nbm = null;
                    if (isImageBad && Properties.Settings.Default.IsNetworkImageTurnOn)
                    {
                        //只有色情图片才加入数据库,防止将性感图片加入以后带来不好的感觉
                        if (imgType == PornClassifier.ImageType.P**n)
                        {
                            //先保存图片,在插入数据库,否则第一项会导致没有图片可以显示
                            bm.Save(Program.AppLocalDir + Properties.Settings.Default.imagesDir + "\\" + HttpUtility.UrlEncode(FullRequestUri));
                            PornDB.InsertPornPic(FullRequestUri, PornClassifier.ImageType.P**n);
                            log.Debug("After PornPicInserted");
                            ip.Report(PornDatabase.PornItemType.NetworkImage);
                        }

                        //此处如果图像为带索引格式,则会引发异常,无法创建graphics对象
                        //这使得网页上一个图片总是无法加载
                        nbm = new Bitmap(bm.Width, bm.Height);
                        //using (Graphics g = Graphics.FromImage(bm))
                        using (Graphics g = Graphics.FromImage(nbm))
                        {
                            //SolidBrush solidBrush = new SolidBrush(Color.Red);
                            SolidBrush solidBrush = new SolidBrush(Color.Azure);
                            g.FillRectangle(solidBrush, 0, 0, bm.Width, bm.Height);
                            SolidBrush stringBrush = new SolidBrush(Color.CadetBlue);
                            g.DrawString(Properties.Resources.ProductionName, new Font("微软雅黑", bm.Width / 10, GraphicsUnit.Pixel), stringBrush, new Point(0, 0));
                            g.Flush();
                        }
                    }

                    // Even if the response was originally transferred
                    // by chunks, we are going to send it unchunked.
                    // (We could send it chunked, though, by calling
                    // TunnelChunkedDataTo, instead of TunnelDataTo.)
                    ResponseHeaders.TransferEncoding = null;

                    // Encode the modified content, and recompress it, as necessary.
                    //String text = htmlDoc.Save()
                    //htmlDoc.Save(HttpUtility.UrlEncode(RequestLine.URI));
                    MemoryStream mstr = new MemoryStream();
                    if (nbm != null)
                    {
                        nbm.Save(mstr, bm.RawFormat);

                        //这里使用toArray就可以得到和实际内容长度相同的数据
                        byte[] output = CompressResponse(mstr.ToArray());
                        //这里必须使用mstr.Length,而不能使用output.Length
                        //因为前者表示真实长度,后者表示总缓存长度,比实际长度要长
                        //如果前面是使用ToArray,而不是GetBuffer则没问题
                        ResponseHeaders.ContentLength = (uint)output.Length;
                        SendResponseStatusAndHeaders();
                        SocketBP.TunnelDataTo(TunnelBP, output);

                        nbm.Dispose();
                    }
                    else
                    {
                        //用于测试,即使图片不替换,也重新保存
                        //bm.Save(mstr, bm.RawFormat);
                        //byte[] output = CompressResponse(mstr.ToArray());
                        //ResponseHeaders.ContentLength = (uint)output.Length;

                        SendResponseStatusAndHeaders();
                        SocketBP.TunnelDataTo(TunnelBP, response);
                    }

                    //debug code
                    //bm.Save(mstr, bm.RawFormat);
                    //这里使用toArray就可以得到和实际内容长度相同的数据
                    //byte[] output = CompressResponse(mstr.ToArray());
                    //byte[] output = CompressResponse(mstr.GetBuffer());
                    //这里必须使用mstr.Length,而不能使用output.Length
                    //因为前者表示真实长度,后者表示总缓存长度,比实际长度要长
                    //如果前面是使用ToArray,而不是GetBuffer则没问题
                    //ResponseHeaders.ContentLength = (uint)output.Length;
                    //SendResponseStatusAndHeaders();
                    //SocketBP.TunnelDataTo(TunnelBP, output);

                    //byte[] output = CompressResponse(mstr.GetBuffer());
                    //ResponseHeaders.ContentLength = (uint)output.Length;

                    // Finally, send the result.
                    //SendResponseStatusAndHeaders();
                    //SocketBP.TunnelDataTo(TunnelBP, output);
                    // We are done with the request.
                    // Note that State.NextStep has been set to null earlier.
                }
            }
        }